Robot Control Library
Motor

Description

Control 4 DC motor Channels.

<rc/motor.h>

The robotics cape can drive 4 DC motors bidirectionally powered only from a 2-cell lithium battery pack connected to the cape. The motors will not draw power from USB or the 9-18v DC Jack. Each channel can support 1.2A continuous and the user must be careful to choose motors which will not exceed this rating when stalled. Each channel is broken out on an independent 2-pin JST ZH connector.

Author
James Strawson
Date
1/31/2018

Macros

#define RC_MOTOR_DEFAULT_PWM_FREQ   25000
 25kHz More...
 

Functions

int rc_motor_init (void)
 Initializes all 4 motors and leaves them in a free-spin (0 throttle) state. More...
 
int rc_motor_init_freq (int pwm_frequency_hz)
 Just like rc_motor_init but allows the user to set the pwm frequency. More...
 
int rc_motor_cleanup (void)
 Puts all 4 motors into a free-spin (0 throttle) state, puts the h-bridges into standby mode, and closes all file pointers to GPIO and PWM systems. More...
 
int rc_motor_standby (int standby_en)
 Toggle the H-bridges in and out of low-power standby mode. More...
 
int rc_motor_set (int ch, double duty)
 Sets the bidirectional duty cycle (power) to a single motor or all motors if 0 is provided as a channel. More...
 
int rc_motor_free_spin (int ch)
 Puts a motor into a zero-throttle state allowing it to spin freely. More...
 
int rc_motor_brake (int ch)
 Connects the motor terminal pairs together which makes the motor fight against its own back EMF turning it into a brake resisting rotation. More...
 

Macro Definition Documentation

◆ RC_MOTOR_DEFAULT_PWM_FREQ

#define RC_MOTOR_DEFAULT_PWM_FREQ   25000

25kHz

Examples:
rc_test_motors.c.

Function Documentation

◆ rc_motor_init()

int rc_motor_init ( void  )

Initializes all 4 motors and leaves them in a free-spin (0 throttle) state.

Note, if the user is optionally using the rc_motor_standby functionality they should be aware that rc_motor_init starts standby mode in a disabled state so it is not necessary for the majority of users who are not interested in standby mode.

This starts the motor drivers at RC_MOTOR_DEFAULT_PWM_FREQ. To use another frequency initialize with rc_motor_init_freq instead.

Returns
0 on success, -1 on failure which is usually due to lack of user permissions to access the gpio and pwm systems.
Examples:
rc_balance.c.

◆ rc_motor_init_freq()

int rc_motor_init_freq ( int  pwm_frequency_hz)

Just like rc_motor_init but allows the user to set the pwm frequency.

RC_MOTOR_DEFAULT_PWM_FREQ is a good frequency to start at.

Note, if the user is optionally using the rc_motor_standby functionality they should be aware that rc_motor_init starts standby mode in a disabled state so it is not necessary for the majority of users who are not interested in standby mode.

Parameters
[in]pwm_frequency_hzThe pwm frequency in hz
Returns
0 on success, -1 on failure which is usually due to lack of user permissions to access the gpio and pwm systems.
Examples:
rc_test_motors.c.

◆ rc_motor_cleanup()

int rc_motor_cleanup ( void  )

Puts all 4 motors into a free-spin (0 throttle) state, puts the h-bridges into standby mode, and closes all file pointers to GPIO and PWM systems.

Returns
0 on success, -1 on failure.
Examples:
rc_test_motors.c.

◆ rc_motor_standby()

int rc_motor_standby ( int  standby_en)

Toggle the H-bridges in and out of low-power standby mode.

This is an entirely optional function as calling rc_motor_cleanup when your program closes will put the h-bridges into standby mode and then calling rc_motor_init at the beginning of your program will take them out of standby mode. However, if the user wishes to toggle in and out of standby mode in their program (for example while paused) then they can use this function.

Parameters
[in]standby_en1 to enable standby mode, 0 to disable
Returns
0 on success, -1 on failure.
Examples:
rc_balance.c.

◆ rc_motor_set()

int rc_motor_set ( int  ch,
double  duty 
)

Sets the bidirectional duty cycle (power) to a single motor or all motors if 0 is provided as a channel.

Parameters
[in]chThe motor channel (1-4) or 0 for all channels.
[in]dutyDuty cycle, -1.0 for full reverse, 1.0 for full forward
Returns
0 on success, -1 on failure
Examples:
rc_balance.c, and rc_test_motors.c.

◆ rc_motor_free_spin()

int rc_motor_free_spin ( int  ch)

Puts a motor into a zero-throttle state allowing it to spin freely.

This is accomplished by putting both motor terminals connected to the h-bridge into a high-impedance state.

Parameters
[in]chThe motor channel (1-4) or 0 for all channels.
Returns
0 on success, -1 on failure
Examples:
rc_balance.c, and rc_test_motors.c.

◆ rc_motor_brake()

int rc_motor_brake ( int  ch)

Connects the motor terminal pairs together which makes the motor fight against its own back EMF turning it into a brake resisting rotation.

Parameters
[in]chThe motor channel (1-4) or 0 for all channels.
Returns
0 on success, -1 on failure
Examples:
rc_test_motors.c.