ev3c_motor

These functions are for reading motor values of the EV3 brick.  At the moment only tacho-motors are supported from ev3c.  The flow is to search first for all connected motors with ev3_load_motors.  This list can then be searched with ev3_search_motor_by_identifier and ev3_search_motor_by_port (or by hand).  To use a motor, it has to be opened with ev3_open_motor.  Then some motor settings can be set like the speed with ev3_set_speed_sp or the time to run ev3_set_time_sp and if everything is setup the motor can be run with ev3_command_motor.  In the very end the motors should be closed using ev3_close_motor or using ev3_delete_motors, which cleans the list and closes all motors if open.

Summary
ev3c_motorThese functions are for reading motor values of the EV3 brick.
Enumerations
ev3_motor_identifiera number for supported tacho motor in ev3dev.
ev3_motor_identifierstatus returned from ev3_motor_state
Types
ev3_motorA struct for every loaded motor.
Functions
ev3_load_motors
ev3_delete_motorsDeletes the linked list of available motors.
ev3_open_motorOpens the motor to be used.
ev3_search_motor_by_identifierSearches for a motor in the linked list identified with the identifier.
ev3_search_motor_by_portSearches for a motor in the linked list identified with the port.
ev3_close_motorCloses the motor.
ev3_command_motorSets the command of the motor, e.g.
ev3_command_motor_by_nameSets the command of the motor, e.g.
ev3_stop_action_motorSets the stop_action of the motor, e.g.
ev3_stop_action_motor_by_nameSets the stop_action of the motor, e.g.
ev3_reset_motorReset the motor to a default state.
ev3_get_duty_cycleReturns the duty cycle of a motor
ev3_set_duty_cycle_spSet the duty cycle set point of a motor.
ev3_get_duty_cycle_spReturns the duty cycle set point of a motor
ev3_get_speedReturns the speed of a motor
ev3_set_speed_spSet the speed set point of a motor.
ev3_get_speed_spReturns the speed set point of a motor
ev3_set_positionSet the position of a motor.
ev3_get_positionReturns the position of a motor
ev3_set_position_spSet the position set point of a motor.
ev3_get_position_spReturns the position set point of a motor
ev3_set_ramp_up_spSet the ramp up set point of a motor.
ev3_get_ramp_up_spReturns the ramp up set point of a motor
ev3_set_ramp_down_spSet the ramp down set point of a motor.
ev3_get_ramp_down_spReturns the ramp down set point of a motor
ev3_set_time_spSet the time set point of a motor.
ev3_get_time_spReturns the time set point of a motor
ev3_motor_stateReturns the state of the motor.
ev3_set_polaritySet the polarity of a motor.
ev3_get_polarityReturns the polarity of a motor

Enumerations

ev3_motor_identifier

a number for supported tacho motor in ev3dev.  For more information have a look at the ev3dev wiki.

Values

FI_L12_EV3Firgelli 12V Motor
LEGO_EV3_L_MOTORlarge lego motor, EV3 and NXT
LEGO_EV3_M_MOTORmiddle lego motor, atm only the small EV3 motor
UNKNOWN_MOTORunknown motor

ev3_motor_identifier

status returned from ev3_motor_state

Values

MOTOR_RUNNINGmotor is running
MOTOR_RAMPINGmotor speed is in- or decreasing
MOTOR_HOLDINGmotor position is hold
MOTOR_STALLEDmotor is stalled

Types

ev3_motor

A struct for every loaded motor.

Variables

driver_name(ev3_string) Name of the driver
driver_identifier(ev3_motor_identifier) Identifier of the driver
port(char) Port (‘A’..’D’) of the EV3 brick
motor_nr(int32) internal, incrementing counter of the motors in ev3dev
duty_cycle_fd(int32) file descriptor for internal use
duty_cycle_sp_fd(int32) file descriptor for internal use
position_fd(int32) file descriptor for internal use
position_sp_fd(int32) file descriptor for internal use
speed_fd(int32) file descriptor for internal use
speed_sp_fd(int32) file descriptor for internal use
ramp_up_sp_fd(int32) file descriptor for internal use
ramp_down_sp_fd(int32) file descriptor for internal use
time_sp_fd(int32) file descriptor for internal use
commands(array of ev3_string) the supported commands of the motor.
command_count(int32) the number of supported commands of the motor.
command(int32) the command mode.
next(pointer of ev3_motor) next element in the linked list.  NULL for the last element.

Functions

ev3_load_motors

ev3_motor_ptr ev3_load_motors(void)

Returns

*ev3_motorreturns a linked list of all available motors.

ev3_delete_motors

void ev3_delete_motors(ev3_motor_ptr motors)

Deletes the linked list of available motors.

Parameters

motors(pointer of ev3_motor) list to delete

ev3_open_motor

ev3_motor_ptr ev3_open_motor(ev3_motor_ptr motor)

Opens the motor to be used.  If called twice nothing happens.

Parameters

motor(pointer of ev3_motor) the motor to be opened.  You can just iterate of all motors returns by ev3_load_motors or you search for a specific motor with ev3_search_motor_by_identifier or ev3_search_motor_by_port and open just this one.

Returns

*ev3_motorreturns the parameter.  Useful if you opened the motor with ev3_open_motor(ev3_search_motor_by_identifier(...)).

ev3_search_motor_by_identifier

ev3_motor_ptr ev3_search_motor_by_identifier(
   ev3_motor_ptr motors,
   enum ev3_motor_identifier identifier,
   int32_t not_ready
)

Searches for a motor in the linked list identified with the identifier.  It may be, that you connected two motors with the same identifier.  In that case you can specify to search only for not yet opened motors.

Parameters

motors(pointer of ev3_motor) linked list of motors created by ev3_load_motors.
identifier(ev3_motor_identifier) Identifier to search for.
not_ready(int32) specifies, whether an already opened motor should be returned or not.  If not_ready is 1 only a not yet opened motor will be returned.

Returns

*ev3_motorthe found motor.  May be NULL if nothing is found.

ev3_search_motor_by_port

ev3_motor_ptr ev3_search_motor_by_port(ev3_motor_ptr motors,
char port)

Searches for a motor in the linked list identified with the port.  The ports are labeled like on the EV3 brick starting with ‘A’.

Parameters

motors(pointer of ev3_motor) linked list of motors created by ev3_load_motors.
port(char) Port to search for.

Returns

*ev3_motorthe found motor.  May be NULL if nothing is found.

ev3_close_motor

void ev3_close_motor(ev3_motor_ptr motor)

Closes the motor.  The pointer is not freed.  The values are not reseted or invalid.

Parameters

motor(point of ev3_motor) motor to close.

ev3_command_motor

ev3_motor_ptr ev3_command_motor(ev3_motor_ptr motor,
int32_t command)

Sets the command of the motor, e.g. run-forever.

Parameters

motor(pointer of ev3_motor) motor to change it’s command
command(int32) command to be set to.  It refers to the number in the array commands in motor.  E.g. run-forever would be 0.

Returns

*ev3_motorthe same pointer as passed as argument.  Useful for such call chains as ev3_open( ev3_command_motor( motor, 1 ) );

ev3_command_motor_by_name

ev3_motor_ptr ev3_command_motor_by_name(ev3_motor_ptr motor,
char *command)

Sets the command of the motor, e.g.  “run-forever”.  Slower, but more easy to use than ev3_command_motor, which makes sense espcecially if you change the command of a motor quite often.  If such a command doesn’t exist, nothing happens and no command is changed.

Parameters

motor(pointer of ev3_motor) motor to change it’s command
command(char*) command to be set to.  It refers to the name from in the array commands in motor, e.g.  “run-forever”.

Returns

*ev3_motorthe same pointer as passed as argument.  Useful for such call chains as ev3_open( ev3_command_motor( motor, 1 ) );

ev3_stop_action_motor

ev3_motor_ptr ev3_stop_action_motor(ev3_motor_ptr motor,
int32_t stop_action)

Sets the stop_action of the motor, e.g. hold.

Parameters

motor(pointer of ev3_motor) motor to change it’s stop_action
stop_action(int32) stop_action to be set to.  It refers to the number in the array stop_actions in motor.  E.g. hold would be 2.

Returns

*ev3_motorthe same pointer as passed as argument.  Useful for such call chains as ev3_open( ev3_stop_action_motor( motor, 1 ) );

ev3_stop_action_motor_by_name

ev3_motor_ptr ev3_stop_action_motor_by_name(ev3_motor_ptr motor,
char *stop_action)

Sets the stop_action of the motor, e.g.  “hold”.  Slower, but more easy to use than ev3_stop_action_motor, which makes sense espcecially if you change the stop_action of a motor quite often.  If such a stop_action doesn’t exist, nothing happens and no stop_action is changed.

Parameters

motor(pointer of ev3_motor) motor to change it’s stop_action
stop_action(char*) stop_action to be set to.  It refers to the name from in the array stop_actions in motor, e.g.  “hold”.

Returns

*ev3_motorthe same pointer as passed as argument.  Useful for such call chains as ev3_open( ev3_stop_action_motor( motor, 1 ) );

ev3_reset_motor

ev3_motor_ptr ev3_reset_motor(ev3_motor_ptr motor)

Reset the motor to a default state.  It may be a good idea to call this right after loading but before opening the motor.

Parameters

motor(pointer of ev3_motor) motor to reset

Returns

ev3_motorthe same pointer as passed as argument.

ev3_get_duty_cycle

int32_t ev3_get_duty_cycle(ev3_motor_ptr motor)

Returns the duty cycle of a motor

Parameter

motor(pointer of ev3_motor) motor to get the value from

Returns

int32_tthe duty cycle

ev3_set_duty_cycle_sp

ev3_motor_ptr ev3_set_duty_cycle_sp(ev3_motor_ptr motor,
int32_t value)

Set the duty cycle set point of a motor.

Parameter

motor(pointer of ev3_motor) motor to set the value
value(int32_t) value to set

ev3_get_duty_cycle_sp

int32_t ev3_get_duty_cycle_sp(ev3_motor_ptr motor)

Returns the duty cycle set point of a motor

Parameter

motor(pointer of ev3_motor) motor to get the value from

Returns

int32_tthe duty cycle set point

ev3_get_speed

int32_t ev3_get_speed(ev3_motor_ptr motor)

Returns the speed of a motor

Parameter

motor(pointer of ev3_motor) motor to get the value from

Returns

int32_tthe speed

ev3_set_speed_sp

ev3_motor_ptr ev3_set_speed_sp(ev3_motor_ptr motor,
int32_t value)

Set the speed set point of a motor.

Parameter

motor(pointer of ev3_motor) motor to set the value
value(int32_t) value to set

ev3_get_speed_sp

int32_t ev3_get_speed_sp(ev3_motor_ptr motor)

Returns the speed set point of a motor

Parameter

motor(pointer of ev3_motor) motor to get the value from

Returns

int32_tthe speed set point

ev3_set_position

ev3_motor_ptr ev3_set_position(ev3_motor_ptr motor,
int32_t value)

Set the position of a motor.

Parameter

motor(pointer of ev3_motor) motor to set the value
value(int32_t) value to set

ev3_get_position

int32_t ev3_get_position(ev3_motor_ptr motor)

Returns the position of a motor

Parameter

motor(pointer of ev3_motor) motor to get the value from

Returns

int32_tthe position

ev3_set_position_sp

ev3_motor_ptr ev3_set_position_sp(ev3_motor_ptr motor,
int32_t value)

Set the position set point of a motor.

Parameter

motor(pointer of ev3_motor) motor to set the value
value(int32_t) value to set

ev3_get_position_sp

int32_t ev3_get_position_sp(ev3_motor_ptr motor)

Returns the position set point of a motor

Parameter

motor(pointer of ev3_motor) motor to get the value from

Returns

int32_tthe position set point

ev3_set_ramp_up_sp

ev3_motor_ptr ev3_set_ramp_up_sp(ev3_motor_ptr motor,
int32_t value)

Set the ramp up set point of a motor.

Parameter

motor(pointer of ev3_motor) motor to set the value
value(int32_t) value to set

ev3_get_ramp_up_sp

int32_t ev3_get_ramp_up_sp(ev3_motor_ptr motor)

Returns the ramp up set point of a motor

Parameter

motor(pointer of ev3_motor) motor to get the value from

Returns

int32_tthe ramp up set point

ev3_set_ramp_down_sp

ev3_motor_ptr ev3_set_ramp_down_sp(ev3_motor_ptr motor,
int32_t value)

Set the ramp down set point of a motor.

Parameter

motor(pointer of ev3_motor) motor to set the value
value(int32_t) value to set

ev3_get_ramp_down_sp

int32_t ev3_get_ramp_down_sp(ev3_motor_ptr motor)

Returns the ramp down set point of a motor

Parameter

motor(pointer of ev3_motor) motor to get the value from

Returns

int32_tthe ramp down set point

ev3_set_time_sp

ev3_motor_ptr ev3_set_time_sp(ev3_motor_ptr motor,
int32_t value)

Set the time set point of a motor.

Parameter

motor(pointer of ev3_motor) motor to set the value
value(int32_t) value to set

ev3_get_time_sp

int32_t ev3_get_time_sp(ev3_motor_ptr motor)

Returns the time set point of a motor

Parameter

motor(pointer of ev3_motor) motor to get the value from

Returns

int32_tthe time set point

ev3_motor_state

int32_t ev3_motor_state(ev3_motor_ptr motor)

Returns the state of the motor.

Parameter

motor(pointer of ev3_motor) motor to get the value from

Returns

int32_tthe state of the motor.  The possibilites are all OR combinations of <ev3_motor_status>.

ev3_set_polarity

ev3_motor_ptr ev3_set_polarity(ev3_motor_ptr motor,
int32_t value)

Set the polarity of a motor.

Parameter

motor(pointer of ev3_motor) motor to set the value
value(int32_t) value to set.  -1 means inversed, 1 is normal

ev3_get_polarity

int32_t ev3_get_polarity(ev3_motor_ptr motor)

Returns the polarity of a motor

Parameter

motor(pointer of ev3_motor) motor to get the value from

Returns

int32_tthe polarity, 1 is normal, -1 is inversed
int32_t ev3_motor_state(ev3_motor_ptr motor)
Returns the state of the motor.
ev3_motor_ptr ev3_load_motors(void)
void ev3_delete_motors(ev3_motor_ptr motors)
Deletes the linked list of available motors.
ev3_motor_ptr ev3_open_motor(ev3_motor_ptr motor)
Opens the motor to be used.
ev3_motor_ptr ev3_search_motor_by_identifier(
   ev3_motor_ptr motors,
   enum ev3_motor_identifier identifier,
   int32_t not_ready
)
Searches for a motor in the linked list identified with the identifier.
ev3_motor_ptr ev3_search_motor_by_port(ev3_motor_ptr motors,
char port)
Searches for a motor in the linked list identified with the port.
void ev3_close_motor(ev3_motor_ptr motor)
Closes the motor.
ev3_motor_ptr ev3_command_motor(ev3_motor_ptr motor,
int32_t command)
Sets the command of the motor, e.g.
ev3_motor_ptr ev3_command_motor_by_name(ev3_motor_ptr motor,
char *command)
Sets the command of the motor, e.g.
ev3_motor_ptr ev3_stop_action_motor(ev3_motor_ptr motor,
int32_t stop_action)
Sets the stop_action of the motor, e.g.
ev3_motor_ptr ev3_stop_action_motor_by_name(ev3_motor_ptr motor,
char *stop_action)
Sets the stop_action of the motor, e.g.
ev3_motor_ptr ev3_reset_motor(ev3_motor_ptr motor)
Reset the motor to a default state.
int32_t ev3_get_duty_cycle(ev3_motor_ptr motor)
Returns the duty cycle of a motor
ev3_motor_ptr ev3_set_duty_cycle_sp(ev3_motor_ptr motor,
int32_t value)
Set the duty cycle set point of a motor.
int32_t ev3_get_duty_cycle_sp(ev3_motor_ptr motor)
Returns the duty cycle set point of a motor
int32_t ev3_get_speed(ev3_motor_ptr motor)
Returns the speed of a motor
ev3_motor_ptr ev3_set_speed_sp(ev3_motor_ptr motor,
int32_t value)
Set the speed set point of a motor.
int32_t ev3_get_speed_sp(ev3_motor_ptr motor)
Returns the speed set point of a motor
ev3_motor_ptr ev3_set_position(ev3_motor_ptr motor,
int32_t value)
Set the position of a motor.
int32_t ev3_get_position(ev3_motor_ptr motor)
Returns the position of a motor
ev3_motor_ptr ev3_set_position_sp(ev3_motor_ptr motor,
int32_t value)
Set the position set point of a motor.
int32_t ev3_get_position_sp(ev3_motor_ptr motor)
Returns the position set point of a motor
ev3_motor_ptr ev3_set_ramp_up_sp(ev3_motor_ptr motor,
int32_t value)
Set the ramp up set point of a motor.
int32_t ev3_get_ramp_up_sp(ev3_motor_ptr motor)
Returns the ramp up set point of a motor
ev3_motor_ptr ev3_set_ramp_down_sp(ev3_motor_ptr motor,
int32_t value)
Set the ramp down set point of a motor.
int32_t ev3_get_ramp_down_sp(ev3_motor_ptr motor)
Returns the ramp down set point of a motor
ev3_motor_ptr ev3_set_time_sp(ev3_motor_ptr motor,
int32_t value)
Set the time set point of a motor.
int32_t ev3_get_time_sp(ev3_motor_ptr motor)
Returns the time set point of a motor
ev3_motor_ptr ev3_set_polarity(ev3_motor_ptr motor,
int32_t value)
Set the polarity of a motor.
int32_t ev3_get_polarity(ev3_motor_ptr motor)
Returns the polarity of a motor
type used for all strings used from the driver lile mode names, commands and similar.
a number for supported tacho motor in ev3dev.
A struct for every loaded motor.
Close