Hello! Programming this year has been going pretty well, but one problem is bugging us. We would like to use the gyro to return the angle of our (alleged) Frisbee launcher and can’t exactly figure out how get the absolute angle from the gyro. I read in the 2009 C++ Getting Started Guide that the gyro is good for getting the relative angle, but not the absolute angle, and the accelerometer is good for directional acceleration and absolute angle (but is “easily confused while moving”). Does anyone happen to know the best way? Thanks!
The rotation of a turret your shooter is mounted on?
We’ll be using it for the pitch. We’ll be aligning the entire robot for the yaw either manually or using the axis camera.
The yaw rate sensor “gyro” doesn’t give you absolute angle. An accelerometer can be used to measure the component of gravity pulling in a specific direction, and from that compute tilt angle.
I believe a better solution would be an absolute angular sensor that turns with your pitch angle. A potentiometer can work, or a US Digital MA3, or an Austria Micro noncontact magnetic angular sensor.
That looks a lot more reliable. Any idea how they are programmed?
Most absolute angle sensors produce an analog voltage. Read it using an analog input. Either use the voltage value directly, or scale it to something which represents a value that makes sense for your application.
Sold. Any programming suggestions while we’re waiting for shipping? (We chose the analog version). We’re intending to mount it in the pivot point on our launcher (we’ll lathe a hole in the rod to get an exact fit). Thanks, by the way!
You can use a PIDController class or a PIDSubsystem (for command-based programs). The input is the potentiometer and the output is the speed controller. You need to choose PID values that scale the inputs (0-5V) to match the required motor value outputs (-1 to 1).
You can see the pot values using the SmartDashboard in test mode to help you come up with the correct values. You can also put the PIDController to the SmartDashboard so that you can tune the PID loop from the computer.
http://wpilib.screenstepslive.com/s/3120/m/7932/l/81113-pid-tuning-with-smartdashboard
Brad
We’ve found that analog channels use averagevalue (0-1024), not averagevoltage (0-5V), in the PID loop. Your setpoints will need to be in the 0-1024 range.
Just a heads-up about the hardware: We’ve used a LOT of these over the years (probably 6 on this year’s bot) and have broken our share of shafts in the process. Be sure to protect them from side loads across the shaft. For our swerve modules, this meant using flexible mounts for the body, and coupling the shaft with flexible tubing
Good luck.