Commit | Line | Data |
---|---|---|
9a978a60 D |
1 | package org.usfirst.frc3501.RiceCatRobot;\r |
2 | \r | |
3 | public class MathLib {\r | |
4 | \r | |
5 | /***\r | |
6 | * This method gives speed as a function of % distance covered so the speed\r | |
7 | * forms a parabola starting and ending at minSpeed when you start and end and\r | |
8 | * achieving maxSpeed exactly halfway.\r | |
9 | *\r | |
10 | * @param minSpeed\r | |
11 | * the starting and ending speed, in range [0, 1]\r | |
12 | * @param maxSpeed\r | |
13 | * the max speed, achieved at percentComplete = 1/2.\r | |
14 | * @param percentComplete\r | |
15 | * should be currentDistance / targetDistance\r | |
16 | * @return the speed (motor value) to set motors to for smooth acceleration.\r | |
17 | * Note that since velocity is a parabola, acceleration is linear. It\r | |
18 | * may exceed the maximum value robot can accelerate without wheel\r | |
19 | * slipping.\r | |
20 | */\r | |
21 | public static double getSpeedForLinearAccel(double minSpeed, double maxSpeed,\r | |
22 | double percentComplete) {\r | |
23 | return 4 * (minSpeed - maxSpeed) * (percentComplete - 0.5)\r | |
24 | * (percentComplete - 0.5) + maxSpeed;\r | |
25 | }\r | |
26 | \r | |
27 | /***\r | |
28 | * This method gives speed as a function of % distance covered so the speed\r | |
29 | * increases linearly from minSpeed to maxSpeed and then back down again.\r | |
30 | *\r | |
31 | * @param minSpeed\r | |
32 | * the starting and ending speed, in range [0, 1]\r | |
33 | * @param maxSpeed\r | |
34 | * the max speed, achieved at percentComplete = 1/2.\r | |
35 | * @param percentComplete\r | |
36 | * should be currentDistance / targetDistance\r | |
37 | * @return the speed (motor value) to set motors to.\r | |
38 | */\r | |
39 | public static double getSpeedForConstantAccel(double minSpeed,\r | |
40 | double maxSpeed, double percentComplete) {\r | |
41 | return maxSpeed + 2 * (minSpeed - maxSpeed)\r | |
42 | * Math.abs(percentComplete - 0.5);\r | |
43 | }\r | |
44 | \r | |
45 | }\r |