DIY

Arduino-controlled four-legged crawling robot

 Four-legged crawling robot controlled by Arduino Four-legged crawling robot controlled by Arduino  Four-legged crawling robot controlled by Arduino The uniqueness of this robot is in its mode of movement. He can move not only “walking” on his feet, but also, as it were, floating on a solid surface. “Swimming” movements resemble the movements of swimming beetles on the water surface.
According to the master, he has not found a single robot with such movements on the Internet.
Skimming (from the English skim – “to slide”) is an uncomfortable and abrupt way of movement, but it is very exciting and much faster than walking. In addition, it allowed for the programming of a “grip mode” whereby the robot can grip small and light objects. In the first video below, the robot walks, then slides across the floor. In the second video, the robot is walking, then about in the middle of the video it grabs the garbage and disposes of it.

Tools and materials:
-SG90 servo motors 12 pcs – with servos (complete with servomotors: 4 cross-type, 8 single-lever) and supplied screws;
-Arduino Nano; -Breadboard;
-Servo drive with pulse modulation (PWM);
-Rollers ½ “- 4 pieces; -Sheet of expanded polystyrene with a thickness of 3.2 mm;
-Plastic corner of polystyrene L- shaped (4.8 mm);
-IR receiver module and IR remote control;
-Nickel-metal hydride batteries 9 V – 2 pcs;
-Charger; -Connectors for 9V batteries – 2 pcs; -M2 screws 10 mm – 38 pcs; -M2 nuts – 60 pcs; -M2 screws 6 mm – 14 pcs; -M3 screws 14 mm – 2 pcs; -M3 nuts – 4 pcs; -LED 5 mm – 1 pc; -Resistor 1000 Ohm; -Jumpers; -Rubber Lego tires – 4 pcs;
-Mini USB cable;
-Glue for models; -Knife; -Pliers; – Drill; -Drill 2 mm; -Screwdriver; -Set paper; -Soldering accessories;
Four-legged crawling robot controlled by Arduino Arduino controlled four-legged crawling robot  Four-legged crawling robot controlled by Arduino Arduino controlled four-legged crawling robot Step one: design
The legs of the robot are numbered: 1) the front left of the robot, 2) the rear left, 3) the rear right, and 4) the front right. Each leg is in three parts with a servo motor to move each part. The names of the three motors are hip, femur, and tibia, and are numbered for each leg. For example, when programming leg 1 motors, they are named “hip1”, “fem1”, and “tib1”. At the bottom of each femoral motor is a small ½ “roller.
Two 9 volt batteries are used to power the robot. One powers the Arduino Nano, which in turn powers the servo driver and receiver for the remote. Another battery is used for the engines.
The master used an infrared (IR) remote control to control the robot. It is easy to use, with preprogrammed code available on the web and has many buttons that make it easy to launch various functions of the robot.
 Four-legged crawling robot controlled by Arduino Four-legged crawling robot controlled by Arduino Four-legged crawling robot controlled by Arduino Arduino controlled four-legged crawling robot  Four-legged crawling robot controlled by Arduino Arduino controlled four-legged crawling robot Step two: frames
To make a stencil for the thigh frame, you need to draw a template on paper on the paper of the bottom of the servo motor. Then the template is transferred to plastic and two rectangles are cut out of the plastic for each node (eight parts in total).
Then you need to make a cut on four rectangles and connect the parts as in the photo. The master uses model glue to fix it.
Each hip frame is a mirror image of two adjacent motors: legs 1 and 4 will have the femoral motor gears facing forward, and the two rear thigh servos, legs 2 and 3, will have gears. facing back. In other words, legs 1 and 2 are mirror images of legs 4 and 3, respectively.
When all the cuts are complete, give the rectangles a hexagonal shape by notching the corners with a knife.
After the glue has dried, reinstall the motors.
Four-legged crawling robot controlled by Arduino Four-legged crawling robot controlled by Arduino Four-legged crawling robot controlled by Arduino Four-legged crawling robot controlled by Arduino Four-legged crawling robot controlled by Arduino Four-legged crawling robot controlled by Arduino Four-legged crawling robot controlled by Arduino Four-legged crawling robot controlled by Arduino Step three : preparing the servo
Servos are usually supplied with levers of various shapes. The cruciform arm is used to attach the thigh motors to the main body. The second last hole on the longest end of the arm and the third last hole on the short end is used. Two screws are required to attach the Phillips arm to the main body. The holes are too small for the M2 screws, so you need to re-drill them.
Each thigh and shin servo uses a lever with one end (eight in total). If necessary, the holes at the ends of these levers must also be drilled out.
Four-legged crawling robot controlled by Arduino Arduino controlled four-legged crawling robot  Four-legged crawling robot controlled by Arduino Step Four: Preparing the Parts
Making the Tibia Parts
There are many variations of the tibia parts in other projects. The ones designed for this robot are 2 cm wide and 7 cm long. A rectangular hole is cut in the upper part of the tibia for the servo.
Making femur parts
The femur is the same size (2 cm x 7 cm) as the tibia. You need to draw a line in the center of the part. It will be used to align the servo arms and mark the position of the screw that will lock the arms to the femur portions.
It should also be noted on the part of the femur, where the center of the gears of the tibial and femoral motors will pass, approximately 1 cm from each end.
Four-legged crawling robot controlled by Arduino Arduino controlled four-legged crawling robot Step five: main building
The main body is a single piece of 3.2mm polystyrene measuring 9cm x 12cm. To mark and drill the holes for attaching the thigh servos, place them in the base frame. The two front thigh motors are facing forward and the two rear thigh motors are facing backward.
Four-legged crawling robot controlled by Arduino Arduino controlled four-legged crawling robot Step six: assembling the legs
First you need to set all the servos to 90 degrees. Optionally, you can modify the flat pattern sketch in the sample servo thumbnails in the Arduino IDE.
Attach the two motors to the base frame with four M2 screws and nuts. Note the orientation of the thigh motors in the thigh frame and set the thigh motors with the gears closer to the bottom. Then attach the servo cross arms to the femoral motor with the mounting screw.
Then, to attach the femoral motor to the main body, align the edges of the thigh frame with the edges of the main body and install and lock the femoral servo.
Now you need to install the tibial motor on the tibial part so that the gears are closer to the top. At the end of each leg, to improve grip when the robot slides, a rubber tire from a Lego kit is installed.
Step Seven: Diagram
Next, we disassemble the wiring diagram.
Install the Nano on the breadboard. Place the jumpers at the ends of the 9V battery connector pins. Thus, the red and black leads of the 9V battery are connected to the “Vin” and “GND” pins of the Nano, respectively. The PWM motor driver is connected as indicated in the table and diagram.
The connections of all jumpers are as follows:
PWM motor driver — Nano:
GND ………………….. GND
SCL ……………… … .. A5
SDA ………………….. A4
VCC …………… … …. 5V
The motors are connected to the PWM/servo by observing the correct orientation of the 3 wires from the servos to each row of 3 pins on the motor driver. The servo pins on the driver are labeled 5V, GND and data. Servo wires are usually red for 5V, black or brown for ground, and orange for data. With this orientation, the motors are connected to the PWM/servo drive as follows:
Servo motor ….. 3-pin PWM motor driver:
hip1 ……………… …….. 0
fem1 ……………………. 1
tib1 ……. ……………….. 2
hip2 ……………………. .4
fem2 ……………………. 5
tib2 ………….. …………. 6
hip3 …………………….. 8
fem3. …………………… 9
tib3 ………………… ….. 10
hip4 ……………………. 12
fem4 ………. ………….. 13
tib4 …………………….. 14
Note: 3, 7 and 11 are not used.
A second 9 V battery is connected through the connecting wires to the screw terminal of the PWM motor driver, the red lead to positive, black to negative.
The infrared sensor is jumpered to the Nano via the breadboard as follows:
IR sensor: ….. ….. Nano:
Vcc ……………….. 5V
GND ………… .. …. GND
Data ……………… D12
A light-emitting diode (LED) is used to inform when the robot is ready for the next command. If you press the remote too early, the robot will skip the command. If you press several times in a row, the remote control will give a “repeat” command for which the robot is not programmed. The LED is connected to the breadboard and the anode of the LED is connected to the D13 pin of the Nano. A 1 kΩ resistor connects the cathode to ground (GND) of the Nano.
Four-legged crawling robot controlled by Arduino Step eight : installing components on the main body
Installing the breadboard with Nano, PWM servo, IR receiver and two batteries at the top center of the main body.
The breadboard with Nano is located in the center of the back of the robot. When placing the Nano, be sure to insert the mini USB cable. There is a double-sided adhesive pad at the bottom of the dummy to secure it in place.
6 -mm screws M2. The IR receiver must be “visible” to the remote control so that nothing interferes with the view of the receiver. Two M2 nuts can serve as spacers, and two nuts can be used to secure the IR receiver.
Arduino controlled four-legged crawling robot  Four-legged crawling robot controlled by Arduino Arduino controlled four-legged crawling robot  Four-legged crawling robot controlled by Arduino Step Nine: Installing the Rollers
For mounting the rollers, a rectangular housing is made to fit the bottom of each servo. The bottom of the box is a 3.2mm diameter piece of polystyrene, about the size of the bottom of a thigh servo. The three sides of the box are pieces of an L-shaped plastic corner. They sit on a 3.2mm element and the corners of the horizontal side are cut at 45 degrees. At this stage, you need to center the roller and mark the mounting holes. Then we drill the holes and screw the roller.
To strengthen the box, four small pieces of a plastic corner in the shape of the letter “L” were cut and glued. Then we install the casings with rollers on the lower part of the servo and fix them with screws.
Four-legged crawling robot controlled by Arduino Arduino controlled four-legged crawling robot Four-legged crawling robot controlled by Arduino Arduino controlled four-legged crawling robot Four-legged crawling robot controlled by Arduino Arduino controlled four-legged crawling robot Step ten: the code
Most of the code is based on the example of the PWM/Servo driver sketch from Adafruit and IR Remote Control Tutorial from Dronebot Workshop.
The code works with three libraries:
IRremote.h
Wire.h
Adafruit_PWMServoDriver.h
PWMServoDriver can be downloaded from the Adafruit link above. As the name suggests, it drives a servo that drives the servo motors. The Wire library is a standard library that comes with the Arduino IDE software. The IRremote library can be found in the Arduino IDE Library Manager.
One of the variables in the code is “togglePosture”, declared at the top of the code. It monitors whether the robot is walking, sliding or grabbing. When the robot is about to move, Nano checks the togglePosture value to determine the current mode. If necessary, it will run the appropriate function to change the pose, and then update the togglePosture variable to the new mode (glide = 0, stand = 1, grip/slide = 2, or none = 3). This allows the user, for example, to activate the “skimForward” function while the robot is standing. Since the robot is not in skimming mode, togglePosture is not equal to 0. Thus, the robot will call the “skimPosture” function, which will cause the robot to descend onto the rollers, and then the value of the togglePosture variable will be updated to 0.
Due to the orientation of the motors, some rotate clockwise to bend upward or move forward, while others rotate counterclockwise for the same movement. So, for example, for tib1 and tib3, the value of 100 is reversed. However, for tib2 and tib4, the value 600 is fully flexed (i.e. the robot is down).
When walking, forward and backward movements should be smooth, coordinated movements with simultaneous movement of more than one joint. This requires a series of movements where the robot shifts its weight to maintain its center of gravity under its three legs, while the fourth leg is raised and moved slowly. For this, the forward and backward functions are split into several “for” loops in the code. For example, one of the first movements when walking forward is to transfer weight to the leg4. This is the following piece of code:

  for (tib2 = 400; tib2 & lt; 500; tib2 = tib2 + 1) & # 123; if (fem2 & lt; 450) fem2 = fem2 + 1; if (hip3 & lt; 500) hip3 = hip3 + 1; if (tib4 & gt; 300) tib4 = tib4 -1; if (hip1 & gt; 350) hip1 = hip1 - 1;} pwm.setPWM (0, 0, hip1); pwm.setPWM (5, 0, fem2); pwm.setPWM (8, 0, hip3); pwm.setPWM (14, 0, tib4); pwm.setPWM (6, 0, tib2); delay (delayTime); }  

In this section of code, the first line is: for (tib2 = 400; tib2 & lt; 500; tib2 = tib2 + 1) {
The variable tib2 corresponds to the position of the tibial motor on the second leg and starts at 400. This line also indicates that as long as tib2 is less than 500, Nano will cycle through eleven lines of code over and over, but increment tib2 by +1 each time. The next few lines of code are multiple “if” statements, where fem1 and hip3 will also increase in position by one each time in the loop as tib2 increases, and tib4 and hip1 will decrease by 1 each time.
The lines with “pwm.setPWM” are functions that cause the PWM servo to advance the motors to the new position specified by the “for” and “if” statements. Since each motor position only changes 1, the movement is a small movement. By increasing these variables one value at a time, the legs will move slowly and smoothly. In addition, since tib2, fem1, hip3, tib4 and hip1 are involved, these five motors will move at the same time, just as a robot coordinated multiple joints at the same time.
The delay (delayTime) line causes the Nano to stop before each loop of this code. The delayTime variable was defined at the very beginning of all the code, just like the togglePosture variable. However, this variable represents the length of the pause in milliseconds. Thus, it determines how quickly the Nano repeats that piece of code over and over. The pause should be short enough so that the motor does not appear to stop between each incremental movement, otherwise it would move like the seconds hand on an analog watch. By using this pause between each cycle of the code section, the walk will be slower and smoother.
When tib2 reaches 500, the for loop will end and Nano will move on to the next section of code, which will control a different set of movements with different motors.
Unlike walking, the code for the sliding and grabbing movements must be much faster, so the movements do not increase in for loops like walking does. For example, at the beginning of the “skimForward” function is this piece of code:

  fem2 = 330, fem3 = 390; //femurs up pwm.setPWM (5, 0, fem2); pwm.setPWM (9, 0, fem3); if (togglePosture == 0) & # 123; fem1 = 375; pwm.setPWM (1, 0, fem1); fem4 = 300; pwm.setPWM (13, 0, fem4); } delay (10);  

In this code, the values ​​of fem2 and fem3 are changed so that the two legs are lifted up. The two lines pwm.setPWM do these two movements for the motors, without increasing the movement. The “if” statement in this code is intended to check if the robot is in “withdrawal” mode, in which case the next two lines are executed (between the curly braces {}). If the variable togglePosture is not zero, then the robot is in capture mode. The delay (10) function delays the robot by 10 milliseconds to give the motors enough time to reach new positions.
At the end of the complete code, the loop () section is very short and fast and looks like this:

 void loop () & # 123; if (irrecv.decode (& amp; results)) & # 123; if (results.value! = 0xFFFFFF) & # 123; //0xFFFFFF is the & # 34; repeat & # 34; command from the remote, so the robot will ignore it digitalWrite (LED_PIN, LOW); //turn off standby LED val = results.value; irrecv.resume (); switch (val) & # 123; //Which functions to call when button is pressed, buttons were defined before the setup case P & # 58; Pause (); break; case Fr & # 58; forward (); break; case B & # 58; back (); break; case L & # 58; left (); break; case R & # 58; right (); break; case St & # 58; stand (); break; case Lu & # 58; legsUp (); break; case Ld & # 58; legsDown (); break; case lt & # 58; legsTogether (); break; case Eq & # 58; gripPosture (); break; case La & # 58; legsApart (); break; case Sf & # 58; skimForward (); break; case Sb & # 58; skimBack (); break; case Sr & # 58; skimRight (); break; case Sl & # 58; skimLeft (); break; case S & # 58; skimPosture (); break; default & # 58; break; }}} digitalWrite (LED_PIN, HIGH); //turn on the standby LED just in case}  

First line: if (irrecv.decode (& amp; results)) {
This line will activate the Nano to decode the IR signal from the remote if received by the IR sensor.
In the line “val = results.value”, the value of the IR signal is written into a variable named “val”. This variable is then used in a toggle function that compares “val” with various commands, each corresponding to one of the move functions. The Nano will execute this motion function and then go back in code to the beginning of the loop to decode the next IR signal.
The full version of the code can be downloaded below.
Robot_WalkSkimGrip_July2021.ino Step Eleven: Control the Robot with an Infrared Remote Control < br> The real remote control can be seen in the second photo of this article. The remote control buttons make the Nano run a separate function in the code. The button and function name (in quotes) looks like this:
ON/Off = “Pause” – makes the robot go down on the rollers and retract all 4 legs. Useful for offloading motors and therefore the battery.
Vol + = “forward”. The robot will get up, if it has not already done so, and will move forward.
Rev & lt; & lt; = “Left” The robot will get up, if it hasn't already done so, and will turn left.
Play = “stand” The robot will stand up if it hasn't already.
FastForward & gt; & gt; = “Right” The robot will get up, if it has not already done so, and turn right.
Vol- = “back”. The robot will get up and walk back.
Up arrow = “gripUp”. When the robot is in grip mode, the robot raises its front legs.
Down arrow = “gripDown”. When the robot is in grip mode, the robot lowers its front legs.
0 = “gripTogether”. When the robot is in grip mode, the robot zooms in with its front legs.
EQ = “gripPosture” The robot assumes a pose for grip mode. Front legs retracted, hind legs to the sides.
ST/REPT = “gripTogether”. When the robot is in grip mode, the robot moves its legs further apart.
2 = “skimForward” The robot will slide forward, pushing its feet to the sides.
4 = “skimLeft” The robot slides to the left with its legs out to the sides.
5 = “skim” The robot will adopt a slide stance. All four legs will be straight out to the sides.
6 = “skimRight” The robot will slide to the right with its legs out to the sides.
8 = “skimBack” The robot will slide backward, pushing itself to the sides with its feet.
Four-legged crawling robot under control Arduino Everything is ready.
 Four-legged crawling robot under control Arduino

Source:

usamodelkina.ru

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button