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.
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){
vex::task::sleep(20)
}
// 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){
vex::task::sleep(20)
}
//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.
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).
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.
@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.
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.