nxtway_wheeled_inverted_pendulum_with_gyro_sensor
Differences
This shows you the differences between two versions of the page.
Next revisionBoth sides next revision | |||
nxtway_wheeled_inverted_pendulum_with_gyro_sensor [2016/11/01 15:48] – created dwallace | nxtway_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> | ||
- | < | ||
- | <iframe width=" | ||
- | </ | ||
- | < | ||
- | <iframe width=" | ||
- | </ | ||
- | <br> | ||
- | '' | ||
- | 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.< | + | {{youtube>UnqKIOawlIk? |
- | The gyro seen in the video about is sold by HiTechnic: http:// | + | |
- | HiTechnic also provides an assembly manual for their " | + | |
- | [[File: | + | |
- | ''' | + | **Note:** If the videos do not load, just refresh |
- | http:// | + | |
- | [[File: | + | |
- | <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]]< | + | The gyro seen in the video about is sold by [[http://www.hitechnic.com/ |
+ | HiTechnic also provides an assembly manual for their " | ||
- | ===Building Instructions=== | + | {{dylanw: |
- | [[File: | + | |
- | These instructions are also available from HiTechnic' | + | **The goal of this project was to verify HiTechnic' |
- | http:// | + | |
- | <br> | + | {{dylanw: |
- | 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)=== | + | ===== Original HTWay ===== |
- | [[File: | + | |
- | This code is also available from HiTechnic' | + | {{dylanw: |
- | http:// | + | |
+ | ===== Building Instructions | ||
+ | |||
+ | {{dylanw: | ||
+ | These instructions are also available from [[http:// | ||
+ | |||
+ | 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: | ||
+ | This code is also available from [[http:// | ||
+ | |||
+ | ===== 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 | + | |
- | * 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.< | + | * 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: | + | Building instruction can be found on HiTechnics site or right here: |
+ | {{dylanw: | ||
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.< | 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.< | ||
- | 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.< | + | 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: | + | |
- | [[Image: | + | {{dylanw: |
+ | |||
+ | ===== 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: | ||
+ | |||
+ | ===== 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 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 |
- | Before you can run HiTechnics HTway code on your wheeled inverted pendulum, you must comment out the calls to the IR sensor.< | + | {{dylanw:nxtway_datalog.nxc.zip}} |
- | Comment out lines ''' | + | |
- | The commented code can be downloaded here: <br> | + | |
- | [[File:nxtway_HTgyro_noIR.nxc.zip]]< | + | |
- | ===IMU gyro and HT gyro data logging=== | + | The data obtained before filtering the IMU gyro data is found to look a lot like the HT gyro data but is offset |
- | 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 | + | |
- | [[File: | + | |
- | 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: |
- | [[Image: | + | ===== 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 | + | Offset |
+ | |||
+ | where i = 1..Number | ||
- | < | + | 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. |
- | 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.< | + | IMUgyro = -0.98*(IMUgyro_raw |
- | < | + | {{dylanw: |
- | [[Image: | + | ===== 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 '' |
- | 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 '' | + | |
- | 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