1) When using an encoder or potentiometer, is there a way in RobotC to have a motor spin and have the program display the encoders or potentiometers current input onto RobotC
2) If I wanted the speed of a motor to increase when the recorded input of an encoder is decreasing. How would I do that? Ex. The set motor speed of a flywheel is 100 and the RPM is 2000, I want the motor speed to increase above 100 if the RPM decreases below 2000. I keep getting stuck on having the motor speed increase. Is there something wrong with this program -
**if (sensorValue[flywheelEncoder] < 2000)
{
motor[flywheel] = > 100;
}
**
Can someone please help? Thank You!
-
In RobotC you should be able to print to the debug stream. You could also display these values on an LCD if you wanted to be able to see data without being connected to your computer. The RobotC help menu has information on all of these functions and it should be pretty easy to figure out from that.
-
An encoder does not measure velocity, it measures displacement. That code is going to address the motor once the sensor value is over 2000 ticks, which is about 5.5 rotations (Encoders measure around 360 ticks to a rotation).
If you want to be able to control flywheel speed, you need to turn that distance value into a velocity by sampling the change over time. Essentially, snapshot the encoder value, wait a small amount of time (maybe 50ms), and then check the encoder value again. You would find the difference in the two values and then divide by time. Then you would adjust that value to turn it from ticks per 50ms into rotations per minute or whatever dimension you want to work with. From there you can write code to control flywheel speed with motor power.