0

Arduino tečaj: robotska ruka

9. lesson

Ovo je dio cjelovitog tečaja Arduino-a.
  1. Štampajte dijelove koristeći ovaj Sketchup model RescueLine.zip.
  2. Sastavite robota koristeći upute za sastavljanje.
  3. Spojite kablove koristeći plan spajanja.
  4. Programirajte robota.
    1. Osnove.
    2. Praćenje crte.
    3. Naredbe.
    4. LIDARi.
    5. Prekidač, IMU, 8x8 LED.
    6. Praćenje zida.
    7. Srebro.
    8. 8x8 LED programiranje.
    9. Robotska ruka (ova stranica).
    10. Raspberry Pi.
    11. Prepoznavanje kamerom, OpenCV.
    12. Arduino i RPI surađuju.

Assembly and programming

Buy 5 pcs. of Hobby King Turnigy™ TGY-306G-HV servo motors. The motors are expensive but have a big torque, metal gears and ball bearings. Connect red wires to +5V, brown to GND and yellow to the pins according the numbers listed later in code: 23 (bottom of the arm), 22, 32, 21, 20 (top).

Make sure that Servos ML-R library is installed. If not, download it from https://www.github.com/PribaNosati/MRMS and install it.

#include <Servos.h>

Servos servos; // 1 object for all servo motors

void setup() {
	Serial.begin(115200);
	delay(800);
	Serial.println("Start");

	//Add servo motors, one by one:
	servos.add(23); // Pin 23,...
	servos.add(22);
	servos.add(32);
	servos.add(21);
	servos.add(20);

	servos.park(); //Park them all.
}

void loop() {
}

/*All the ML-R libraries invoke this function when something goes wrong. Here we stop the motors, display the error
message which enters the function as the only argument ("message") and then enter an endless loop. while(1) never ends as the condition
(1) is always true. The only command that is in the loop is ";" (empty command - does nothing).
@param message
*/
void error(String msg) {
	Serial.print(msg);
	while (true)
		;
}

Start the program and watch the arm moving into a certain position. Immediately disconnect power because some motors can be stalled. Now re-assemble motors one by one so that the arm forms inverted letter U - all the servos will be in about a middle of the possible positions. This is the park position (90 degrees) and they can travel between 0 and 180 degrees.

Now change the program into its final form by adding orange parts:

#include <Servos.h>

Servos servos;

void setup() {
	Serial.begin(115200);
	delay(800);
	Serial.println("Start");

	//Add servo motors, one by one:
	servos.add(23); // Pin 23,...
	servos.add(22, 120); // This one will have a different park position: 120 degrees instead of implicit 90.
	servos.add(32);
	servos.add(21);
	servos.add(20);
	
	
	//Add all the points that define a complex movement. The first argument is time (in ms) needed to complete that step, then follow
	//angles for all servos. The lowest one should remain at 90 degrees, the next one up should go to 60 degrees, etc.
	servos.trajectoryStep(1000, 90, 60, 130, 120, 180);//Lower the arm
	servos.trajectoryStep(1000, 90, 60, 130, 120, 30); //Grab
	servos.trajectoryStep(1000, 90, 120, 90, 90, 30); //Lift
	servos.trajectoryStep(1500, 0, 120, 90, 90, 30); //Rotate
	servos.trajectoryStep(3000, 0, 120, 90, 90, 30); //Wait
	servos.trajectoryStep(1000, 0, 120, 90, 90, 180); //Let go
	servos.trajectoryRun(); //Execute the stored movement.

	servos.park(); //Park
}

void loop() {
}

void error(String msg) {
	Serial.print(msg);
	while (true)
		;
}

If the ball is in the right position, this program will lead the arm to extend, open the grippers, grab the ball, lift it and rotate the whole arm, wait for 3 sec., drop the ball and park the arm.

Previous lesson
Next lesson