Mixer      06/15/2019

Segway with your own hands. Do-it-yourself Segway Electronic filling of the Segway

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:

Gear Motor direct current 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 DMP 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.

hoverboard inside

Main details

What is a gyroscope made of? If you look from the side, the gyro scooter is an interesting device. The first is a work platform or board. It is on it that a person gets up and, trying to keep balance, drives, rides or falls. On the sides of the platform there are two wheels, it is they that give us the opportunity to ride and move forward or backward.

First, let's deal with the platform. The working platform is divided into two parts, right and left. Just right and left foot. This was done in order to be able to turn right or left, just by pressing the toe on these platforms.

How is a gyro scooter?

mini segway device

wheels

There are two wheels on the sides. Usually hoverboards come in 4 types, and they differ in the class and size of the wheels. The first class of hoverboards is a children's hoverboard with 4.5 inch wheels. The small size of the wheels makes the scooter very uncomfortable and not passable in some sections of the road.

The next class is the 6.5 inch hoverboard. He already has larger diameter wheels, but everything is also designed only for driving on flat surfaces. The 8 inch gyroscooter is the golden mean among all gyroboards. He has optimal size wheels that can drive on almost any road.

And the biggest is the SUV of all mini-segways - a 10-inch hoverboard. This is a model that has interesting feature, in addition to large wheels, these wheels have a chamber system. That is, the wheels are inflatable, they have a smoother ride, and such hoverboards are more wear-resistant than smaller prototypes.

Frame

The body of all hoverboards is made of different materials, but with the same feature. Everywhere the case covers the wheels, protecting from splashes, dirt, water, snow and dust. Gyroscooters with small wheels 4.5 and 6 are usually made of ordinary plastic. Since these models are designed to drive on a flat road, and do not develop such a high speed, the engineers decided not to install expensive plastic and thereby increase the price of a hoverboard.

For a hoverboard with 8 inch wheels, the bodies are made of various materials, both from simple plastic, and from carbon, high-impact magnesium plastic. Such plastic is able to withstand almost any physical impact and shock. Carbon, for example, is also a lightweight material, thereby reducing the load on electric motors and reducing the rate of battery discharge.

Engines

After you remove the cover, on the sides closer to the wheel you should see the electric motor. Electric motors are different power. The average value among all mini-segways is 700 watts on both wheels. Or 350 watts per wheel. The fact is that the electric motors of the gyroscooters work independently of each other. One wheel can go at one speed and the other at another, or they can move in different directions, one backward, the other forward. Thus, this system gives the gyroscooter controllability.

It becomes more sensitive to turns at high speed. You can also turn around 360 degrees. The higher the power of the engine, the higher the load carried and the higher the speed, but not always. It must be understood that the higher the mass of the load on the platform, the lower the speed and the faster the battery is discharged. Therefore, gyroscooters with powerful engines are more expensive.

Balancing system

The balancing system consists and includes quite a few components. First of all, these are two gyroscopic sensors, which are located on the right and left sides of the platform. If you remove the case cover, you can see two auxiliary boards, it is to them that the gyroscopic sensors are connected. Auxiliary boards help process information and send it to the processor.

Further on the right side you can see the main board, it is there that the 32-bit processor is located and all control and calculation is carried out. There is also a program that reacts to any change in the platform on the right or left.

If the platform leans forward, then the processor, having processed the information, sends a signal to the electric motors that physically hold the board in a level position. But if the platform tilts more with a certain pressure, the wheel immediately starts moving forward or backward.

It must be remembered that in all current hoverboards there must be two auxiliary boards for gyroscopic sensors and one main board, where the processor is located. In older models, there may also be a two-board system, but since the fall of 2015, a change has been made to the standard and now all hoverboards, mini-segways are made with 3 boards.

In Chinese fakes or low-quality hoverboards, there may be one board, the main one. Unfortunately, such a mini-segway has poor handling characteristics. May vibrate or overturn the driver. And then the whole system can fail altogether.

Scheme internal device Controlling a scooter is not as difficult as it seems. The whole system is designed to respond as quickly as possible to any behavior of the platform. The calculation is done in a fraction of a second and with amazing accuracy.

Battery

The power supply system of the hoverboard is powered by two or more batteries. In standard inexpensive models, a battery with a capacity of 4400 mAh is usually installed. The battery is responsible for the operation of the entire system as a whole and providing it with electricity, so the battery must be of high quality and branded. Typically, two brands of batteries are used - these are Samsung and LG.

Batteries also differ in class. There are low-level batteries of classes 1C, 2C. Such batteries are usually put on hoverboards with 4.5 and 6.5 inch wheels. All for the same reason, because these hoverboards are designed for flat roads, flat asphalt, marble or floors.

Gyroscooters with 8-inch wheels, usually put batteries of the middle class type 3C, this is already more reliable model batteries. It will not turn off during a sudden stop or when hitting a curb or a hole.

Large-wheeled 10-inch models usually have class 5C batteries. This hoverboard is able to ride on almost any road, land, puddles, pits. Therefore, the battery needs to be more reliable.

The basic principle of the hoverboard device is due to balance. With a large weight of the driver, the gyro scooter needs more electricity to carry out maneuvers and movement.

Other

Many hoverboards also have a Bluetooth system and speakers. With it, you can listen to your favorite music and ride with friends. But this system still makes it possible to connect your smartphone to the hoverboard and monitor the state of your vehicle. Can be followed average speed, see how far you have covered. Set the maximum allowed speed and much more.

Many models also have a backlight, it illuminates your path in the dark, and can also flash brightly to the beat of the music. But you need to remember that music and lighting greatly drain the battery. Many generally turn off the backlight to increase the power reserve.

Conclusion

The scooter is designed to be compact and lightweight, yet fast, powerful and durable. The main thing is to buy a hoverboard from trusted suppliers who have all the necessary documentation so that you do not have to disassemble it after an unsuccessful ride.


This article will consider the creation of a self-balancing vehicle, or simply a Segway. Almost all materials for creating this device easy to get.

The device itself is a platform on which the driver stands. By tilting the torso, two electric motors through a chain of circuits and microcontrollers responsible for balancing.

Materials:


-XBee wireless control module.
- Arduino microcontroller
-batteries
- InvenSense MPU-6050 sensor on the “GY-521” module,
- wooden blocks
-button
-two wheels
and other things indicated in the article and in the photographs.

Step one: Determine the required characteristics and design the system.

When creating this device, the author tried to make it fit into such parameters as:
- flotation and power needed to move freely even on gravel
-batteries of sufficient capacity to provide at least one hour of continuous operation of the device
- provide the possibility of wireless control, as well as fixing data on the operation of the device on an SD card for troubleshooting and troubleshooting.

In addition, it is desirable that the costs of creating similar device were less than the order of the original off-road hoverboard.

According to the diagram below, you can see the circuit electrical circuit self-balancing vehicle.


The following image shows the drive system of the scooter.


The choice of a microcontroller to control Segway systems is diverse, the author Arduino system most preferred because of its price ranges. Suitable controllers such as Arduino Uno, Arduino Nano, or you can take the ATmega 328 to use as a separate chip.

To power a dual bridge motor control circuit, a supply voltage of 24 V is required, this voltage is easily achieved by connecting 12 V car batteries in series.

The system is designed so that power is supplied to the motors only while the start button is pressed, so for a quick stop, just release it. In this case, the Arduino platform must maintain serial communication with both the bridge control circuit of the motors and with the wireless control module.

Tilt parameters are measured using the InvenSense MPU-6050 sensor on the “GY-521” module, which processes acceleration and carries the functions of a gyroscope. The sensor was located on two separate expansion boards. The l2c bus communicates with the Arduino microcontroller. Moreover, the tilt sensor with address 0x68 was programmed in such a way as to poll every 20 ms and provide an interrupt to the Arduino microcontroller. The other sensor has address 0x69 and is pulled directly to the Arduino.

When the user stands on the platform of the scooter, the load limit switch is activated, which activates the algorithm mode for balancing the Segway.

Step two: Creating the body of the hoverboard and installing the main elements.


After determining the basic concept of the gyro scooter operation scheme, the author proceeded to the direct assembly of its body and the installation of the main parts. The main material was wooden planks and bars. The tree weighs little, which will positively affect the duration of the battery charge, in addition, wood is easily processed and is an insulator. A box was made from these boards, in which batteries, motors and microcircuits will be installed. Thus, a U-shaped wood detail, on which wheels and engines are attached by means of bolts.

The transmission of engine power to the wheels will be due to gearing. When laying the main components in the body of the Segway, it is very important to ensure that the weight is distributed evenly when bringing the Segway to a working upright position. Therefore, if you do not take into account the distribution of weight from heavy batteries, then the work of balancing the device will be difficult.

In this case, the author placed the batteries at the back, so as to compensate for the weight of the engine, which is located in the center of the device. The electronic components of the device were stowed in place between the engine and the batteries. For later testing, a temporary start button was also attached to the handle of the Segway.

Step Three: Wiring Diagram.



According to the above diagram, all the wires in the Segway case were carried out. Also, in accordance with the table below, all the outputs of the Arduino microcontroller were connected to the bridge motor control circuit, as well as to the balancing sensors.


The following diagram shows the tilt sensor installed horizontally, while the control sensor was installed vertically along the Y-axis.



Step four: Testing and configuring the device.


After carrying out the previous stages, the author received a Segway model for testing.

When conducting testing, it is important to take into account such factors as the safety of the testing area, as well as protective equipment in the form of protective shields and a helmet for the driver.

Is it possible to make a segway with your own hands? How difficult is it, and what details will be required for this? Will it homemade apparatus perform all the same functions as factory-made? A bunch of similar questions arise in the head of a person who decides to build with his own hands. The answer to the first question will be simple and clear: to make an “electric scooter” by yourself is within the power of any person who is at least a little versed in electronics, physics and mechanics. Moreover, the device will work no worse than that produced on a factory machine.

How to make a segway with your own hands?

If you look closely at the hoverboard, you can see a fairly simple structure in it: it's just a scooter equipped with an automatic balancing system. There are 2 wheels on both sides of the platform. To carry out effective balancing, the Segway designs are equipped with an indicator stabilization system. The impulses coming from the tilt sensors are transported to the microprocessors, which, in turn, produce electrical signals. As a result, the gyro scooter moves in a given direction.

In order to make a Segway with your own hands, you will need the following items:

  • 2 wheels;
  • 2 motors;
  • steering wheel;
  • aluminum blocks;
  • supporting steel or aluminum pipe;
  • 2 lead-acid batteries;
  • aluminum plate;
  • resistors;
  • emergency brake;
  • steel axle 1.2 cm;
  • printed circuit board;
  • capacitors;
  • Lipo battery;
  • gate drivers;
  • led indicators;
  • 3 x ATmtga168;
  • voltage regulator;
  • ADXRS614;
  • 8 Mosfets;
  • two springs;
  • and ADXL203.

Among the listed items there are both mechanical parts and electronic components, and other equipment.

Segway assembly order

Assembling a Segway with your own hands is not as difficult as it seems at first glance. With all the necessary components, the process takes very little time.

Collection of mechanical parts

  1. Motors, wheels, gears and batteries can be borrowed from Chinese scooters, and finding an engine is no problem at all.
  2. The large gear located on the steering wheel is transmitted from the small gear on the engine.
  3. The gear on the wheel (12") has a free play - this requires some changes to be made to work the rotating elements in both directions.
  4. A fixed axle attached with three aluminum blocks (they can be fixed with 5mm set screws) forms the basis of the platform.
  5. Using the SolidWorks program, you need to make a drawing of a part that will allow the hoverboard to turn to the sides while tilting the torso. After that, the part must be machined on a CNC machine. The machine used the CAMBAM program, which was also used in the manufacture of the box for the emergency brake unit.
  6. The handlebar is attached to a 2.5 cm empty steel pipe.
  7. To ensure that the steering column is always located in the center, as well as the reverse thrust is more intense, you can use a pair of steel springs.
  8. The steering wheel is equipped with a special emergency button connected to the relay - this allows you to reduce engine power.
  9. Motor power supplies - rechargeable batteries for 24 V.

Collection of electronic parts

In order to assemble a Segway with your own hands, it is not enough just to fasten the mechanical parts. Electronic control no less important in a hoverboard, because it is quite an important component of the unit.

  1. The printed circuit board, which has a computing function, collects information from sensors - a gyroscope, an accelerometer, a potentiometer, and then sets the direction of rotation.
  2. Without the ATmtga168 processor, the scooter will not be able to work normally. The connection to the computer is made via Bluetooth and RN-41.
  3. With the help of two H-bridges, the control impulses from the base board are converted into the force of the motors. Each bridge is equipped with ATmtga168, the boards communicate with each other via UART.
  4. All electronics are powered by a separate battery.
  5. In order to quickly get to the batteries, as well as program the base board and change the parameters of the control loops, you need to make a small box with connectors, equip its case with a trimmer potentiometer on top, and also provide an electronics power switch.

Segway software

How to make a segway with your own hands so that it will surely work? Right - install the software (or software). Here are the required steps to complete this task:

  1. The microcontroller software includes a filter for the accelerometer and gyroscope and a PD control loop.
  2. Kalman and Complemenatry filters will do the job just fine.
  3. Write applications using the Java programming language - this will allow you to see the degree of battery charge, all sensor readings and control parameters.

That, perhaps, is all that is required from a person who decides to make a Segway on his own. Understanding the subject and process, as well as the necessary components, will allow you to build an excellent hoverboard at home.

Is it really possible to make such a complex device as a Segway yourself? It turns out you can. If you apply enough diligence and use special knowledge. What did a young engineer named Petter Forsberg, who graduated Swedish Chalmers University of Technology with a degree in Automation and Mechatronics.

In addition to knowledge and skills, he still had to need a lot of money, you say. Yes, money was needed, but not much, about 300 euros, to purchase a certain set of parts and equipment. The result of his efforts is in this video:

Mechanics

Motors, wheels, chains, gears and batteries were taken from two inexpensive Chinese electric scooters. Engines allow you to provide 24V, 300W, 2750 rpm.

The transmission is carried out from the small gear on the motor to the large gear on the steering wheel. The ratio is about 6:1, a high ratio is preferable to get better torque and lower top speed. The transmission on the 12" wheel was based on a freewheel mechanism, so the necessary modifications had to be made to allow the wheel to be driven in both directions.

The basis of the platform is a fixed axle on which both wheels must rotate. The axle is mounted with three aluminum blocks, which are fixed with 5mm set screws.

In order to be able to turn when driving a segway by tilting the steering column to the left and right, a drawing of the necessary part was made in the SolidWorks program, after which it was made on a CNC machine. The machine program was written using CAMBAM. The same method was used to produce the electronics box and assemble the emergency brake unit.

The steering wheel of the future Segway is a conventional bicycle handlebar, the tube of which is attached to a 25 mm steel hollow pipe. To keep the steering column centered and create some feedback force, two steel springs were used. The steering wheel also has an emergency button, which is connected to a standard relay from the car and can reduce engine power.

For power supply, two 12V 12Ah lead batteries are used, which are used for 24V motors.

Electronics

All printed circuit boards were made specifically for this development. The main board takes care of the calculations, collects data from sensors such as a gyroscope (ADXRS614), an accelerometer (ADXL203) and a trim pot, based on which it is able to determine which direction you want to turn.

Main processor AVR ATmega168. Connection with a laptop is made via Bluetooth using the RN-41. Two H-bridges convert the control signals from the main board into force for the motors. Each H-bridge has an ATmega168, communication between the boards is via UART. All electronics run on a separate battery (LiPo 7.4V 900mAh).

In order to have easy access to charging the batteries, for programming the main board, changing the parameters of the control loop, a small box was made with the necessary connectors, an electronics power switch and a trimmer potentiometer on the top side.

Software

The microcontroller software mainly consists of a filter for the gyroscope and accelerometer and a PD control loop. Two filters were taken for the test: Kalman and Complemenatry. It turned out that their performance was very similar, but the Complemenatry filter requires less computation, so it was chosen to be used. Java applications have also been written so that you can see all the values ​​​​of sensors and control signals, battery status, etc.

The technical side of creating a Segway with your own hands in this video: