User Tools

Site Tools


nxtway_wheeled_inverted_pendulum_with_gyro_sensor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revisionBoth sides next revision
nxtway_wheeled_inverted_pendulum_with_gyro_sensor [2016/11/01 15:48] – created dwallacenxtway_wheeled_inverted_pendulum_with_gyro_sensor [2016/11/09 13:54] dwallace
Line 1: Line 1:
 ====== NXTWay: Wheeled Inverted Pendulum with Gyro Sensor ====== ====== NXTWay: Wheeled Inverted Pendulum with Gyro Sensor ======
  
-==Motivation==+===== Motivation =====
 The LEGO Mindstorms NXT based Wheeled Inverted Pendulum has been proven to work using various types of sensors including stock light sensors and after market gyro sensors. The LEGO Mindstorms NXT based Wheeled Inverted Pendulum has been proven to work using various types of sensors including stock light sensors and after market gyro sensors.
-<br> 
-<html> 
-<iframe width="420" height="315" src="http://www.youtube.com/embed/UnqKIOawlIk" frameborder="0" allowfullscreen></iframe> 
-</html> 
-<html> 
-<iframe width="420" height="315" src="http://www.youtube.com/embed/7OfJwG0EhBU" frameborder="0" allowfullscreen></iframe> 
-</html> 
-<br> 
-''Note:'' If the videos do not load, just refresh the page. 
  
-The light sensor control sceme relies on a relatively solid colored texture free surface to perform well. Changes in light intensity at the sensor cause the robot to move forward or backward in response the sensed tilt. The gyro based model is more robust as it senses angular velocity of the robot directly. Being Gyro controlled, this robot can handle any colored surface, including ramps and small bumps.<br><br> +{{youtube>UnqKIOawlIk?medium}}{{youtube>7OfJwG0EhBU?medium}}\\ 
-The gyro seen in the video about is sold by HiTechnic: http://www.hitechnic.com/<br><br> +
-HiTechnic also provides an assembly manual for their "HiTechnic HTWay" and sample code that allows it to balance and be controlled by and infrared transmitting controller.<br> +
-[[File:HiTechnicHTWayAssembly.pdf]], [[File:HiTechnicHTWayNXCcode.nxc.zip]]<br><br>+
  
-'''The goal of this project was to verify HiTechnic's controller using their gyrothen modify the controller to work with an analog Sparkfun 6-axis IMU (sku: SEN-09431, Retired): +**Note:** If the videos do not loadjust refresh the page.
-http://www.sparkfun.com/products/9431<br><br> +
-[[File:razorIMU.jpeg|200px|6DOF Razor IMU]] +
-<br>+
  
-==Original HTWay== +The light sensor control sceme relies on a relatively solid colored texture free surface to perform well. Changes in light intensity at the sensor cause the robot to move forward or backward in response the sensed tilt. The gyro based model is more robust as it senses angular velocity of the robot directly. Being Gyro controlled, this robot can handle any colored surface, including ramps and small bumps. 
-[[File:HTway.jpg|300px|HTway]]<br><br>+The gyro seen in the video about is sold by [[http://www.hitechnic.com/|HiTechnic]] 
 +HiTechnic also provides an assembly manual for their "HiTechnic HTWay" and sample code that allows it to balance and be controlled by and infrared transmitting controller.
  
-===Building Instructions=== +{{dylanw:HiTechnicHTWayAssembly.pdf}}, {{:HiTechnicHTWayNXCcode.nxc.zip}} 
-[[File:HiTechnicHTWayAssembly.pdf]]<br> + 
-These instructions are also available from HiTechnic's Models page:<br> +**The goal of this project was to verify HiTechnic's controller using their gyro, then modify the controller to work with an analog [[http://www.sparkfun.com/products/9431|Sparkfun 6-axis IMU]] (sku: SEN-09431, Retired): 
-http://www.hitechnic.com/models<br> + 
-<br> +{{dylanw:razorIMU.jpeg}}\\  
-In DASL, we have only the HiTechnic Gyro. If you omit the IR receiver, you will have to comment out the corresponding sensor calls in the original code. The edited code in the following section will account for this omission.<br><br> + 
-===Code (NXC)=== +===== Original HTWay ===== 
-[[File:HiTechnicHTWayNXCcode.nxc.zip]]<br> + 
-This code is also available from HiTechnic's Models page:<br> +{{dylanw:HTway.jpg}}\\  
-http://www.hitechnic.com/models<br><br>+ 
 +===== Building Instructions ===== 
 + 
 +{{dylanw:HiTechnicHTWayAssembly.pdf}} 
 +These instructions are also available from [[http://www.hitechnic.com/models|HiTechnic's Models page]] 
 + 
 +In DASL, we have only the HiTechnic Gyro. If you omit the IR receiver, you will have to comment out the corresponding sensor calls in the original code. The edited code in the following section will account for this omission. 
 + 
 +===== Code (NXC) ===== 
 + 
 +{{dylanw:HiTechnicHTWayNXCcode.nxc.zip}} 
 +This code is also available from [[http://www.hitechnic.com/models|HiTechnic's Models page]] 
 + 
 +===== NXTway using Sparkfun IMU =====
  
-==NXTway using Sparkfun IMU== 
 My method of retrofitting the Sparkfun IMU using the HiTechnic HTway design and NXC code: My method of retrofitting the Sparkfun IMU using the HiTechnic HTway design and NXC code:
-* Build HiTechnic design HTway +  * Build HiTechnic design HTway 
-* Test HiTechnic code with HiTechnic gyro (IR control omitted) +  * Test HiTechnic code with HiTechnic gyro (IR control omitted) 
-* Connect IMU and log data from both the HiTechnic and Sparkfun gyros for comparison +  * Connect IMU and log data from both the HiTechnic and Sparkfun gyros for comparison 
-* Using both sets of data, find the equation relating IMU data to HiTechnic Gyro data so that the gyro input to the controller effectively looks the same. +  * Using both sets of data, find the equation relating IMU data to HiTechnic Gyro data so that the gyro input to the controller effectively looks the same. 
-* Alter code to read only IMU gyro data and remove the HiTechnic gyro +  * Alter code to read only IMU gyro data and remove the HiTechnic gyro 
-* Edit PID gains to account for slower update frequency.<br><br>+  * Edit PID gains to account for slower update frequency.
  
-===Build HTway=== +===== Build HTway ===== 
-Building instruction can be found on HiTechnics site or right here:<br> + 
-[[File:HiTechnicHTWayAssembly.pdf]]<br><br>+Building instruction can be found on HiTechnics site or right here: 
 +{{dylanw:HiTechnicHTWayAssembly.pdf}}
 When building this model, you can omit the IR sensor and rubber bumpers. The IR sensor use will be omitted from the code and the rubber bumpers are unavailable in the DASL Mindstorms kits.<br><br> When building this model, you can omit the IR sensor and rubber bumpers. The IR sensor use will be omitted from the code and the rubber bumpers are unavailable in the DASL Mindstorms kits.<br><br>
-When adding the Sparkfun IMU into the mix, you should match the position, orientation and wiring seen in the following pictures. This way, all the code will work. You can change things up later. As seen on the underside of the IMU, the 3V in can be wired to the 3.3V output on the HT proto-board and the ground should be wired to ground. The 4x-amplified X-axis gyro output should be wired to the first analog input, A0.<br><br> +When adding the Sparkfun IMU into the mix, you should match the position, orientation and wiring seen in the following pictures. This way, all the code will work. You can change things up later. As seen on the underside of the IMU, the 3V in can be wired to the 3.3V output on the HT proto-board and the ground should be wired to ground. The 4x-amplified X-axis gyro output should be wired to the first analog input, A0. 
-[[Image:NXTway_front.jpg|300px]] + 
-[[Image:nxtway_back.jpg|530px]]<br><br>+{{dylanw:NXTway_front.jpg}}{{dylanw:nxtway_back.jpg}}\\  
 + 
 +===== Test HiTechnic Code w/o IR ===== 
 + 
 +Before you can run HiTechnics HTway code on your wheeled inverted pendulum, you must comment out the calls to the IR sensor. 
 +Comment out lines **273** and **511** 
 +{{dylanw:nxtway_HTgyro_noIR.nxc.zip}} 
 + 
 +===== IMU gyro and HT gyro data logging =====
  
-===Test HiTechnic Code w/o IR=== +The functions for writing data to a file can be found in the code provided below. The functions initialize a fileprevent overwriting of previously saves files, and create a comma separated CSV file usable by MS Excel or another spreadsheet programThe provided reads each gyro every iteration and stores the raw data read from each
-Before you can run HiTechnics HTway code on your wheeled inverted pendulumyou must comment out the calls to the IR sensor.<br> +{{dylanw:nxtway_datalog.nxc.zip}}
-Comment out lines '''273''' and '''511'''.<br><br> +
-The commented code can be downloaded here: <br> +
-[[File:nxtway_HTgyro_noIR.nxc.zip]]<br><br>+
  
-===IMU gyro and HT gyro data logging=== +The data obtained before filtering the IMU gyro data is found to look lot like the HT gyro data but is offset by almost 400 units and flipped about the x-axis (depending on gyro orientation).
-The functions for writing data to a file can be found in the code provided below. The functions initialize a file, prevent overwriting of previously saves files, and create a comma separated CSV file usable by MS Excel or another spreadsheet program. The provided reads each gyro every iteration and stores the raw data read from each.<br> +
-[[File:nxtway_datalog.nxc.zip]]<br><br>+
  
-The data obtained before filtering the IMU gyro data is found to look a lot like the HT gyro data but is offset by almost 400 units and flipped about the x-axis (depending on gyro orientation).<br>+{{dylanw:GyroDataRaw.jpg}}\\ 
  
-[[Image:GyroDataRaw.jpg|1000px|Raw gyro data from both sensors]]<br><br>+===== IMU Data Massaging =====
  
-===IMU Data Massaging===+To find the offset necessary to center the IMU gyro data about the y=0 axis (the same center as the HT gyro data), the average of the differences between the two data sets at each point was found (-384.525).
  
-To find the offset necessary to center the IMU gyro data about the y=0 axis (the same center as the HT gyro data), the average of the differences between the two data sets at each point was found (-384.525)<br><br>+  Offset MeanIMUgyro_i - HTgyro_i )
 +   
 +where i = 1..Number of data points.
  
-<pre>Offset = Mean( IMUgyro_i - HTgyro_i )where i = 1..Number of data points.</pre><br>+Adding this value to the raw IMU gyro data at every point pulls the data down and centers it about the same central axis as the HT gyro data. After thatit can be seen that the IMU gyro data must be scaled slightly so that the local data minimums and maximums correspond in amplitudeThis scaling factor can be found by examining corresponding peaks in HT gyro data and IMU gyro dataThis scaling factor is found to be -0.98. This scalar to be multiplied by the offset IMU gyro data both decreases the amplitude slightly and flips the data over the x-axis. The data from both sensors now lines up and can be verified by applying filtering when the data is read in the code.
  
-Adding this value to the raw IMU gyro data at every point pulls the data down and centers it about the same central axis as the HT gyro data. After that, it can be seen that the IMU gyro data must be scaled slightly so that the local data minimums and maximums correspond in amplitude. This scaling factor can be found by examining corresponding peaks in HT gyro data and IMU gyro data. This scaling factor is found to be -0.98. This scalar to be multiplied by the offset IMU gyro data both decreases the amplitude slightly and flips the data over the x-axis. The data from both sensors now lines up and can be verified by applying filtering when the data is read in the code.<br><br>+  IMUgyro = -0.98*(IMUgyro_raw 384.525)
  
-<pre>IMUgyro = -0.98*(IMUgyro_raw - 384.525)</pre><br>+{{dylanw:GyroDataFiltered.jpg}}\\ 
  
-[[Image:GyroDataFiltered.jpg|1000px|Raw gyro data from both sensors]]<br><br>+===== Wheeled Inverted Pendulum with IMU gyro =====
  
-===Wheeled Inverted Pendulum with IMU gyro=== +At this point, the gyros can effectively be swapped. This means that the HT gyro can be omitted from the control loop and removed from the robot. If you replace every part of the code where the controller calls data from the HT gyro with a read of the analog port connected to the IMU gyro, you will find that the robot ''almost'' works but is extremely unstable.
-At this point, the gyros can effectively be swapped. This means that the HT gyro can be omitted from the control loop and removed from the robot. If you replace every part of the code where the controller calls data from the HT gyro with a read of the analog port connected to the IMU gyro, you will find that the robot ''almost'' works but is extremely unstable.<br>+
  
-This instability is due to a much slower control loop and therefore a need for a more extreme reaction. The robot will fall further before the wheels are given a command to react. While the HT gyro can be read at up to 300Hz, the low speed proto-board board connected to the IMU can only be read at about 20Hz max.<br>+This instability is due to a much slower control loop and therefore a need for a more extreme reaction. The robot will fall further before the wheels are given a command to react. While the HT gyro can be read at up to 300Hz, the low speed proto-board board connected to the IMU can only be read at about 20Hz max.
  
-Luckily, it is easy to compensate for this newly introduced lag in the controller. This compensation comes in the form of cranking up a gain on the effect of sensed angle (integrated angular velocity from gyro) on the reactionary motor speed. This increases causes smaller tilt angles to cause greater motor speeds than the original gain. With a slower reaction time, a reaction of greater magnitude is necessary to account for lost time!<br>+Luckily, it is easy to compensate for this newly introduced lag in the controller. This compensation comes in the form of cranking up a gain on the effect of sensed angle (integrated angular velocity from gyro) on the reactionary motor speed. This increases causes smaller tilt angles to cause greater motor speeds than the original gain. With a slower reaction time, a reaction of greater magnitude is necessary to account for lost time!
  
 <pre> <pre>
nxtway_wheeled_inverted_pendulum_with_gyro_sensor.txt · Last modified: 2016/11/09 14:08 by dwallace