
19-05-2014, 12:56
|
 |
 |
 |
Registered User
 FRC #0330 (Beachbots)
Team Role: Engineer
|
|
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,587
|
|
|
Re: What's your favorite programming/control system magic this year?
Quote:
Originally Posted by ekapalka
Our autonomous and teleop aim-assist could be reduced down to just a few lines of code using the map() function we replicated from the Arduino language. For both the range was smoothed using a moving average to avoid jittering.
Code:
ForwardSpeed = map(rangefinder_distance - target_distance, 0, 200, 0, 1);
The map() function takes an input (in our case from a rangefinder), the minimum expected value of that input, the maximum expected value of that input, the minimum value to output, and the maximum value to output. The input/output ranged aren't exactly set in stone... if the input is greater than expected, the output will also be outside of the expected range (meaning that the above piece of code can be used when too close or too far away from the wall, even though the output should fall between 0 and 1. It just re-maps values from one range to another.
|
This is another way of doing proportional control, (ie the P in PID). It's a nice way to do a first pass to figure out the P constant.
|