Ready-made Arduino robots. Arduino-based four-legged robot Arduino-based tracked vehicle controlled from a cell phone

Good day! Before you, dear ones, is an art robot that can paint various spherical or egg-shaped objects ranging in size from 4 to 9 cm.

To make it, you need a 3D printer, a set of standard tools + Arduino.

Note: Do not give up on projects that use a 3D printer. If desired, you can always find a place or method where you can order the printing of the details necessary for the project.

Step 1: A little about the robot

Art robot - two-axis homemade, which can print on most spherical surfaces. The robot is configured for a certain type of object (ping-pong balls, Christmas decorations, light bulbs and eggs (duck, goose, chicken ...).

High-precision stepper motors with high torque are used to rotate the spherical object and move the manipulator, and a quiet and reliable SG90 servo drive is used to lift the handle mechanism.

Step 2: Required Parts

To make do-it-yourself craft we will need:

  • 2x bearings 623;
  • Hairpin with a diameter of 3 mm and a length of 80-90 mm;
  • 1x spring (length 10mm and diameter 4.5mm);
  • 2x NEMA 17 stepper motors (torque 4.4 kg/cm);
  • Cables for motors (length 14 + 70 cm);
  • USB cable;
  • 1x SG90 servo;
  • Arduino Leonardo;
  • shield JJRobots;

  • 2xA4988 stepper motor drivers;
  • Power supply 12V / 2A;
  • 11x M3 6mm screws;
  • 4x M3 16mm screws;
  • 4x nuts M3;
  • 2x 20mm suction cups;
  • 1x wing nut M3;
  • 1x marker;

Step 3: General scheme

As a "cheat sheet" you can use this scheme.

Step 4: Let's get started!

The robot moves a manipulator with a marker attached to it, which is driven by a stepper motor. Another stepper motor is responsible for turning the object on which the drawing is applied (egg, ball ...). Two suction cups are used to hold the item in place, one attached to the stepper motor and the other on the opposite side of the item. A small spring will press on the suction cup to help it hold the item. The SG90 servo is used to raise/lower the marker.

Step 5: Manipulator

Install the nut in the hole prepared for it and tighten the 16 mm screw. Let's do the same for the item holder (on the right in the image above). When creating the hinge for the manipulator, 2 16 mm screws were used. This hinge should rotate freely after tightening the screws.

Step 6: Suckers

Install one of the suction cups inside the hole in the item holder.

Step 7: Attaching Stepper Motors

Fix both stepper motors to the main frame with 8 screws.

Step 8: Axis of rotation

Let's place all the elements as shown in the image above.

  • Sucker;
  • Screw;
  • Top part;
  • Spring;
  • Bearing 623 (should be built into the left cup);
  • Left cup;
  • Free space for the main frame;
  • Right cup;
  • Bearing 623;
  • Separating ring;
  • Wing nut (M3).

Step 9: Putting Everything in Place

Insert the assembled manipulator onto the axis of the stepper motor.

Install the left support on the axis of the stepper motor.

The marker and egg are set as an example (you don't need to place them now).

NOTE: The servo will require adjustments. You will need to re-set its angle during the calibration process.

Step 10: Electronics

Fix the electronics on the back side of the main frame with screws (2 will be enough).

Let's connect the cables.

If you reverse the polarity when connecting stepper motors, they will simply rotate in the opposite direction, but with a servo the situation is not so harmless! So double check the polarity before connecting!

Step 11: Programming the Arduino Leonardo

Let's program the Arduino Leonardo using the Arduino IDE software environment (v 1.8.1).

  • Download Arduino IDE (v 1.8.1) and install the program;
  • Let's run the software. Select the Arduino Leonardo board and the corresponding COM-PORT in the "tools->board" menu;
  • Let's open and download the Sphere-O-Bot code. Let's unpack all the files inside one folder and call it "Ejjduino_ARDUINO".

Step 12: The Art Robot is Ready to Create Artwork

Step 13: Robot control

Software inkscape. Download and install the Inkscape software (I recommend stable version 0.91).

Download and install the EggBot Control extension (version 2.4.0 has been fully tested).

The EggBot Control extension for Inkscape is a tool to be used when testing and calibrating the EggBot and transferring drawings to the egg. First you need to launch Inkscape. After launching Inkscape, the "Extensions" menu will appear, and in it you already need to select the "Eggbot" submenu. If you don't see the Eggbot submenu, then you didn't install the extensions correctly. Back up and carefully follow the instructions for installing extensions.

That's all, thank you for your attention!)

The result is a rather funny robot, which can see obstacles in front of it, analyze the situation and then, only choosing the best route, goes further. The robot turned out to be very maneuverable. It is able to turn 180 degrees, and the angle of rotation is 45 and 90 degrees. As the main controller, the author used Iteaduino, which is an analogue of Arduino.

Materials and tools for making a robot:
- microcontroller (Arduino or similar Iteaduino);
- ultrasonic sensor;
- holder for batteries;
- Chinese toys to create a wheelbase (you can buy ready-made);
- wire cutters;
- glue;
- wires;
- motors;
- fiberboard;
- jigsaw;
- transistors (D882P).

Robot manufacturing process:

Step one. Creating a wheelbase
In order to create a wheelbase, the author bought two Chinese toy cars. However, you don’t have to worry about this if you have extra money, since you can buy a ready-made base. With the help of wire cutters, the cars were cut into two parts to form two driving axles. These parts were then glued together. However, in this case, you can work with a soldering iron, the plastic is perfectly soldered.

When choosing cars, it is best to take toys with ordinary wheels, since, according to the author, with spikes like his, the robot jumps a lot.

There is another such moment when wires will be output from the motors, on one of them you need to remember to change the polarity.


Step two. Making the top cover
The top cover of the robot is made of fiberboard, and thick cardboard can also be used for this purpose. A rectangular hole can be seen in the cover, it must be located so that the axis of the servo, which will be inserted into it, is symmetrical. As for the hole in the middle, wires will be output through it.


Step three. Robot stuffing
It is best to use a separate power supply to connect the chassis, since the controller requires 9V to power it, and only 3V for the motors. In general, battery holders are already built into the chassis of such machines, they just need to be connected in parallel.








The motors are connected to the controller using transistors of the D882 P type. They were pulled out of the old machine control panel. It is best, of course, to use power transistors of the TIP120B type, but the author chose simply according to suitable characteristics. The entire electronic part is connected according to the specified scheme.

After the firmware of the robot, it will be ready for testing. In order for the robot to have time to turn around at a certain angle, you need to choose the right time for the operation of the motors.

As for the sensors, the ultrasonic one must be connected to the 7th digital output of the microcontroller. The servomotor is connected to the 3rd digital input, the base of the transistor of the left motor is connected to the 11th pin, and the base of the right motor to the 10th.

If Krona is used as power, then the minus is connected to GND, and the plus to VIN. You also need to connect the emitter of the transistor and the negative contact from the power supply of the robot chassis to GND.

Let's talk about how you can use Arduino to create a robot that balances like a Segway.

Segway from English. Segway is a two-wheeled standing vehicle equipped with an electric drive. They are also called gyroscooters or electric scooters.

Have you ever wondered how a Segway works? In this tutorial we will try to show you how to make an Arduino robot that balances itself just like a Segway.

In order to balance the robot, the motors must counteract the fall of the robot. This action requires feedback and corrective elements. Feedback element - , which provides both acceleration and rotation in all three axes (). The Arduino uses this to know the robot's current orientation. The corrective element is the combination of engine and wheel.

The end result should be something like this:

Robot scheme

L298N Motor Driver Module:

DC Gear Motor with Wheel:

A self-balancing robot is essentially an inverted pendulum. It can be better balanced if the center of mass is higher relative to the wheel axles. A higher center of mass means a higher mass moment of inertia, which corresponds to a lower angular acceleration (slower fall). That's why we put the battery pack on top. However, the height of the robot was chosen based on the availability of materials 🙂

The completed version of the self-balancing robot can be seen in the figure above. At the top are six Ni-Cd batteries to power the PCB. Between motors, a 9-volt battery is used for the motor driver.

Theory

In control theory, holding some variable (in this case the position of the robot) requires a special controller called a PID (Proportional Integral Derivative). Each of these parameters has a "gain", commonly referred to as Kp, Ki and Kd. The PID provides a correction between the desired value (or input) and the actual value (or output). The difference between input and output is called "error".

The PID controller reduces the error to the smallest possible value by continuously adjusting the output. In our self-balancing Arduino robot, the input (which is the desired slope in degrees) is set by the software. The MPU6050 reads the robot's current tilt and feeds it into a PID algorithm that performs calculations to control the motor and keep the robot upright.

The PID requires that the Kp, Ki and Kd values ​​be set to optimal values. Engineers use software such as MATLAB to automatically calculate these values. Unfortunately, we can't use MATLAB in our case because it will complicate the project even more. Instead, we will tune the PID values. Here's how to do it:

  1. Set Kp, Ki and Kd to zero.
  2. Adjust Kp. Too little Kp will cause the robot to fall because the fix is ​​not enough. Too much Kp makes the robot go wild back and forth. A good Kp will make the robot lean back and forth quite a bit (or oscillate a bit).
  3. Once Kp is set, adjust Kd. A good Kd value will reduce the oscillations until the robot is almost stable. Also, a proper Kd will keep the robot even if pushed.
  4. Finally, install Ki. When turned on, the robot will oscillate even if Kp and Kd are set, but will stabilize over time. The correct Ki value will shorten the time required for the robot to stabilize.

The behavior of the robot can be seen below in the video:

Arduino code for a self-balancing robot

We needed four external libraries to create our robot. The PID library makes it easy to calculate P, I and D values. The LMotorController library is used to control two motors with the L298N module. The I2Cdev library and the MPU6050_6_Axis_MotionApps20 library are designed to read data from the MPU6050. You can download the code including libraries in this repository.

#include #include #include "I2Cdev.h" #include "MPU6050_6Axis_MotionApps20.h" #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE #include "Wire.h" #endif #define MIN_ABS_SPEED 20 MPU6050 mpu; // MPU control/status vars bool dmpReady = false; // set true if DMP init was successful uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU uint8_t devStatus; // return status after each device operation (0 = success, !0 = error) uint16_t packetSize; // expected DMP packet size (default is 42 bytes) uint16_t fifoCount; // count of all bytes currently in FIFO uint8_t fifoBuffer; // FIFO storage buffer // orientation/motion vars Quaternion q; // quaternion container VectorFloat gravity; // gravity vector float ypr; // yaw/pitch/roll container and gravity vector //PID double originalSetpoint = 173; double setpoint = originalSetpoint; double movingAngleOffset = 0.1; double input, output; //adjust these values ​​to fit your own design double Kp = 50; double Kd = 1.4; double Ki = 60; PID pid(&input, &output, &setpoint, Kp, Ki, Kd, ​​DIRECT); double motorSpeedFactorLeft = 0.6; double motorSpeedFactorRight = 0.5; //MOTOR CONTROLLER int ENA = 5; int IN1 = 6; int IN2 = 7; int IN3 = 8; int IN4 = 9; int ENB = 10; LMotorController motorController(ENA, IN1, IN2, ENB, IN3, IN4, motorSpeedFactorLeft, motorSpeedFactorRight); volatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has gone high void dmpDataReady() ( mpuInterrupt = true; ) void setup() ( // join I2C bus (I2Cdev library doesn't do this automatically) #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE Wire.begin( ); TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz) #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE Fastwire::setup(400, true); #endif mpu.initialize(); devStatus = mpu.dmpInitialize(); // supply your own gyro offsets here, scaled for min sensitivity mpu.setXGyroOffset(220); mpu.setYGyroOffset(76); mpu.setZGyroOffset(-85); mpu.setZAccelOffset(1788); // 1688 factory default for my test chip // make sure it worked (returns 0 if so) if (devStatus == 0) ( // turn on the DMP, now that it's ready mpu.setDMPEnabled(true); // enable Arduino interrupt detection attachInterrupt(0 , dmpDataReady, RISING); mpuIntStatus = mpu.getIntStatus(); // set our DMP Ready flag so the main loop() function knows it"s okay to use it dmpReady = true; // get expected DM P packet size for later comparison packetSize = mpu.dmpGetFIFOPacketSize(); //setup PID pid.SetMode(AUTOMATIC); pid.SetSampleTime(10); pid. SetOutputLimits(-255, 255); ) else ( // ERROR! // 1 = initial memory load failed // 2 = DMP configuration updates failed // (if it"s going to break, usually the code will be 1) Serial.print(F("DMP Initialization failed (code ")); Serial.print(devStatus); Serial.println(F(")")); ) ) void loop() ( // if programming failed, don"t try to do anything if (!dmpReady ) return; // wait for MPU interrupt or extra packet(s) available while (!mpuInterrupt && fifoCount< packetSize) { //no mpu data - performing PID calculations and output to motors pid.Compute(); motorController.move(output, MIN_ABS_SPEED); } // reset interrupt flag and get INT_STATUS byte mpuInterrupt = false; mpuIntStatus = mpu.getIntStatus(); // get current FIFO count fifoCount = mpu.getFIFOCount(); // check for overflow (this should never happen unless our code is too inefficient) if ((mpuIntStatus & 0x10) || fifoCount == 1024) { // reset so we can continue cleanly mpu.resetFIFO(); Serial.println(F("FIFO overflow!")); // otherwise, check for DMP data ready interrupt (this should happen frequently) } else if (mpuIntStatus & 0x02) { // wait for correct available data length, should be a VERY short wait while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount(); // read a packet from FIFO mpu.getFIFOBytes(fifoBuffer, packetSize); // track FIFO count here in case there is >1 packet available // (this lets us immediately read more without waiting for an interrupt) fifoCount -= packetSize; mpu.dmpGetQuaternion(&q, fifoBuffer); mpu.dmpGetGravity(&gravity, &q); mpu.dmpGetYawPitchRoll(ypr, &q, &gravity); input = ypr * 180/M_PI + 180; ) )

Kp, Ki, Kd values ​​may or may not work. If they don't, follow the steps above. Note that the tilt in the code is set to 173 degrees. You can change this value if you like, but note that this is the angle the robot must support. Also, if your motors are too fast, you can adjust the motorSpeedFactorLeft and motorSpeedFactorRight values.

That's all for now. See you.

It is very easy to make different cars with remote control, simple sensors and logic on Arduino. Therefore, this line is incredibly popular. Many compatible sensors and expansion boards are sold. The Internet is filled with ready-made software libraries and open source projects for all occasions. Almost all the questions that you will have in the process of mastering Arduino have already been asked by someone, and you will always find the answer.

Let's start with something, shall we? The main issue is the choice of controller. There are many revisions of Arduino, as well as third-party clones built from those revisions. Here are perhaps the two most interesting classes for us:

  • Arduino Uno is the best choice for a beginner, the simplest, most affordable and most common board. It is based on an ATmega328 chip with a clock frequency of 16 MHz, 32 KB of flash memory, 2 KB of RAM and 1 KB of EEPROM. Uno has 14 digital inputs/outputs that can be used to control sensors and servos and other devices;
  • The Arduino Mega / Mega 2560 is a board that will come in handy when you know in advance that the project will be difficult. The main difference is more inputs/outputs (48 in Mega, 54 in Mega 2560). There is also much more memory here: 8 KB of RAM, 4 KB of EEPROM, and flash memory of 128 and 256 KB (in Mega and Mega 2560, respectively). Between themselves, the boards also differ in chip, USB speed and some other characteristics.

Of course, there are also Arduino Pro, Arduino LilyPad and many others. But now let's focus on the first two models. In our case, everything is quite simple: Mega is needed for a robot with a lot of legs.

First code

First, let's install the Arduino IDE (arduino.cc) - this is a free cross-platform development environment. Now, if we connect our Arduino, we can try to write the first code on the simplest example: the blinking LED program. Most Arduino controllers have it and are connected to pin 13. By the way, in the Arduino world, programs are commonly called sketches. Here is the text of the sketch with comments:

// Give this pin the name LED: const int LED = 13; void setup() ( // Initialize digital pin // for output: pinMode(LED, OUTPUT); ) void loop() ( // Set logic-one level // to pin 13 (light LED): digitalWrite(LED, HIGH) ; // Pause the sketch // for a second: delay(1000); // Apply a logic zero level // to pin 13 (turn off the LED): digitalWrite(LED, LOW); // Pause the sketch again for a second: delay(1000); )

Notice the setup and loop functions. They must be present in any Arduino sketch. Setup is called once when the controller is turned on or after the controller is restarted. If you want the code to be executed only once, it should be placed here. Most often, these are all kinds of initialization procedures for something. Our sketch is no exception: Arduino digital pins can work as both inputs and outputs. In the setup function, we say that pin 13 will work as a digital output of the controller.

After the setup function completes its work, a closed loop is automatically launched, inside which the loop function will be called. We are required to write what we want to do there. And we want to apply a logic one level (5 V) to pin 13, that is, light the LED, then wait one second (1000 in milliseconds), then apply a logic zero level (0 V) and again wait one second. The next call to loop will repeat everything.

Now we “upload” our sketch to the controller. No, we don't need a programmer. Arduino controllers, in addition to our sketches, contain a special program - bootloader, which, in particular, controls the loading of code from a computer. So to upload the sketch, we only need a USB cable and the menu item File → Upload (Ctrl + U) in the Arduino IDE.

key question

How many legs do we actually need? Let's define in a variety of configurations of walking robots. By number of legs:

  • biped - two-legged (prototype - man);
  • quadruped - four-legged (prototype - most mammals);
  • hexapod - six-legged (prototype - most insects);
  • octopod - eight-legged (prototype - spiders, scorpions, crabs and other arthropods).

In addition to the number of legs, the configuration of each is also important. The main characteristic of the leg is the number of degrees of freedom, or dimensions of freedom (DOF). The degree of freedom is the ability to rotate or bend around one axis (less often, to move forward along it). Obviously, if there is only one degree of freedom, then you will not go far on such a leg. Legs with two degrees of freedom (2DOF) already allow multi-legged robots to move, although 2DOF allows free movement of the tip of the leg in only one plane. And the 3DOF leg moves the “foot” in 3D space (unless, of course, all three axes are parallel). There are also 4DOF legs that simply increase the flexibility and range of movement of the leg. Insects most often have 4DOF legs.

What does this mean for us? In cheap amateur robots, each degree of freedom is implemented by one motor, more precisely, a servo drive, or serv. The configuration of the legs uniquely determines how many of these servos are needed. So a 3DOF hexapod would require 18 servos, and a 4DOF spider would require 32. Don't be intimidated by the numbers, the small servos used in amateur RC models are very cheap. In online stores, they can be found on request micro servo.

To program servos, it is enough to know that they already have a controller that does the main work. And all that is needed is to supply power and a digital signal that tells the controller in which position we want to turn the drive shaft. It is easy to find information about their design. Their protocol is the simplest of all digital communication protocols: pulse-width modulation - PWM (PWM in English). All simple servos have a three-pin connector: ground, +5V (voltage may vary depending on size and power) and a signal input. Arduino controllers can generate this signal in two different ways. The first is hardware PWM, which the chip itself can output on several of its digital I/O pins. The second is software. Software allows you to receive more different PWM signals at the same time than hardware. A convenient wrapper is provided for it under Arduino - the Servo library. It allows you to use 12 servos simultaneously on most small-sized controllers (Uno, Due, Nano) and 48 servos on Arduino Mega and the like. The signal pin of the servo is connected to the digital pin of the Arduino. Ground and power - obviously, to ground and power, they can be shared by all servos. In three-wire servo loops, black or brown is ground, usually red +5 V in the middle, and finally white or yellow is signal. From a software point of view, control is extremely simple:

Servo myservo; // Servo on Arduino pin 9 myservo.attach(9); // Rotate to position 90º myservo.write(90);

Most servos can rotate the shaft 180°, and for them 90° is the middle position. To simplify the connection of servos to the Arduino board, there are a number of solutions. The most canonical is the Sensors Shield. By installing it on the Uno and supplying power to the terminals for the servos, you can connect their connectors directly to it.

Battery

Another important issue is nutrition. If you have an advanced board that allows you to supply the entire system through one power line (and the servo motors will not interfere with the operation of the controller), then you can get by with one source. The choice is huge, best of all, of course, Li-Ion / Li-Po briquettes for radio models. But they also need the appropriate chargers. If you have a simpler controller (Uno / Due / Nano), then you can power it separately, for example, with a 9-volt Krona, and connect the servos to the main powerful battery. So the servos will definitely have enough power. In the case of lithium batteries, you need to monitor the voltage even more carefully than usual so that there is no overdischarge (the allowable voltages should be clarified for a particular type of battery). To do this, a small digital voltmeter is also screwed onto the Sleipnir robot, which will be discussed further.

Robobug do it yourself

Kit

  • Arduino Uno controller: 1150 rubles
  • Three servomotors. I used HXT500, 200 r. a piece
  • Battery compartment for "Krona" with a switch: 50 rubles.
  • Battery "Krona": 145 rubles.
  • IR receiver: $90
  • Steel wire with a diameter of approximately 1.5 mm. For example, I used a broken egg beater

Total: 2035 p.

DmitryDzz: I want to invite you to make a small remote-controlled six-legged robotic beetle based on the Arduino Uno controller. The paws will have one degree of freedom, the control will take place using a conventional TV remote control.

I must say that these are the prices of expensive Moscow stores. In Chinese online stores, all this will cost two times cheaper. Considering shipping. True, you will have to wait, in my experience, from two weeks to three months.

An easier way is to take a constructor set, because in the first steps one controller will not be enough. Now many shops offer such sets. For example, there is a wonderful online store "Amperka". Here you will be offered several similar designers, differing in fullness and, of course, in price. The simplest thing was enough for me - "Matryoshka X". It includes an Arduino Uno controller, a USB cable for connecting to a computer, a prototyping board (an indispensable thing!), a set of jumpers, LEDs, resistors and other trifles.

In the same store there is a "Wiki" section, where you will even find wonderful short video tutorials translated into Russian. Be sure to check them out. And of course, there is a forum where they will probably try to help you.

What you need from the tools:

  • soldering iron and everything you need for soldering. You don’t have to solder much, and you don’t need much skill;
  • hot glue gun and rods to it;
  • pliers for working with wire.

If you've got everything, let's get started!

Control

Let's move on to the first step: we need to learn how to interact with the remote control and find out the codes for pressing some of its buttons. These codes will then come in handy for the robot control sketch.

At this stage, you will also need an IR receiver and it would be nice to have a prototyping board. The vast majority of IR remotes operate at carrier frequencies of 36 kHz, 38 kHz, or 40 kHz (Panasonic, Sony). The exceptions are Sharp (56 kHz), Bang & Olufsen (455 kHz), and maybe someone else more exotic. Therefore, any IR receiver at 36, 38 or 40 kHz is quite suitable for us. The frequency may not exactly match the carrier frequency of the signal. In this case, the sensitivity of the receiver will decrease, but in practice I did not notice any discomfort using the TSOP2136 IR receiver (36 kHz - the last two digits - frequency) and the Sony remote control (40 kHz).

So, IR receivers TSOP21xx, TSOP22xx, TSOP312xx are suitable for most remotes. The last two digits can be 36, 37, 38 or 40. Before turning on the IR receiver, check the pinout of its pins - there are only three of them: + 5V (power), GND (ground), Vs (output). Let's assemble the circuit, as in the illustration (wiring for TSOP2136).


As you can see, we connected the output of the IR receiver to the analog input of the A0 controller.

Here's what the sketch code looks like:

#include "IRremote.h" // Analog input of the controller // to which the IR receiver is connected: const int IR_PIN = A0; // Create an IR receiver object: IRrecv irrecv(IR_PIN); void setup() ( Serial.begin(9600); Serial.println("ready"); // Start listening to IR signals: irrecv.enableIRIn(); ) void loop() ( // Describe the structure results, / / where // received and decoded // IR commands will be placed: decode_results results; // If the IR command is accepted and // successfully decoded, then output // the received code to the // serial port of the controller: if (irrecv.decode (&results)) ( Serial.println(results.value); irrecv.resume(); ) )

The sketch uses a special library IRremote.h, which decodes the signals of various IR remotes. This library is an open project, you can download it from https://github.com/shirriff/Arduino-IRremote. And to connect it to our project, you need to perform three steps:

  • copy the library directory to the libraries directory, which, in turn, is located in the Arduino IDE installation directory;
  • restart IDE;
  • add the line #include "IRremote.h" to the beginning of our sketch.

Now the IR decoding functions will be available in the sketch. But to see the resulting codes, we will still use the Serial object. With its help, via the serial port (same USB cable), we will transfer the codes to the computer. In the setup function, we initialize the Serial object. "9600" is 9600 baud - the rate that will be used for data transfer. After initialization, we can write to the serial port using the println function. To view the result of this output on the computer in the Arduino IDE, select the menu item Tools → Serial Monitor (Ctrl + Shift + M). Just make sure it's set to 9600 baud.

So, the controller receives power via a USB cable, and transmits data via it. We load the sketch, launch the Serial Monitor and start pressing the buttons on the remote control. Codes should appear in the Serial Monitor window. Remote control protocols are different, sometimes it can be one code, sometimes several. In any case, you can always allocate codes that are unique to each button on the remote.

We need 13 remote control buttons. I used the following:

  • 1 - smooth turn to the left;
  • 2 - moving forward;
  • 3 - smooth turn to the right;
  • 4 - turn left on the spot;
  • 5 - stop;
  • 6 - turn right on the spot;
  • 7 - movement back with a turn to the right;
  • 8 - backward movement;
  • 9 - movement back with a turn to the left;
  • blue button - very slow;
  • yellow - slowly;
  • green - fast;
  • red - very fast.

Write down the codes for these buttons, you will need them later for the robot control sketch.

Movement algorithm

The robot control sketch is available on our project page (bit.ly/1dEwNDC). Do not forget to change the values ​​of the constants of the codes of the pressed remote control buttons to the codes of your remote control (the IR_COMMAND_XXX_CODES constants in the ir_command_codes.h file).

We will not analyze the sketch in detail, I think comments in the code are enough, but one question is still worth considering.

Insect movements are very interesting. And although all these beetles fall very close to the ground, for some reason they are always stable: at any given time, at least three legs (two on one side and one on the other) stand on the surface. And while these legs are pulling the beetle towards one of its driven targets, the other three are pulled up to repeat this movement. Our goal is to do something similar.

Our robot bug has three servomotors arranged in a row perpendicular to the movement. For the left and right servomotors, the shaft axis is directed upwards, and for the central one, it is forward. The task, for example, of the left servo is to pump two legs at once: the left front and the left back. By the way, they are rigidly interconnected and glued to the rocker of this servo. The task of the central servo is to lift the left side of the beetle, then the right. Therefore, the central left and right legs are attached to the rocker of this engine, which are a single U-shaped part.

The sketch should ensure that the robot moves forward, backward, smooth turns in motion and turns in place. And I would also like to control the speed of the beetle. To describe these movements programmatically, we need mathematics. Look at the diagram.


The blue circles indicate the legs of the robot beetle, standing on the surface, and the white circles are those in the air. Please note that when moving forward or backward, the left and right servomotors must move exactly the same way. And when turning in place, the engines should spin in different directions (symmetrically). It is also interesting that the forward and backward movement differs only in the phase of the central servomotor.

So how is it implemented? We remember that the controller constantly calls the loop function. So, in this function we must put the code that determines the current position of the servos and sets them to this position. Each servomotor must oscillate. We can calculate the position of the servomotor at time t using the following formula:

X = A sin(2πt/T),

where X is the desired position of the servomotor, A is the oscillation amplitude, T is the oscillation period.

So, depending on the moment of time t, we will get a change in the value of X in the range from -A to +A. The servomotors can take position in the range from 0 to 180°. Therefore, it is better for us to oscillate around the “zero” position at 90 °. And if we want to provide oscillations with a period of 1 s around the position of 90 ° with an amplitude of 30 °, then the formula is converted into the following form:

X = 90 + 30 sin(2πt/1000),

where t is the time in milliseconds since the start of the oscillation. To control the speed of the robocall, we can change the oscillation period. The larger it is, the lower the speed.

And now let's go back to our scheme again, because the formula written above is not yet complete. How to ensure that the synchronous, then the opposite movement of the left and right servomotor? How to change the phase of the central servomotor? We have to add the oscillation phase to our formula. Shifting the sine argument by π for, for example, the right engine will make it work in antiphase to the left one, that is, the way we need to turn in place. Here's what our formula will look like now:

X = 90 + 30 sin(2πt/1000 + Φ),

where Φ is the phase of the oscillations, the value is from 0 to 2π.

Look at the table to understand what the oscillation phases of the servomotors should be for each type of movement.

Assembly

Now let's assemble the robot on the prototyping board and fill in the control sketch.

This is a very important step before assembly. Try disconnecting the USB cable and powering the layout from the Krona battery. Check all phases of the movement and make sure everything works. After assembling the robot, changing anything (for example, replacing a broken servomotor) will be more difficult.


Now let's move on to the assembly itself. The main bearing element is the battery compartment. I advise you to use a closed type compartment and always with a switch.

The easiest way to fix the details of the beetle is with hot glue. Start with servomotors. Remove unnecessary fastening ears and connect the cars together. Then glue this assembly of three "servos" to the battery cover. Do not forget that the battery compartment must open freely to change the battery.

The easiest way is to glue the controller to the bay, but I do not really like this option, as I will have to give the Arduino Uno to the bug forever. Therefore, you can complicate your life and use the Arduino connectors to attach the battery compartment. Glue a pin connector on the bottom of the compartment with a 2.54 mm pitch between the pins. It should be located so that it enters the controller socket in the area of ​​​​digital outputs 8-11. We still don't need them anyway. If the connector is not at hand, a U-shaped curved paper clip will do.

The wires coming from the battery compartment must be connected to the Vin terminals and the GND adjacent to it. Don't reverse the polarity! Plus "Krona" on Vin, minus on GND. To ensure reliable contact of the wires with the Arduino connectors, you can simply tin the tip of the wire thicker, but I used a short piece of paper clip as a plug. And the place of soldering was closed with heat shrink tubing.


The connectors from the servo cables should be cut off, the power wires (+5 V - usually red and GND - black or brown) should be combined and connected to the 5V jacks and the adjacent GND on the controller. We will connect a little later. The control signal wires (usually yellow) are output to the digital outputs of the controller: the left servomotor is on pin 2, the center one is on pin 4, the right one is on pin 7.

The "+" and "-" of the IR receiver can simply be plugged into the Arduino connector (5V and adjacent GND). True, bending in half, doubling their thickness. We solder the previously connected power wires to the servomotors to the same power legs of the IR receiver. The signal output of the IR receiver is unlikely to reach the analog input of the A0 controller, and you will have to increase it with a wire.

A few tips for making legs. First, prepare the left and right "front-back" legs. Make sure they are symmetrical (pay attention to both the lengths and the angles of the bends). Start gluing the legs only after making sure that the servomotors are set to the "zero" position (90°).

Place the middle pair of legs last. I advise you to first make the middle legs longer, and then after installation, cut them to the desired length. In the "zero" position, all six feet should be on the surface. The rolling of the middle legs with an amplitude of 15° should not interfere with the front-back turns.

What's next?

Robobug is a ready-made mobile platform based on one of the most popular and affordable controllers. The project is open: https://github.com/beetle-ringo/arduino . Make a fork (branch) in GitHub and add your functionality. Let your imagination run wild - add an IR LED and the robot is ready for robot battle. Connect rangefinders, tactile sensors, a gyroscope... Teach the robot to bypass obstacles or walk along a line, try installing a webcam on it. There can be a million ideas, and you can always choose the most interesting one.

Robot Sleipnir

Kit

  • Arduino Uno Dagu Spider Robot Controller: $2530
  • Servo drives SG90 9g (16 pieces) 1150 р.
  • LiPo battery pack, 7.4 V, 1800 mAh $4.99
  • Radio module 4 Pin Bluetooth RF Transceiver 270 р.
  • Voltage indicator (optional) DC 3.3-30V Red LED Panel Meter $100
  • Aluminum corner. In the nearest construction market 135 rubles.
  • Bolts and nuts. At the nearest flea market 35 rubles.

Total: 4710 r.

*Components were purchased at different times and many positions can be optimized

poconoco: Let's try to assemble a non-standard configuration - an eight-legged 2DOF robot. 2DOF legs are much easier to program, plus I have a bunch of unused servos in stock. And most importantly, it will be possible to name it in honor of the eight-legged horse of the god Odin Sleipnir (always dreamed of!).

Our Sleipnir will have four legs with two hinges on each side. Each joint is a servo, so eight servos per side. For simplicity, all eight hinges of one side of the horse will rotate in the same plane. Although this is not at all necessary. Moreover, if the legs on one side are put in a little "chess" so that two adjacent legs cannot touch each other, it will be even better, it will allow you to take a wider step and gallop.


A neat and functional, but far from the cheapest solution is to use a non-standard controller board, optimized for connecting servos in large numbers. I came across a Dagu Spider Robot Controller - this is the same Arduino Mega, but on a board with pre-soldered 3-pin pin connectors, where you can immediately connect those same 48 servos without any shields. Ideal for multi-legged Arduino robots.

Control

We will be controlled via Bluetooth. There are various hardware solutions for this. These are shields, and separate scarves with a UART serial interface (like a regular com port, only with 5 V signal levels). It seemed to me the most practical was a small scarf with a UART interface. Connects to the corresponding UART/Serial pins on the Arduino port. We note two nuances: there is only one such port on Uno / Due / Nano and the like, and it is also used for flashing via USB. Therefore, you may need to turn off the Bluetooth module during the firmware. And the second nuance - do not forget that the RX-pin of the module is connected to the TX-pin of the Arduino, and TX - to RX. Such things are in the UART.

Bluetooth programming is no more difficult than servos, data can be read byte by byte, which we will use:

Charcmd; Serial.begin(9600); if (Serial.available()) cmd = Serial.read();

If Arduino Mega is used and Bluetooth is connected to the second port, then Serial1 is written instead of Serial. It is noteworthy that you can not use Bluetooth, but control the robot directly via USB. And nothing will change in the code above! It's just working with a serial port, and whether a BT transmitter or a USB Serial converter hangs there - it doesn't matter to us.

The Other Side of Bluetooth

The most convenient way to connect is through standard Linux utilities. To work, we need the sdptool, rfcomm utilities (included in the bluez package in the Ubuntu repositories), as well as minicom (the package is called so). Instructions for using these utilities can be found on the Web.

Movement algorithm


For a hexapod, the simplest gait will be this: the legs are divided into two groups of three legs, and one of the groups is completely on the ground, the other is in the air, rearranged forward. This is far from the only possible gait. You can keep only two paws in the air, or even one, and the remaining four or five on the ground. For an octapod, there are also many gaits. We will take the simplest, also with two groups of four legs.

So what do we need to do to work with 16 servos and a chosen gait? The correct answer is to read about inverse kinematics (IK). The volume of the article does not allow expanding the topic widely, but there are plenty of materials on the Internet. In short, IR solves the problem of finding the necessary control signals in order for the system to take the desired position in space. For the leg, this means that according to the coordinates of the point where the foot should hit, it is necessary to determine the angles of the servos that need to be set for this. And by controlling the coordinates of the feet, you can control the position of the body. We have 2DOF legs, the axes are parallel, so the foot always moves in the same plane. The IR problem in this case is reduced to a 2D space, which greatly simplifies it.

Let for each leg the local origin O be the shaft of the upper servo, that is, the thigh. And we have the coordinates of point A, where the foot needs to hit. Then it is easy to see that it is necessary to solve the problem of finding the intersection points of two circles (see the diagram of the legs of one side, this is illustrated there on the rightmost leg). Having found the point B of the intersection of the circles (selecting any of them), it is easy to calculate the desired angles using the conversion from Cartesian coordinates to polar ones. In code, the solution to this problem looks like this:

Float A = -2*x; float B = -2 * y; float C = sqr(x) + sqr(y) + sqr(hipLength) - sqr(shinLength); float X0 = -A * C / (sqr(A) + sqr(B)); float Y0 = -B * C / (sqr(A) + sqr(B)); float D = sqrt(sqr(hipLength) - (sqr(C) / (sqr(A) + sqr(B)))); float mult = sqrt(sqr(D) / (sqr(A) + sqr(B))); float ax, ay, bx, by; ax = X0 + B*mult; bx = X0 - B*mult; ay = Y0 - A*mult; by = Y0 + A*mult; // or bx for another point of intersection float jointLocalX = ax; // or by for another intersection point float jointLocalY = ay; float hipPrimaryAngle = polarAngle(jointLocalX, jointLocalY); float hipAngle = hipPrimaryAngle - hipStartAngle; float shinPrimaryAngle = polarAngle(x - jointLocalX, y - jointLocalY); float shinAngle = (shinPrimaryAngle - hipAngle) - shinStartAngle;

where x and y are the coordinates of the point where you need to reach with your foot; hipStartAngle - the angle by which the "hip" is initially turned (with the servo in the middle position), similarly - shinStartAngle. By the way, in these calculations, the angles are obviously in radians, and they need to be transferred to Servo objects already in degrees. The full working firmware code, including this piece, is posted on GitHub, see the link at the end of the article. This is a piece of IC, but besides that, you need some pretty simple code to use this IC on all legs (see legsReachTo(), legWrite() functions). You will also need code that actually implements the gait - the movement of one group of legs "back" (so that the robot moves forward), while the other group of legs rises and moves forward for the next step, see the stepForward () function. She takes one step with the given parameters. These parameters, by the way, can take a step back, despite the name of the function. If this function is called in a loop, the robot will step forward.

Now receiving commands and their interpretation. Let's add a state to the program:

Enum State ( STOP, FORWARD, BACKWARD, FORWARD_RIGHT, FORWARD_LEFT );

And in the main loop() execution loop, we will look at the current state (state variable) and pull stepForward() if we are moving forward (with or without rotation), and again stepForward(), but with a negative xamp argument, if we need to move backward . Turns will then be handled in legWrite(), and for a right turn the legs on the right side will stand still (while the left rows). Here is such a horse-tank. Brutal, but very simple and works. Smooth turning can only be done with 3DOF legs, an example of this can be seen in the buggybug repo.

Switch (state) ( case FORWARD: case FORWARD_RIGHT: case FORWARD_LEFT: stepForward(h, dh, xamp, xshift); break; case BACKWARD: stepForward(h, dh, - xamp, xshift); break; )

Char command; while (Serial1.available()) command = Serial1.read(); switch (command) ( case "w": state = FORWARD; break; case "s": state = BACKWARD; break; case "d": state = FORWARD_RIGHT; break; case "a": state = FORWARD_LEFT; break; default : state = STOP; )

On this, the main points of the firmware are over, the rest is all small things. Although there is one more, perhaps, important point - the ability to fine-tune the servos. Even with the most careful assembly, if all the servos are commanded to turn 90°, some of them will still turn out to be slightly off-angle. That's why you need to be able to customize it. You can see how I did it in the hipsWrite() and shinsWrite() methods and in the hipsTune and shinsTune fine-tuning arrays.

Assembly

For such structures, nothing special is needed: a sheet of plexiglass of suitable thickness (from the nearest household flea market) and a jigsaw or hacksaw will do to cut out the details. And of course, a drill to drill holes. Instead of plexiglass, you can use plywood (then you can still make a commemorative inscription on the final design with a burner). Aluminum sheets or corners can also be used. With Sleipnir, I went just the way of using an aluminum corner with 1 cm ribs (I bought it somewhere in a hardware supermarket).


The base will be a rectangular frame. Limbs - 4-centimeter stripes. It is also worth stocking up with a lot of small bolts, nuts. We cut the corner into the necessary pieces, cut out grooves for servos, drill holes for mounting bolts and screws. The design is better to show than to describe. The sizes can be any, robots should be various. But remember: the longer the legs, the more leverage the servo will have to push and the greater the load on it. Up to the impossibility to turn around and even breakage. But 4–5 cm is no problem.

For budget lightweight robots, they often do not bother with a separate swivel of the limbs, and the entire load falls entirely on the servo shaft. With a small weight, this is not at all critical. And with more weight, you should think about servos with metal gears and a ball bearing shaft.

Each servo usually comes with a couple of screws and a set of bits that can be screwed onto the shaft for a variety of applications. A single "horn" (or horn) is most suitable for us, which allows you to attach a bar to the servo. So, the axes of two servos are attached to one bar, and the bar becomes a “thigh”. In this case, one serv is attached to the body, and the other becomes part of the lower leg. It is worth screwing another bar to it, just to lengthen or make the limb more interesting. A little hard work - and the platform is ready (handy sets of screwdrivers, wrenches, tweezers, wire cutters, etc. greatly speed up the process).

What's next?

The entire project is available at https://github.com/poconoco/sleipnir. I described one of the most impractical configurations - a lot of 2DOF legs, tall, narrow, easily falls on its side. Try to make a better robot with 3DOF legs. With 4DOF legs. With claws or jaws. As an example of 3DOF inverse kinematics, you can refer to the buggybug repository - there is a hexapod firmware. You can also make not controlled, but intelligent robots, putting distance sensors instead of Bluetooth, and teach the robot to bypass walls and obstacles. If you put such a sensor on a servo drive and rotate it, then you can scan the area, almost like a sonar.

Hello. This article is a short story about how do robot their hands. Why a story, you ask? All due to the fact that for the manufacture of such crafts it is necessary to use a significant amount of knowledge, which is very difficult to present in one article. We'll walk through the build process, take a peek at the code, and ultimately bring the creation of Silicon Valley to life. I advise you to watch the video in order to have an idea of ​​\u200b\u200bwhat should happen in the end.

Before moving on, please note the following, that in the manufacture crafts used a laser cutter. You can refuse a laser cutter if you have sufficient experience in working with your hands. Accuracy is the key to completing a project successfully!

Step 1: How does it work?

The robot has 4 legs, with 3 servos on each of them, which allow it to move its limbs in 3 degrees of freedom. He moves with a "creeping gait". Let it be slow, but one of the smoothest.

First you need to teach the robot to move forward, backward, left and right, then add an ultrasonic sensor, which will help detect obstacles / obstacles, and after that a Bluetooth module, thanks to which the robot control will reach a new level.

Step 2: Required Parts

Skeleton made of plexiglass 2 mm thick.

The electronic part of the homemade product will consist of:

  • 12 servos;
  • arduino nano (can be replaced with any other arduino board);

  • Shield for servo control;
  • power supply (in the project, a 5V 4A power supply unit was used);

  • ultrasonic sensor;
  • hc 05 bluetooth module;

In order to make a shield you will need:

  • circuit board (preferably with common lines (buses) of power and ground);
  • inter-board pin connectors - 30 pcs;
  • sockets per board - 36 pcs;

  • wires.

Instruments:

  • Laser cutter (or skillful hands);
  • Super glue;
  • Hot glue.

Step 3: Skeleton

Let's use a graphics program to draw the component parts of the skeleton.

After that, in any available way, we cut out 30 parts of the future robot.

Step 4: Assembly

After cutting, remove the protective paper coating from the plexiglass.

Next, proceed to the assembly of the legs. Fasteners built into parts of the skeleton. All that remains to be done is to put the pieces together. The connection is quite tight, but for greater reliability, you can apply a drop of superglue to the fasteners.

Then you need to modify the servos (glue a screw opposite the servo shafts).

With this refinement, we will make the robot more stable. The refinement needs to be done only for 8 servos, the remaining 4 will be attached directly to the body.

We attach the legs to the connecting element (curved part), and it, in turn, to the servo on the body.

Step 5: Making the Shield

Making the board is quite simple if you follow the photos presented in the step.

Step 6: Electronics

Fix the servo pins on the arduino board. The pins must be connected in the correct sequence, otherwise nothing will work!

Step 7: Programming

It's time to bring Frankenstein to life. First, load the legs_init program and make sure that the robot is in the position shown in the picture. Next, load quattro_test to see if the robot responds to basic movements such as forward, backward, left, and right.

IMPORTANT: You need to add an additional library to the arduino IDE. The link to the library is given below:

The robot must take 5 steps forward, 5 steps back, turn left 90 degrees, turn right 90 degrees. If Frankenstein is doing everything right, we are moving in the right direction.

P. S: install the robot on the cup as a stand, so that each time it does not set it to the original point. Once the tests have shown the normal operation of the robot, we can continue testing by placing it on the ground / floor.

Step 8: Inverse Kinematics

Inverse kinematics is what actually controls the robot (if you are not interested in the mathematical side of this project and you are in a hurry to finish the project, you can skip this step, but knowing what drives the robot will always be useful).

In simple words, inverse kinematics or IK for short is the "part" of the trigonometric equations that determine the position of the sharp end of the leg, the angle of each servo, etc., which ultimately determine a couple of preliminary settings. For example, the length of each step of the robot or the height at which the body will be located during movement / rest. Using these predefined parameters, the system will extract the amount by which each servo must be moved in order to control the robot with given commands.

What else to read