Advertisement
Guest User

2602H autonlib

a guest
Dec 14th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.62 KB | None | 0 0
  1. #ifndef AUTONS_HPP
  2. #define AUTONS_HPP
  3.  
  4. #include "main.h"
  5.  
  6. const bool DISABLE_AUTONOMOUS = false;
  7.  
  8. //S_armsMotion_proceed{
  9. const int TILTER_MAX_VALUE = 0;
  10. const int TILTER_MIN_VALUE = -2950;
  11. const int TILTER_SPEED = 127;
  12. const int LIFT_MAX_VALUE = 1300;
  13. const int LIFT_MIN_VALUE = 0;
  14. const int LIFT_SPEED = 127;
  15. const int INTAKEA_SPEED = 127;
  16. const int INTAKEB_SPEED = 127;
  17. //}
  18.  
  19. //backup_autonomous_API
  20. const int AUTOMOVE_ALLOWABLE_ERROR = 36;
  21. const int AUTOMOVE_SUCCESS_HOLDING_TIME = 200;
  22. const int LCD_DISPLAY_FRAMERATE = 30;
  23. //backup_autonomous_API
  24.  
  25. extern PID drivePID;
  26. extern PID turnPID;
  27.  
  28. extern float lastSlew;
  29. extern float maxAccel;
  30. extern float maxAccelTray;
  31. extern float lastSlewRate;
  32.  
  33. void A_goTo(float targetX, float targetY);
  34. /*
  35. Goes to a specific coordinate using ODOM
  36.  
  37. *targetX - X coordinate
  38. *targetY - Y coordinate
  39. */
  40. void setDrive(int left, int right);
  41. /*
  42. Helper function for Chassis
  43.  
  44. *left - Set left side power
  45. *right - Set right side power
  46. */
  47. void A_rotate(int degrees, int voltage);
  48. /*
  49. Gyro based turning
  50.  
  51. *degrees - Amount of degrees you want to turn
  52. *voltage - Controls chassis voltage (Ex. 127 for max speed)
  53. */
  54. float slewCalc(float desiredRate);
  55. /*
  56. A basic 1D motion profiler / Acceleration Control
  57.  
  58. *desiredRate - Input value for slew to be applied to.
  59. */
  60. float motorSlew(float desiredRate, float maxAccelMotor);
  61. /*
  62. 1D motion profiling for a specific motor.
  63.  
  64. *desiredRate - Input value for slewrate to be applied to.
  65. *maxAccelMotor - Input max acceleration rate for the motor.
  66. */
  67. void A_motorTarget(int port, PID pid, int special, int target, int time, float speed, float accel, bool slew);
  68. /*
  69. One motor target movement function w/ PID and slew.
  70.  
  71. *port - Port of the motor
  72. *pid - Motor's PID **MAKE SURE TO INITIALIZE IN AUTON**
  73. *special - Get the encoder value from a specific source. 0 = IME, 1 = Potentiometer
  74. *target - Specified target
  75. *time - Allowed time in ms
  76. *speed - Speed coefficient
  77. *accel - Maximum acceletation allowed (Ex. 0.16)
  78. *slew - Slew enabled if true
  79. */
  80. void A_driveTarget(int target, int time, float speed);
  81. /*
  82. Straight Line Motion
  83.  
  84. *Target - Desired Target Value
  85. *Time - Allowed time for the function to run before it ends (ms)
  86. *Speed - Speed multiplier for the drive (Ex. 0.5 50% speed, 1 100% speed)
  87. */
  88. void A_gyroDriveTarget(float angle, int target, int time, float speed);
  89. /*
  90. Straight Line Motion with Gyro Correction.
  91.  
  92. *Angle - Uses Gyro to correct angle while driving / RELATIVE TO STARTING ALIGNMENT.
  93. *Target - Desired Target Value
  94. *Time - Allowed time for the function to run before it ends (ms)
  95. *Speed - Speed multiplier for the drive (Ex. 0.5 50% speed, 1 100% speed)
  96. PID and Slew applied by default.
  97. */
  98. void A_gyroTurn(int target, int accuracy, int time, float speed);
  99. /*
  100. Gyro based turning with PID and Slew
  101.  
  102. *Target - Angle of Turn
  103. *Accuracy - How close to the target the robot is
  104. *Time - Amount of time allowed for the turn. (In MS)
  105. *Speed - Speed coefficient. Ex. 1 is max speed, 0.5 is half speed.
  106. */
  107. bool S_motorSuccess( pros::Motor motor );
  108. /*
  109. Check if a motor reached it's target position
  110.  
  111. parameters:
  112. -pros::Motor motor - motor to be checked
  113.  
  114. constants:
  115. -AUTOMOVE_ALLOWABLE_ERROR - the maximum diffrence between the target position and the real position that will be considered success (for all motors)
  116.  
  117. return:
  118. -bool true - if the motor reached it's target position OR
  119. -bool false - if the motor does not reach it's target position
  120.  
  121. return after:
  122. -instantly
  123. */
  124. int S_chassis_wait_till_success(int timeOut, int mode);
  125. /*
  126. Wait until all chassis motors reached it's target position
  127.  
  128. parameters:
  129. -int timeOut - maximum wait time before timeout (in milliseconds)
  130. -int mode - the movement mode of the chassis currently (0 for move, 1 for turn)
  131.  
  132. constants:
  133. -AUTOMOVE_SUCCESS_HOLDING_TIME - the minimum time as holding the chassis in the target position before considering the move being successed
  134. -LCD_DISPLAY_FRAMERATE - the framerate of the LCD-display
  135.  
  136. return:
  137. -int 0 - if the all chassis motors reached it's target position before timeout OR
  138. -int -1 - if timeOut
  139.  
  140. return after: (WARNING: this is a synchronous function)
  141. -all chassis motors reached it's target get_position OR
  142. -timeout
  143. */
  144. int S_chassis_move(int angle, float speed, int timeOut);
  145. /*
  146. Move the chassis in a straight line with a specific speed and for a specific distance
  147.  
  148. parameters:
  149. -int angle - the total angle required for the motors of the chassis to spin (in degrees)
  150. -float speed - the required speed for the chassis to move (in proportion, from 0 to 1)
  151. -int timeout - maximum move attempting time before timeout (in milliseconds)
  152.  
  153. constants:
  154. -none
  155.  
  156. return:
  157. -int 0 - if the move successed before timeout OR
  158. -int -1 - if timeout
  159.  
  160. return after: (WARNING: this is a synchronous function)
  161. -move successed OR
  162. -timeout
  163. */
  164. int S_chassis_turn(int angle, float speed, int timeOut);
  165. /*
  166. Turn the chassis in a specific speed for a specific angle
  167.  
  168. parameters:
  169. -int angle - the total angle required for the motors of the chassis to spin (in degrees)
  170. -float speed - the required speed for the chassis to move (in proportion, from 0 to 1)
  171. -int timeout - maximum move attempting time before timeout (in milliseconds)
  172.  
  173. constants:
  174. -none
  175.  
  176. return:
  177. -int 0 - if the turn successed before timeout OR
  178. -int -1 - if timeout
  179.  
  180. return after: (WARNING: this is a synchronous function)
  181. -turn successed OR
  182. -timeout
  183. */
  184. void S_zero_all_motors();
  185. /*
  186. Stop all motors from moving (WARNING:using this function inappropriately will cause the motors to malfunction)
  187.  
  188. parameters:
  189. -none
  190.  
  191. constants:
  192. -none
  193.  
  194. return:
  195. -none
  196.  
  197. return after:
  198. -instantly
  199. */
  200. void S_reset_all_motors();
  201. /*
  202. Reset the position of all motors to 0 (WARNING:using this function inappropriately will cause the motors to malfunction)
  203.  
  204. parameters:
  205. -none
  206.  
  207. constants:
  208. -none
  209.  
  210. return:
  211. -none
  212.  
  213. return after:
  214. -instantly
  215. */
  216. void S_reset_chassis_motors();
  217. /*
  218. Reset the position of all chassis motors to 0 (WARNING:using this function inappropriatly will cause the motors to malfunction)
  219.  
  220. parameters:
  221. -none
  222.  
  223. constants:
  224. -none
  225.  
  226. return:
  227. -none
  228.  
  229. return after:
  230. -instantly
  231. */
  232. void S_drive_chassis_tank();
  233. /*
  234. Drive the chassis with a tank-drive (implement: call the function in the main loop, between 20 to 1000 hz)
  235.  
  236. parameters:
  237. -none
  238.  
  239. constants:
  240. -none
  241.  
  242. return:
  243. -none
  244.  
  245. return after:
  246. -instantly
  247. */
  248. void S_drive_chassis_arcade();
  249. /*
  250. Drive the chassis with a arcade-drive (implement: call the function in the main loop, between 20 to 1000 hz)
  251.  
  252. parameters:
  253. -none
  254.  
  255. constants:
  256. -none
  257.  
  258. return:
  259. -none
  260.  
  261. return after:
  262. -instantly
  263. */
  264. void S_moveMotor_withLimit(pros::Motor motor, int velocity, int max_value, int min_value,
  265. pros::controller_digital_e_t button1, pros::controller_digital_e_t button2, int limitSource);
  266. /*
  267. Set the movement to a motor according to the status of two buttons and the position and the limit-position in a specific speed
  268.  
  269. parameters:
  270. -pros::Motor motor - motor to be moved
  271. -int velocity - the speed of the movement (from 0 to 127)
  272. -int max_value - the maximum allowed position of the motor
  273. -int min_value - the minimum allowed position of the motor
  274. -pros::controller_digital_e_t button1 - the button to use to move the motor forward
  275. -pros::controller_digital_e_t button2 - the button to use to move the motor backward
  276. -int limitSource - indicate the data source of the motor's position (0 for disable limit, 1 for motor's IMU, 2 for anglemeter, 3 for encoder)
  277. WARNING: the anglemeter limit source and the encoder limit source is NOT implemented yet (limitSource 2 OR limitSource 3)
  278.  
  279. constants:
  280. -none
  281.  
  282. return:
  283. -none
  284.  
  285. return after:
  286. -instantly
  287. */
  288. void S_armsMotion_proceed();
  289. /*
  290. Control the arms of the robot in the following way: (implement: call the function in the main loop, between 20 to 1000 hz)
  291. - button L1 and L2 - tilter
  292. - button UP and DOWN - lift
  293. - button R1 and R2 - intake
  294.  
  295. parameters:
  296. -none
  297.  
  298. constants:
  299. --TILTER_SPEED, TILTER_MAX_VALUE, TILTER_MIN_VALUE, LIFT_SPEED, LIFT_MAX_VALUE, LIFT_MIN_VALUE, INTAKEA_SPEED, INTAKEB_SPEED
  300.  
  301. return:
  302. -none
  303.  
  304. return after:
  305. -instantly
  306. */
  307. void S_armsMotion_Amode_proceed();
  308. /*
  309. Control the arms of the robot in the following way: (implement: call the function in the main loop, between 20 to 1000 hz)
  310. - left joystick - tilter
  311. - button UP and DOWN - lift
  312. - button R1 and R2 - intake
  313.  
  314. parameters:
  315. -none
  316.  
  317. constants:
  318. --LIFT_SPEED, LIFT_MAX_VALUE, LIFT_MIN_VALUE, INTAKEA_SPEED, INTAKEB_SPEED
  319.  
  320. return:
  321. -none
  322.  
  323. return after:
  324. -instantly
  325. */
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement