236 views

# Accelerometer/ Gyro Help

1. last week

### Seth

Dec 5 North Carolina 5139 A

Hey I'm am a little new to the sensor world that is vex programming and am having a hard time understanding how an Accelerometer or Gyro works. My team captain wants me to start programming an Accelerometer and I don't even know where to start for my code. I understand that it's a grid and we only require the X and Y Axes, but I don't understand how to wire it and get my code going and translated into something my whole team could understand. In VCS it shows as it only needing one wire port but it has multiple prongs on it for wires to connect to. If someone could help me understand how all of this works I would greatly appreciate it. Thank You.
- Dylan Jones - Programmer

2. ### Lukyan_1

Dec 5 Woodbridge, VA 4303A
Edited last week by Lukyan_1

I dont know about the accelerometer but the gyro,

Use ` Gyro.value(vex::analogUnits::range12bit)`

The reason for that could be found in this post

It returns the range12bit units which are basically the degree of the rotation X 10. if you turn 180 it will output 1800, so when you input the degrees you want to rotate, make sure you multiply it by 10. Also if you are using C++ Pro, don't forget to assign the port to the gyro.

For turns in autonomous, I just have

```if (target_deg > Gyro.value(vex::analogUnits::range12bit){   //turn right
start motors (make sure two of them are reversed if you are using 2 motors per side)
while (target_deg > Gyro.value(vex::analogUnits::range12bit){
}
// this just makes the motors go until its at the right degree

}

else if(target_deg > Gyro.value(vex::analogUnits::range12bit){  //turn left
start motors (make sure two of them are reversed if you are using 2 motors per side)
while (target_deg > Gyro.value(vex::analogUnits::range12bit){
}
//same here
}
//after its done, it exits the loop and stops the motors
motors.stop();```

(`target_deg` is degrees i want to turn * 10 + the current gyro value.

3. ### Seth

Dec 5 North Carolina 5139 A
Edited last week by Seth

@Lukyan_1 I dont know about the accelerometer but the gyro,

Use ` Gyro.value(vex::analogUnits::range12bit)`

It returns the range12bit units which are basically the degree of the rotation X 10. if you turn 180 it will output 1800, so when you input the degrees you want to rotate, make sure you multiply it by 10. Also if you are using C++ Pro, don't forget to assign the port to the gyro.

For turns in autonomous, I just have

```if (target_deg > Gyro.value(vex::analogUnits::range12bit){
turn right
}else if(target_deg > Gyro.value(vex::analogUnits::range12bit)[
turn left
}

motors.stop();```

(`target_deg` is degrees i want to turn * 10 + the current gyro value.

Thank you for that. Though I believe my captain wants me to focus on the Accelerometer because it helps navigation of the field via a grid and coordinates. And the reason I mentioned the gyro was because I would maybe try to use this for both sensors. I just thought about that after I titled the post. oops (Now it's changed. I find it easier to look for things in one spot instead of 10).
- Dylan Jones - Programmer

4. ### Lukyan_1

Dec 5 Woodbridge, VA 4303A

@Seth No problem

Btw if you are using V5, you don't need the accelerometer because the motor can tell you its velocity by itself.

5. ### Seth

Dec 5 North Carolina 5139 A

@Lukyan_1 We are using V5 but sometimes the wheels slip and we would like to be more accurate. It will help us navigate the field via coordinates.

6. ### Lukyan_1

Dec 5 Woodbridge, VA 4303A

@Seth I see

7. ### Seth

Dec 5 North Carolina 5139 A

@Lukyan_1 Sometimes they just slip when we drive cause of speed and how the field tiles are.

8. ### Lukyan_1

Dec 5 Woodbridge, VA 4303A

@Seth are you using 600 rpm?

9. ### Ashwin_D.

Dec 6 California 2496J

If you lack experience with acceloms. just don't use them. They provide very noisy data and in order to get velocity and or inertial frame of reference, you need to integrate the sensor. However, if you want position, you need to double integrate the sensor and use a filter. In addition, if you just double integrate it to get position, it would be like a scalar as you need to use some other sensor to be able to track the robot on a Cartesian plane.

In all honesty, almost nobody uses an accelom. because of the other better options there are (such as encoder tracking wheels which are significantly more reliable)

Gyros on the other hand are very very useful and could be used to detect orientation as it is a rotational sensor. You can use a gyro to straighten your robot, find your orientation without having to worry about wheel slips. Gyros also do not drift much in the autonomous period however for skills you might need a filter as well.

If you want to find code on how to use these in a programming context the VexForum has a lot of other threads such as: https://www.vexforum.com/index.php/32352-gyroscope-drive-straight/0, https://renegaderobotics.org/getting-started-with-the-vex-gyro-sensor/ , https://www.vexforum.com/index.php/6465-a-pid-controller-in-robotc/0

10. ### Kselva20

Dec 6 5249Z

@Seth With the accelerometer, you need to connect it to one of the three wire ports labeled as letters instead of numbers. From there, you can only receive analog values that will output numbers in the 2000s range. To get the value in Gs, it is fairly simple with 2 axes. Simply place the robot so that one of the axes is being brought down by the force of gravity, and note the accelerometer's value. Do this on the opposite side. These will be the accelerometer values at 1G and -1G (depending on which one is lower). 1G equals 9.8 m/s^2. After double integrating using the trapezoid rule, one can simply find position with the accelerometer. This sensor is very noisy and requires a lot of tuning and experimentation, so I recommend using 2 to 3 of these if you decide to use it. I hope this helped.

11. ### Kselva20

Dec 6 5249Z

Sorry, forgot to mention this: based on which axes you want, connect each axes to its own three wire port. There will be labels on the sensor showing which axis it belongs to. In the config file, declare each one as their own accelerometer . To make it easier, try naming each one AccelX and AccelY for your ease.

12. ### Seth

Dec 6 North Carolina 5139 A

@Lukyan_1 No just standard. The standard Green packages that come with V5. (200Rpm)

@Ashwin_D. It was just a thought because my captain thinks it will be useful for us to navigate the field during drivers and autonomous.

@Kselva20 Thank you very much. All though idk how much of that I understood lol. I apprieciate the help, from all of you.