Practical Robotics Modular Robot Library
motors.h@1:a6728adaf7e7, 2016-11-26 (annotated)
- Committer:
- jah128
- Date:
- Sat Nov 26 21:43:52 2016 +0000
- Revision:
- 1:a6728adaf7e7
- Parent:
- 0:8a2dd255c508
- Child:
- 3:8762f6b2ea8d
Added docs, debug
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 0:8a2dd255c508 | 1 | #ifndef MOTORS_H |
jah128 | 0:8a2dd255c508 | 2 | #define MOTORS_H |
jah128 | 0:8a2dd255c508 | 3 | |
jah128 | 1:a6728adaf7e7 | 4 | /** |
jah128 | 1:a6728adaf7e7 | 5 | * The Motors class contains the functions to control the robots motors |
jah128 | 1:a6728adaf7e7 | 6 | */ |
jah128 | 0:8a2dd255c508 | 7 | class Motors |
jah128 | 0:8a2dd255c508 | 8 | { |
jah128 | 0:8a2dd255c508 | 9 | public: |
jah128 | 0:8a2dd255c508 | 10 | /** |
jah128 | 0:8a2dd255c508 | 11 | * Setup the PWM based H-Bridge drivers for the motors |
jah128 | 0:8a2dd255c508 | 12 | */ |
jah128 | 0:8a2dd255c508 | 13 | void init(void); |
jah128 | 0:8a2dd255c508 | 14 | |
jah128 | 0:8a2dd255c508 | 15 | |
jah128 | 1:a6728adaf7e7 | 16 | /** |
jah128 | 1:a6728adaf7e7 | 17 | * Put the H-Bridge drivers in sleep (low-power) mode |
jah128 | 1:a6728adaf7e7 | 18 | */ |
jah128 | 1:a6728adaf7e7 | 19 | void sleep(void); |
jah128 | 0:8a2dd255c508 | 20 | |
jah128 | 1:a6728adaf7e7 | 21 | /** |
jah128 | 1:a6728adaf7e7 | 22 | * Wake the H-Bridge drivers from sleep mode |
jah128 | 1:a6728adaf7e7 | 23 | */ |
jah128 | 0:8a2dd255c508 | 24 | void wake_up(void); |
jah128 | 1:a6728adaf7e7 | 25 | |
jah128 | 1:a6728adaf7e7 | 26 | /** |
jah128 | 1:a6728adaf7e7 | 27 | * Set the left H-Bridge driver to high-Z (coast mode) for the motor |
jah128 | 1:a6728adaf7e7 | 28 | */ |
jah128 | 0:8a2dd255c508 | 29 | void coast_left(void); |
jah128 | 1:a6728adaf7e7 | 30 | |
jah128 | 1:a6728adaf7e7 | 31 | /** |
jah128 | 1:a6728adaf7e7 | 32 | * Set the left H-Bridge driver to active brake |
jah128 | 1:a6728adaf7e7 | 33 | */ |
jah128 | 0:8a2dd255c508 | 34 | void brake_left(void); |
jah128 | 1:a6728adaf7e7 | 35 | |
jah128 | 1:a6728adaf7e7 | 36 | /** |
jah128 | 1:a6728adaf7e7 | 37 | * Set the speed and direction of the left-motor H-Bridge driver |
jah128 | 1:a6728adaf7e7 | 38 | * |
jah128 | 1:a6728adaf7e7 | 39 | * @param speed - A value between -1.0 [max reverse], 0 [coast] and 1.0 [max forward] |
jah128 | 1:a6728adaf7e7 | 40 | */ |
jah128 | 0:8a2dd255c508 | 41 | void set_left_motor_speed(float speed); |
jah128 | 1:a6728adaf7e7 | 42 | |
jah128 | 1:a6728adaf7e7 | 43 | /** |
jah128 | 1:a6728adaf7e7 | 44 | * Set the right H-Bridge driver to high-Z (coast mode) for the motor |
jah128 | 1:a6728adaf7e7 | 45 | */ |
jah128 | 0:8a2dd255c508 | 46 | void coast_right(void); |
jah128 | 1:a6728adaf7e7 | 47 | |
jah128 | 1:a6728adaf7e7 | 48 | /** |
jah128 | 1:a6728adaf7e7 | 49 | * Set the right H-Bridge driver to active brake |
jah128 | 1:a6728adaf7e7 | 50 | */ |
jah128 | 0:8a2dd255c508 | 51 | void brake_right(void); |
jah128 | 1:a6728adaf7e7 | 52 | |
jah128 | 1:a6728adaf7e7 | 53 | /** |
jah128 | 1:a6728adaf7e7 | 54 | * Set both H-Bridge drivers to high-Z (coast mode) for the motor |
jah128 | 1:a6728adaf7e7 | 55 | */ |
jah128 | 0:8a2dd255c508 | 56 | void coast(void); |
jah128 | 1:a6728adaf7e7 | 57 | |
jah128 | 1:a6728adaf7e7 | 58 | /** |
jah128 | 1:a6728adaf7e7 | 59 | * Set both H-Bridge drivers to active brake |
jah128 | 1:a6728adaf7e7 | 60 | */ |
jah128 | 0:8a2dd255c508 | 61 | void brake(void); |
jah128 | 1:a6728adaf7e7 | 62 | |
jah128 | 1:a6728adaf7e7 | 63 | /** |
jah128 | 1:a6728adaf7e7 | 64 | * Set the speed and direction of the right-motor H-Bridge driver |
jah128 | 1:a6728adaf7e7 | 65 | * |
jah128 | 1:a6728adaf7e7 | 66 | * @param speed - A value between -1.0 [max reverse], 0 [coast] and 1.0 [max forward] |
jah128 | 1:a6728adaf7e7 | 67 | */ |
jah128 | 0:8a2dd255c508 | 68 | void set_right_motor_speed(float speed); |
jah128 | 1:a6728adaf7e7 | 69 | |
jah128 | 1:a6728adaf7e7 | 70 | /** |
jah128 | 1:a6728adaf7e7 | 71 | * Get the approximate instantaneous current draw of the left-motor H-Bridge driver |
jah128 | 1:a6728adaf7e7 | 72 | * |
jah128 | 1:a6728adaf7e7 | 73 | * @returns The current value in A |
jah128 | 1:a6728adaf7e7 | 74 | */ |
jah128 | 0:8a2dd255c508 | 75 | float get_current_left(void); |
jah128 | 1:a6728adaf7e7 | 76 | |
jah128 | 1:a6728adaf7e7 | 77 | /** |
jah128 | 1:a6728adaf7e7 | 78 | * Get the approximate instantaneous current draw of the right-motor H-Bridge driver |
jah128 | 1:a6728adaf7e7 | 79 | * |
jah128 | 1:a6728adaf7e7 | 80 | * @returns The current value in A |
jah128 | 1:a6728adaf7e7 | 81 | */ |
jah128 | 0:8a2dd255c508 | 82 | float get_current_right(void); |
jah128 | 1:a6728adaf7e7 | 83 | |
jah128 | 1:a6728adaf7e7 | 84 | /** |
jah128 | 1:a6728adaf7e7 | 85 | * Calculates an adjusted speed value to avoid stalls at low-speeds if USE_STALL_OFFSET is set to 1 [in robot.h] |
jah128 | 1:a6728adaf7e7 | 86 | * @params speed_in - The speed value from 0.0 to 1.0 |
jah128 | 1:a6728adaf7e7 | 87 | * @returns The adjusted speed value from 0.0 to 1.0, increased by STALL_OFFSET then scaled to fit |
jah128 | 1:a6728adaf7e7 | 88 | */ |
jah128 | 0:8a2dd255c508 | 89 | float get_adjusted_speed(float speed_in); |
jah128 | 0:8a2dd255c508 | 90 | |
jah128 | 0:8a2dd255c508 | 91 | |
jah128 | 0:8a2dd255c508 | 92 | }; |
jah128 | 0:8a2dd255c508 | 93 | |
jah128 | 0:8a2dd255c508 | 94 | #endif |