Self ductio n 2 Backg ro und

Self Balancing Single-Axle Robot MEE 3 22 H onors P ro je ct Sprin g 2 018 04/2 7/2 018 Rafa l K rz y sia k Hnin L in Dev in M cC orm ic k Am ro S han sh al1 Table of Contents In tr o ductio n 2 Backg ro und R esearc h 2 Theo ry 3 Contr o lle r D esig n a n d S im ula tio n 5 Cart D esig n P ro ced ure 6 Robot C om ponen ts a n d P ro ced ure 7 Alg orit h m 9 Part L is t 11 Pro je ct T im elin e 12 E ? ectiv en ess, C halle n g es, a n d L im it a tio ns 13 1. D esig n 13 2. C ontr o l S yste m 13 Refe re n ces 14 Appen dic es 15 Ard uin o C ode 15 Solid w ork s D ra w in gs ( D im en sio ns in m m) 21 Ove ra ll a sse m bly 21 3D P rin te d B ase 21 Modif ie d S helf 22 Fin al D esig n 222 In tr o ductio n The task for this project is to develop a system to balance a single axle robot similar to balancing an inverted pendulum. This system will consist three main components: a tower, a computer, and a drive system. The tower, simply to make balancing more difficult, will have mounted sensors to monitor the acceleration. These sensors will output to the computer so that the computer can make adjustments and balance the robot.

The computer will be composed of an arduino board. It will receive input from the sensors and determine the required response. The arduino board will then output to DC motor (s) that will move the axle to balance the robot. Backg ro und R ese arc h There is an abundance of similar projects to reference that can help us in designing, building, and troubleshooting this project.

Sometimes it is hard to do all the work on your own
Let us help you get a good grade on your paper. Get expert help in mere 10 minutes with:
  • Thesis Statement
  • Structure and Outline
  • Voice and Grammar
  • Conclusion
Get essay help
No paying upfront

Each project is fundamentally the same but differs only in the components. Each project varies in size, computer components, and drive system. For our project we determined that it will be best to use an arduino board and to keep as much mass as possible near the axle to reduce the moment of inertia. The Arduino Uno was selected as the preferred microcontroller over the Arduino Nano because it has more processing power. Also with the inclusion of the sensors that will be aiding in the calculation of the tilt of the robot, the group decided that the best option would be getting an accelerometer/gyroscope sensor to provide more options to tackle whatever problem arises from required calculations in preventing the robot from overshooting the neutral position.3 Theory The robot system is consisted of a cart with the components sitting on it which all conclude to a total mass of the cart, along with a pendulum that is linked to the cart. Newton’s second law of motion were applied to analyze the system’s equation of motion.

The free body diagram (FBD) below shows the forces acting on the cart and the pendulum. Using the FBD, and by summing all the force of the cart along the horizontal direction, Equation 1 shows the equation of motion ends up being: Where is the mass of the cart, N is the horizontal force when the pendulum rod tilts creatingm an angle. The equation of N is result of the pendulum tilting is shown in Equation 2:4 Where is the mass of the pendulum, is the length, and is the angle along with angular m p l ? velocity and angular acceleration. Substitution N (Equation 2) into Equation 1 results in the first equation of motion as shown in Equation 3: The forces along the perpendicular direction of the pendulum can be summed up to result in the second equation of motion shown in Equation 4: Where P is the vertical force caused by the tilt of the pendulum.

The terms P and N can be simplified by taking the moments around the centroid of the pendulum and that is shown in Equation 5: The second equation of motion will be a result of combining Equations 4 and 5 which results in Equation 6:5 Contr o lle r D esig n a nd S im ula tio n The control used for the robot was proportional plus integral plus derivative (PID). The proportional control (P) makes the control signal related to the system error instantaneously. That analysis can be implemented with the proportional gain value where the error is multiplied by k p the gain which is responsible for the process stability. The integral control (I) minimizes the k p steady-state error and the steady-state output response to disturbances. The integral gain k Iinfluences the control signal by summing each instant of time of all the previous values of tracking error; therefore, resulting in a control criteria that is based on the history of the error in the system. The derivative control (D) which can also be called rate feedback. D control improves closed-loop system stability as well as reducing the system overshoot and speeding up the transient response of the controller.

The gain value associated with the D control is is k d responsible for the system response. The the rate of change of error is multiplied by . The k p main challenge in this robot design was to control the pendulum position. The force that is applied on the pendulum of the cart is considered as a disturbance. The block diagram below shows the closed loop control of the inverted pendulum robot:6 Cart D esig n P ro ce d ure After determining the parts necessary for the project, we were able to begin the design and coding work. A solidworks part was designed to include mounts for the motors, areas for circuit board placement, and a pole to mount the accelerometer on. The base was designed to be lightweight, have a low moment of inertia, and to have sufficient area for the components.

This part drawing is included in the appendix. The part was manufactured using SLS. After receiving the printed part the motors were superglued to the base and the circuit boards were laid out. At this point it became evident that we had not accounted for one of the circuit boards and had insufficient space. Another part was then designed to be 3D printed to allow for more space for components. Once again this drawing is included in the appendix. The second portion of the frame was then attached. Finally, the circuit boards and other components were mounted using screws.

The arduino was connected to the motor controller through the digitalwrite pins. The accelerometer is connected to the arduino through the analog and digital write pins. The data from the accelerometer is used by the arduino board to calculate the necessary power output to balance the robot which is then applied to the motor controller.7 Robot C om ponents a nd P ro ce dure89 Alg orit h m The pendulum is first positioned upright manually, which is in an unstable position relative to the equilibrium. In other words, it is given some initial displacement (position). The PID controller kicks in to balance the pendulum and maintain the balance with the external disturbance.

The code has 4 files: the main code, the motors, the PID controller, and the IMU sensor reading. The main code first initializes the entire variables: pins, sensors, and communications. Then it gets values from the gyroscope and the accelerometer.

The initialization process is important as the initial angle was set to zero, the sensor has an initial10 deviation, and this initial angle is used to subtract it from the posterior measurements of the sensors to obtain the real angle. The next part of code is the loop where we take the sensor values for every microseconds, and calculate the angle of the robot in x, y, and z directions from the gyroscope. Once the angles are obtained, they were combined to overcome the gyro drift and the accelerometer noise. This process is done by using the Complementary filter, which will trust the gyro for short periods of time and the accelerometer for longer periods of time as below. Current angle = 98% x (current angle + gyro rotation rate) + (2% * Accelerometer angle) Next, A PID control algorithm is used to balance the robot by driving the motors based on the tilt. The proportional control will try and correct the balance based on the current error from point zero.

The integral term is based on the current angle difference accumulated over time, and assists in balancing the robot while moving. The derivative term is based on the current rate of rotation. The addition of all the PID values will be used to drive the motors in the right direction and with the right power. Output = P-term + I-term + D-term11 Part L is t Ite m N um ber Seria l Num ber/I d en tif ic a tio n Desc rip tio n Dis tr ib ute r 1 L 298N Moto r D riv e C ontr o lle r Board M odule Quan qi 2 GY-5 21 M PU -6 050 3 A xis A cc ele ro m ete r Gyro sc o pe Gen eric 3 N/A 4 P cs A rd uin o P la stic Tir e W hee l w ith D C 3 V 5V 6 v G ear M oto r N/A 4 1/8 1 2×12 Acry lic P le x ig la ss Sheet Sourc e O ne 5 LJY -1 86 Wall A dap te r P ow er Supply (1 2V D C) NKC E le ctr o nic s 6 GY-2 9 M M A7455 Tria x ia l D ig ita l Acce le ro m ete r S en so r Module KNACRO 7 US-S A -A JD -0 0101 Gear M oto r Uxcell12 Pro je ct T im elin e For this project a timeline was made to help manage the different subtasks of the project. The gantt chart below lays out how long each task is expected to take and when each task is to be completed.13 E ? ectiv e ness, C hall e nge s, a n d L im it a tio ns 1. Desig n While designing the chassis of the self-balancing robot, the goal was to build a rigid frame that is inexpensive, relatively light, and adjustable to meet the needs throughout the project.

It was also designed to minimize the moment of inertia to allow for easier balancing. To meet these requirements, the frame was 3D printed at the MakerSpace. However, the initial design couldn’t provide the necessary space for all the components for the robot, and was not very stable to put the sensor, giving inaccurate reading. Therefore, a modified shelf with a flat surface, as shown in the Appendix, was added to the frame. Another challenge this project was selecting the motors. For the robot to properly balance, the motor must provide high torque and a sufficiently high RPM to connect the wheels directly to the motor shaft.

A high torque is necessary in order to avoid stalling, and a high enough RPM is required to prevent the motor speed from saturating during normal balancing behavior. 2. Contr o l S yste m After the experimentation, it was observed that a PID controller is very easy to implement as it only requires three parameters to be set in order to have a speed control system. Moreover, since the PID controller is linear, the logic is very simple and useful in many linear or fairly linear applications. However, during the project, there were a few limitations with respect to the control system.

Even though a PID controller is easy to implement, it is a major drawback14 of the system that tuning the value of constants for the K ?P ?, K ?I ?, K ?D values was based on the trial and error method, and thus it is not e ? cient. Moreover, the experimental results showed that for di ? erent values of the reference speed for the motor, the PID controller malfunctioned for the same values of the PID constants. For di ? erent speeds, the constants had to be selected di ? erently. Moreover, PID controller generally has to balance all three gains impact to the whole system and may compromise the transient response, such as settling time, overshoots, and oscillations. If the system parameters cannot be precisely estimated or achieved, the designed PID gains may not resist the uncertainties and disturbances, and thus present low robustness. During the experimentation, the speed of the motor was controlled using the PID Algorithm. However, the motor does not rotate smoothly under small voltage or PWM, and provides jerks that might cause some wrong values fed to the system. In addition, due to wobbling, the sensor sometimes misses some slits providing higher values.

Refe re nce s 1 ? ? ? 2 ? ? ? 3 ? ? ?https://smartech. 4 ? ? 5 ? 6 ?https://www. Appendic e s Solid w ork s D ra w in gs ( D im en sio n s in m m) Ove ra ll a sse m bly16 3D P rin te d B ase Modif ie d S helf17 Fin al D esig n Ard uin o C ode #in clu de " I2 C dev.h " #in clu de " M PU 6050.h " #if I2 C DEV_IM PLE M EN TA TIO N = = I 2 C DEV_A R D UIN O _W IR E # in clu de " W ir e .h " #endif // c re ate th e a cce le ro m ete r o bje ct MPU 6050 a cce lg yro ; // p in n um bers th at w ill g o in to th e m oto r c o ntr o lle r co nst in t E N A = 5 ; co nst in t E N B = 1 0; co nst in t IN 1 = 6 ; co nst in t IN 2 = 7 ; co nst in t IN 3 = 8 ; co nst in t IN 4 = 9 ;18 // c re ate tim es fo r th e I v a lu e o f t h e P ID unsig ned lo ng c u rre ntT im e; unsig ned lo ng tim eN ow ; unsig ned lo ng la stT im e; in t o utp ut; double e rrS um , la stE rr; flo at c ycle T im e = 0 .0 04;// in s e co nds // P ID v a lu es double k p = 0 .

0 ; double k i = 0 .0 ; double k d = 0 .0 ; // fo r c a lc u la tin g th e o utp ut e rro r double a cce lD ata ; double e rro r; double d E rr; double a cce lT ota l; double g yro D ata ; // v a ria ble s fo r th e a cce le ro m ete r in t1 6_t a x, a y, a z; in t1 6_t g x, g y, g z; in t s u m gx, s u m gy, s u m gz; in t s u m ax, s u m ay, s u m az; flo at d ela yT im eC orre ct; // in it ia liz in g v a ria ble s to 0 in it ia lly sta tic in t s e tp oin t = 0 ; sta tic in t in put = 0 ; sta tic in t la stIn put = 0 ; #defin e O UTP U T_R EAD ABLE _A C C ELG YR O vo id s e tu p() { # if I2 C DEV_IM PLE M EN TA TIO N = = I2 C DEV_A R D UIN O _W IR E W ir e .b egin (); # elif I2 C DEV_IM PLE M EN TA TIO N = = I 2 C DEV_B U IL T IN _F A STW IR E F astw ir e ::s e tu p(4 00, tr u e); # endif // in it ia liz e th e s e ria l19 S eria l. b egin (1 15200); // in it ia liz e th e a cce le ro m ete r a cce lg yro .in it ia liz e (); // g et th e x d ir e ctio n o f th e g yro sco pe fo r ( in t i = 1 ; i ; 3 3; i = i + 1 ) { a cce lg yro .g etR ota tio n(; gx, ; gy, ; gz); s u m gx = s u m gx + g x; } s u m gx = s u m gx / 3 2; // g et th e x d ir e ctio n o f th e a cce le ro m ete r fo r ( in t i = 1 ; i ; 3 3; i = i + 1 ) { a cce lg yro .

g etA cce le ra tio n(; ax, ; ay, ; az); s u m ax = s u m ax + a x; } s u m ax = s u m ax / 3 2; // e sta blis h w hat th e p in s w ill b e p in M ode(E N A, O UTP U T); p in M ode(E N B, O UTP U T); p in M ode(IN 1, O UTP U T); p in M ode(IN 2, O UTP U T); p in M ode(IN 3, O UTP U T); p in M ode(IN 4, O UTP U T); a nalo gW rit e (E N A, 0 ); a nalo gW rit e (E N B, 0 ); } vo id lo op() { c u rre ntT im e = m ic ro s(); a cce lg yro .g etM otio n6(; ax, ; ay, ; az, ; gx, ; gy, ; gz); a cce lD ata = ( a x-s u m ax); a cce lT ota l = a cce lD ata + s e tp oin t; g yro D ata = ( g x-s u m gx); // g et th e in put n um ber, f o cu s m ain ly o n th e g yro sco pic d ata in put = ( 0 .9 8*((la stIn put) + ((g yro D ata )* c ycle T im e)))+ (0 .

0 2*(a cce lT ota l) );20 c a lc O utp ut( ); M oto rL 298(); s e ria lI n put( ); s e ria lO utp ut( ); la stE rr = e rro r; la stIn put = in put; c o rre ctT im e(); } // fo r th e I v a lu e in th e P ID c o ntr o lle r vo id c o rre ctT im e() { tim eN ow = m ic ro s(); d ela yT im eC orre ct = 2 500-(tim eN ow – c u rre ntT im e); d ela yM ic ro se co nds(d ela yT im eC orr e ct) ; } // c a lc u la tin g th e o utp ut o f t h e s yste m u sin g th e P ID v a lu es vo id c a lc O utp ut( ) { e rro r = s e tp oin t – in put; e rro r = e rro r; e rrS um = e rrS um + ( e rr o r * c ycle T im e); //in te rg ra l p art s u m o f e rr o rs p ast d ouble d In put = in put – la stI n p ut; o utp ut = ( k p * e rro r) – ( k i * e rr S um ) + (k d * d In put) ; } // h ow th e m oto rs w ill b e c o ntr o lle d vo id M oto rL 298() { o utp ut = ( o utp ut / 2 ); if ( o utp ut 0 )21 { d ig it a lW rit e (IN 1, L O W ); d ig it a lW rit e (IN 2, H IG H); a nalo gW rit e (E N A, o utp u t) ; d ig it a lW rit e (IN 3, H IG H); d ig it a lW rit e (IN 4, L O W ); a nalo gW rit e (E N B, o utp u t) ; } e ls e { o utp ut = 0 ; d ig it a lW rit e (IN 1, L O W ); d ig it a lW rit e (IN 2, L O W ); a nalo gW rit e (E N A, o utp u t) ; d ig it a lW rit e (IN 3, L O W ); d ig it a lW rit e (IN 4, L O W ); a nalo gW rit e (E N B, o utp u t) ; } } // c h angin g th e P ID v a lu es in th e s e ria l vo id s e ria lI n put( ) { if ( S eria l. a va ila ble () ; 0 ) { c h ar c h = S eria l. r e ad(); if ( c h = = '4 ') { k p = k p + 0 .0 5; } e ls e if ( c h = = '1 ') { k p = k p – 0 .0 5; } e ls e if ( c h = = '5 ') { k i = k i + 0 .0 5; }22 e ls e if ( c h = = '2 ') { k i = k i – 0 .0 5; } e ls e if ( c h = = '6 ') { k d = k d + 0 .

0 5; } e ls e if ( c h = = '3 ') { k d = k d – 0 .0 5; } } } // p rin t o ut th e P ID v a lu es in th e S eria l to d ete rm in e w hat th ey a re vo id s e ria lO utp ut( ) { s ta tic in t k = 0 ; if ( k = = 0 ) { S eria l. p rin t( " P " ); S eria l. p rin t( k p ); } e ls e if ( k = = 1 ) { S eria l.

p rin t( " I " ); S eria l. p rin t( k i) ; } e ls e if ( k = = 2 ) { S eria l. p rin t( " D " ); S eria l.

p rin t( k d ); } k = k + 1 ; if ( k = = 3 )23 { k = 0 ; S eria l. p rin tln (); } }


I'm Gerard!

Would you like to get a custom essay? How about receiving a customized one?

Check it out