Go to the source code of this file.
§ MAX_COMMAND
Maximum possible value for commands
Definition at line 11 of file motor.h.
§ MIN_COMMAND
Minimal value that makes the robot move
Definition at line 9 of file motor.h.
§ motor_direction_t
Alias for motor rotation sense.
Enumerator |
---|
FORWARD | Motor turns so that robot moves forward
|
BACKWARD | Motor turns so that robot moves backward
|
Definition at line 28 of file motor.h.
§ motor_sense_t
Alias for motor orientation.
Enumerator |
---|
DIRECTION_1 | Value 1
|
DIRECTION_2 | Value 2
|
Definition at line 40 of file motor.h.
§ motor_t
Alias to select the motor to work on.
Enumerator |
---|
MOTOR_LEFT | Left motor
|
MOTOR_RIGHT | Right motor
|
Definition at line 20 of file motor.h.
§ motor_get_direction()
Get the current rotation direction of the specified motor.
- Parameters
-
[in] | motor | The motor to look at. |
- Returns
- The current rotation direction of the specified motor.
- Return values
-
FORWARD/BACKWARD | |
-1 | Invalid 'motor' parameter. |
Definition at line 114 of file motor.c.
§ motor_get_speed()
int8_t motor_get_speed |
( |
motor_t |
motor | ) |
|
Get the rotation speed of the specified motor.
- Parameters
-
[in] | motor | The motor to get the speed of. |
- Returns
- The rotation speed of the specified motor or -1 in case of error.
Definition at line 103 of file motor.c.
§ motor_init()
Initialise the motor driver.
This function is in charge of enabling all the low-level components used to control the motors. It configures the timers used to generate the PWM and starts them. It also sets the direction pins so that the motors turn forward as defined by the parameters.
- Parameters
-
[in] | motor_left_forward_sense | The rotation direction which corresponds to a forward movement of the left motor. |
[in] | motor_right_forward_sense | The rotation direction which corresponds to a forward movement of the right motor. |
- Note
- To provide a high-level interface to control the motors, this driver uses the values FORWARD and BACKWARD to describe the rotation direction of the motors. However, these directions depend on how the motors are placed in the robot and how they are wired on the H-bridge. In order to foster reusability of this driver, the mapping between pins state and rotation direction is settable. The 2 parameters of this init function are for this purpose. DIRECTION_1 corresponds to PIN_A at '1' (+3V3) and PIN_B at '0' (GND). DIRECTION_2 corresponds to PIN_A at '0' (GND) and PIN_B at '1' (+3V3).
- Warning
- This function must be called first to start the motor driver.
Definition at line 48 of file motor.c.
§ motor_set_direction()
Set the rotation direction of the specified motor.
- Parameters
-
[in] | motor | To motor to set the direction of. |
[in] | direction | The requested rotation direction. |
- Returns
- An int indicating success, else an error code.
- Return values
-
0 | Success. |
-1 | Invalid 'motor' parameter. |
-2 | Invalid 'direction' parameter (out of range). |
Definition at line 123 of file motor.c.
§ motor_set_speed()
int motor_set_speed |
( |
motor_t |
motor, |
|
|
uint8_t |
speed |
|
) |
| |
Set the rotation speed of the specified motor.
- Parameters
-
[in] | motor | The motor to change the speed of. |
[in] | speed | The requested speed. Allowed range is [0,MAX_COMMAND]. Be careful that a minimum non-zero value (MIN_COMMAND) is required for the robot to move. |
- Returns
- An int indicating success, else an error code.
- Return values
-
0 | Success. |
-1 | Invalid 'motor' parameter. |
-2 | Invalid 'speed' parameter (out of range). |
Definition at line 77 of file motor.c.
§ motor_toggle_direction()
void motor_toggle_direction |
( |
motor_t |
motor | ) |
|
Revert the rotation direction of the specified motor.
- Parameters
-
[in] | motor | To motor to change the rotation direction of. |
Definition at line 145 of file motor.c.