Practical Robotics Modular Robot Library

Dependents:   ModularRobot

Committer:
jah128
Date:
Fri Jan 13 23:16:23 2017 +0000
Revision:
6:732aa91eb555
Parent:
5:6da8daaeb9f7
Updated;

Who changed what in which revision?

UserRevisionLine numberNew 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 3:8762f6b2ea8d 14
jah128 3:8762f6b2ea8d 15 /**
jah128 3:8762f6b2ea8d 16 * Returns the current [adjusted] value for the target left motor speed
jah128 3:8762f6b2ea8d 17 *
jah128 3:8762f6b2ea8d 18 * @returns The speed value from -1.0 to 1.0
jah128 3:8762f6b2ea8d 19 */
jah128 3:8762f6b2ea8d 20 float get_left_motor_speed(void);
jah128 3:8762f6b2ea8d 21
jah128 3:8762f6b2ea8d 22 /**
jah128 3:8762f6b2ea8d 23 * Returns the current [adjusted] value for the target right motor speed
jah128 3:8762f6b2ea8d 24 *
jah128 3:8762f6b2ea8d 25 * @returns The speed value from -1.0 to 1.0
jah128 3:8762f6b2ea8d 26 */
jah128 3:8762f6b2ea8d 27 float get_right_motor_speed(void);
jah128 3:8762f6b2ea8d 28
jah128 3:8762f6b2ea8d 29 /**
jah128 3:8762f6b2ea8d 30 * Calls set_left_motor_speed and set_right_motor_speed with equal values
jah128 3:8762f6b2ea8d 31 *
jah128 3:8762f6b2ea8d 32 * @params speed - The forward speed value from -1.0 to 1.0
jah128 3:8762f6b2ea8d 33 */
jah128 3:8762f6b2ea8d 34 void forwards(float speed);
jah128 3:8762f6b2ea8d 35
jah128 3:8762f6b2ea8d 36 /**
jah128 3:8762f6b2ea8d 37 * Calls set_left_motor_speed and set_right_motor_speed with equal inverse values
jah128 3:8762f6b2ea8d 38 *
jah128 3:8762f6b2ea8d 39 * @params speed - The forward speed value from -1.0 (max forwards) to 1.0 (max reverse)
jah128 3:8762f6b2ea8d 40 */
jah128 3:8762f6b2ea8d 41 void backwards(float speed);
jah128 3:8762f6b2ea8d 42
jah128 3:8762f6b2ea8d 43 /**
jah128 3:8762f6b2ea8d 44 * Calls set_left_motor_speed and set_right_motor_speed with sign-opposite values
jah128 3:8762f6b2ea8d 45 *
jah128 3:8762f6b2ea8d 46 * @params speed - The forward speed value from -1.0 (max counterclockwise) to 1.0 (max clockwise)
jah128 3:8762f6b2ea8d 47 */
jah128 3:8762f6b2ea8d 48 void turn(float speed);
jah128 3:8762f6b2ea8d 49
jah128 1:a6728adaf7e7 50 /**
jah128 1:a6728adaf7e7 51 * Put the H-Bridge drivers in sleep (low-power) mode
jah128 3:8762f6b2ea8d 52 */
jah128 1:a6728adaf7e7 53 void sleep(void);
jah128 3:8762f6b2ea8d 54
jah128 1:a6728adaf7e7 55 /**
jah128 1:a6728adaf7e7 56 * Wake the H-Bridge drivers from sleep mode
jah128 1:a6728adaf7e7 57 */
jah128 0:8a2dd255c508 58 void wake_up(void);
jah128 3:8762f6b2ea8d 59
jah128 1:a6728adaf7e7 60 /**
jah128 1:a6728adaf7e7 61 * Set the left H-Bridge driver to high-Z (coast mode) for the motor
jah128 1:a6728adaf7e7 62 */
jah128 0:8a2dd255c508 63 void coast_left(void);
jah128 3:8762f6b2ea8d 64
jah128 1:a6728adaf7e7 65 /**
jah128 1:a6728adaf7e7 66 * Set the left H-Bridge driver to active brake
jah128 1:a6728adaf7e7 67 */
jah128 0:8a2dd255c508 68 void brake_left(void);
jah128 3:8762f6b2ea8d 69
jah128 1:a6728adaf7e7 70 /**
jah128 1:a6728adaf7e7 71 * Set the speed and direction of the left-motor H-Bridge driver
jah128 1:a6728adaf7e7 72 *
jah128 1:a6728adaf7e7 73 * @param speed - A value between -1.0 [max reverse], 0 [coast] and 1.0 [max forward]
jah128 1:a6728adaf7e7 74 */
jah128 0:8a2dd255c508 75 void set_left_motor_speed(float speed);
jah128 3:8762f6b2ea8d 76
jah128 1:a6728adaf7e7 77 /**
jah128 1:a6728adaf7e7 78 * Set the right H-Bridge driver to high-Z (coast mode) for the motor
jah128 1:a6728adaf7e7 79 */
jah128 0:8a2dd255c508 80 void coast_right(void);
jah128 3:8762f6b2ea8d 81
jah128 1:a6728adaf7e7 82 /**
jah128 1:a6728adaf7e7 83 * Set the right H-Bridge driver to active brake
jah128 1:a6728adaf7e7 84 */
jah128 0:8a2dd255c508 85 void brake_right(void);
jah128 3:8762f6b2ea8d 86
jah128 1:a6728adaf7e7 87 /**
jah128 1:a6728adaf7e7 88 * Set both H-Bridge drivers to high-Z (coast mode) for the motor
jah128 1:a6728adaf7e7 89 */
jah128 0:8a2dd255c508 90 void coast(void);
jah128 3:8762f6b2ea8d 91
jah128 3:8762f6b2ea8d 92 /**
jah128 3:8762f6b2ea8d 93 * Set both H-Bridge drivers to active brake
jah128 3:8762f6b2ea8d 94 */
jah128 0:8a2dd255c508 95 void brake(void);
jah128 3:8762f6b2ea8d 96
jah128 1:a6728adaf7e7 97 /**
jah128 1:a6728adaf7e7 98 * Set the speed and direction of the right-motor H-Bridge driver
jah128 1:a6728adaf7e7 99 *
jah128 1:a6728adaf7e7 100 * @param speed - A value between -1.0 [max reverse], 0 [coast] and 1.0 [max forward]
jah128 1:a6728adaf7e7 101 */
jah128 0:8a2dd255c508 102 void set_right_motor_speed(float speed);
jah128 3:8762f6b2ea8d 103
jah128 1:a6728adaf7e7 104 /**
jah128 1:a6728adaf7e7 105 * Get the approximate instantaneous current draw of the left-motor H-Bridge driver
jah128 1:a6728adaf7e7 106 *
jah128 1:a6728adaf7e7 107 * @returns The current value in A
jah128 1:a6728adaf7e7 108 */
jah128 0:8a2dd255c508 109 float get_current_left(void);
jah128 3:8762f6b2ea8d 110
jah128 1:a6728adaf7e7 111 /**
jah128 1:a6728adaf7e7 112 * Get the approximate instantaneous current draw of the right-motor H-Bridge driver
jah128 1:a6728adaf7e7 113 *
jah128 1:a6728adaf7e7 114 * @returns The current value in A
jah128 1:a6728adaf7e7 115 */
jah128 0:8a2dd255c508 116 float get_current_right(void);
jah128 3:8762f6b2ea8d 117
jah128 1:a6728adaf7e7 118 /**
jah128 1:a6728adaf7e7 119 * 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 120 * @params speed_in - The speed value from 0.0 to 1.0
jah128 1:a6728adaf7e7 121 * @returns The adjusted speed value from 0.0 to 1.0, increased by STALL_OFFSET then scaled to fit
jah128 1:a6728adaf7e7 122 */
jah128 0:8a2dd255c508 123 float get_adjusted_speed(float speed_in);
jah128 5:6da8daaeb9f7 124
jah128 5:6da8daaeb9f7 125 /**
jah128 5:6da8daaeb9f7 126 * Sets the PWM period in microseconds (minimum value set to 10 for 100kHZ PWM)
jah128 5:6da8daaeb9f7 127 */
jah128 5:6da8daaeb9f7 128 void set_pwm_period(int period_in);
jah128 3:8762f6b2ea8d 129
jah128 0:8a2dd255c508 130
jah128 0:8a2dd255c508 131 };
jah128 0:8a2dd255c508 132
jah128 0:8a2dd255c508 133 #endif