EV3RT C API Reference [English]
An RTOS-based development platform for LEGO Mindstorms EV3.
 All Data Structures Functions Variables Enumerations Enumerator Groups
Motor

Definitions of API for controlling motors. More...

Enumerations

enum  motor_port_t {
  EV3_PORT_A = 0,
  EV3_PORT_B = 1,
  EV3_PORT_C = 2,
  EV3_PORT_D = 3,
  TNUM_MOTOR_PORT = 4
}
 ID for supported motor ports. More...
 
enum  motor_type_t {
  NONE_MOTOR = 0,
  MEDIUM_MOTOR,
  LARGE_MOTOR,
  UNREGULATED_MOTOR,
  TNUM_MOTOR_TYPE
}
 Enumeration type for supported motor types. More...
 

Functions

ER ev3_motor_config (motor_port_t port, motor_type_t type)
 Configure a motor port. More...
 
ER_UINT ev3_motor_get_type (motor_port_t port)
 Get the type of a motor port. More...
 
int32_t ev3_motor_get_counts (motor_port_t port)
 Get the angular position of a motor port. More...
 
ER ev3_motor_reset_counts (motor_port_t port)
 Reset the angular position of the motor to zero. More...
 
ER ev3_motor_set_power (motor_port_t port, int power)
 Set the unregulated power for a motor port. More...
 
int ev3_motor_get_power (motor_port_t port)
 Get the actual power of a motor port. More...
 
ER ev3_motor_stop (motor_port_t port, bool_t brake)
 Stop a motor port. More...
 
ER ev3_motor_rotate (motor_port_t port, int degrees, uint32_t speed_abs, bool_t blocking)
 Rotate a motor port for specified degrees. More...
 
ER ev3_motor_steer (motor_port_t left_motor, motor_port_t right_motor, int power, int turn_ratio)
 Move the robot along a curved path using two motors. More...
 

Detailed Description

Definitions of API for controlling motors.

Enumeration Type Documentation

ID for supported motor ports.

Enumerator
EV3_PORT_A 

Port A.

EV3_PORT_B 

Port B.

EV3_PORT_C 

Port C.

EV3_PORT_D 

Port D.

TNUM_MOTOR_PORT 

Number of motor ports.

Enumeration type for supported motor types.

Enumerator
NONE_MOTOR 

Not connected.

MEDIUM_MOTOR 

Medium servo motor.

LARGE_MOTOR 

Large servo motor.

UNREGULATED_MOTOR 

Unregulated motor.

TNUM_MOTOR_TYPE 

Number of motor types.

Function Documentation

ER ev3_motor_config ( motor_port_t  port,
motor_type_t  type 
)

Configure a motor port.

Set the type of motor connected to the motor port. You can also specify a new motor type even if you have already set it.

Parameters
portMotor port to be configured
typeMotor type for the specified motor port
Return values
E_OKSuccessful completion
E_IDIllegal motor port number
E_PARIllegal motor type
int32_t ev3_motor_get_counts ( motor_port_t  port)

Get the angular position of a motor port.

When an incorrect motor port number is specified, it always returns 0.

Parameters
portMotor port to be inquired
Returns
Angular position in degrees. A negative value means the motor rotate has rotated backwards. [TODO: number of degrees per one revolution of motor]
int ev3_motor_get_power ( motor_port_t  port)

Get the actual power of a motor port.

When an incorrect motor port number is specified, it always returns 0.

Parameters
portMotor port to be set
Returns
Motor power [TODO: range?]
ER_UINT ev3_motor_get_type ( motor_port_t  port)

Get the type of a motor port.

Parameters
portMotor port to be inquired
Return values
>=0Motor type of specified motor port
E_IDIllegal motor port number
ER ev3_motor_reset_counts ( motor_port_t  port)

Reset the angular position of the motor to zero.

Setting the value of the angular position sensor of the motor does not affect the actual power and position of the motor.

Parameters
portMotor port to be inquired
Return values
E_OKSuccessful completion
E_IDIllegal motor port number
E_OBJMotor port has not been initialized.
ER ev3_motor_rotate ( motor_port_t  port,
int  degrees,
uint32_t  speed_abs,
bool_t  blocking 
)

Rotate a motor port for specified degrees.

Parameters
portMotor port to be rotated
degreesDegrees to be rotated. A negative value makes the motor rotate backwards.
speed_absSpeed for rotating. The value is a percentage of full speed, ranging from 0 to +100.
blockingtrue (The function will be blocked until the rotation is finished), or false (The function will not be blocked).
Return values
E_OKSuccessful completion
E_IDIllegal motor port number
E_OBJMotor port has not been initialized.
ER ev3_motor_set_power ( motor_port_t  port,
int  power 
)

Set the unregulated power for a motor port.

Parameters
portMotor port to be set
powerThe percentage of full power, ranging from -100 to +100. A negative value makes the motor rotate backwards.
Return values
E_OKSuccessful completion
E_IDIllegal motor port number
E_OBJMotor port has not been initialized.

Start the motor

ER ev3_motor_steer ( motor_port_t  left_motor,
motor_port_t  right_motor,
int  power,
int  turn_ratio 
)

Move the robot along a curved path using two motors.

Parameters
left_motorID of the left motor port
right_motorID of the right motor port
powerPower of motors. Range: -100 to +100. A negative value moves the robot backwards.
turn_ratioThe sharpness of the turn. Range: -100 to +100. If turn_ratio is negative, the robot will turn left. If turn_ratio is positive, the robot will turn right. More specifically, turn_ratio determines the ratio of inner wheel speed as a percent. For example, if turn_ratio is +25, the right motor will move at 75% of the power, which makes the robot turn right.
Return values
E_OKSuccess
E_IDInvalid ID of motor port
E_OBJMotor port has not been initialized.
ER ev3_motor_stop ( motor_port_t  port,
bool_t  brake 
)

Stop a motor port.

Parameters
portMotor port to be stopped
brakeBrake mode, true for braking, false for coasting.
Return values
E_OKSuccessful completion
E_IDIllegal motor port number
E_OBJMotor port has not been initialized.