Quote:
|
Originally Posted by Matthew_H
Where in the default code do we slow the full speed of the robot. I know this is simple but I just can not seem to find it. Thanks
|
I'm not exactly sure what you mean by 'slow down' but I'll take a stab.
For as far as I know our team has been scaling back the speed of the robot by 50% unless the 'turbo' button is pressed on the drive stick. This makes the robot more controlable, but still allows the driver to go full speed.
So here's how we do it, and generally how you'd scale any motor down:
<beginner mistake>
If I want to scale the motor speed down by 50% all I have to do is divide the speed by 2
</beginner mistake>
This won't work because the 'zero' point where the motor doesn't move is 127, not 0. So if you divide 127 (motor not moving) by 2 you get 63 which means your motor is moving half speed backwards. In order for your motor to stop running you must add back 64.
Now my equation is motor_speed / 2 + 64. Seems to work fine.
If you want to scale by 1/3 you divide your motor speed by 3 and add 85.
The general formula is:
(motor_speed * (1 / scaling_factor)) + (127 * (1 - (1 / scaling factor)))
Or you could approach it another way. Instead of fooling around with adding the (1 - 1/scaling) factor, you can re-center your math around 0:
First thing you do is subtract 127 from your motor speed, then divide by your scaling factor, then add 127 again to get back to pwm values. Quite simple, but remember to cast the calculation to an integer because an unsigned char can't handle negative numbers.
((motor_speed - 127) / scaling_factor) + 127
Both work. One is probably more efficient than the other. It's a matter of personal preference. I hope this helps.
Someone please check what I wrote for typos, I've been known to make them.