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

Definitions of API for controlling sensors. More...

Data Structures

struct  rgb_raw_t
 Structure for an RGB raw value. More...
 
struct  ir_seek_t
 Structure for IR Seek values for all 4 channels. More...
 
struct  ir_remote_t
 

Macros

#define IR_RED_UP_BUTTON   1
 
#define IR_RED_DOWN_BUTTON   2
 
#define IR_BLUE_UP_BUTTON   4
 
#define IR_BLUE_DOWN_BUTTON   8
 
#define IR_BEACON_BUTTON   16
 

Enumerations

enum  sensor_port_t {
  EV3_PORT_1 = 0,
  EV3_PORT_2 = 1,
  EV3_PORT_3 = 2,
  EV3_PORT_4 = 3,
  TNUM_SENSOR_PORT = 4
}
 Enumeration type for supported sensor ports. More...
 
enum  sensor_type_t {
  NONE_SENSOR = 0,
  ULTRASONIC_SENSOR,
  GYRO_SENSOR,
  TOUCH_SENSOR,
  COLOR_SENSOR,
  INFRARED_SENSOR,
  HT_NXT_ACCEL_SENSOR,
  NXT_TEMP_SENSOR,
  TNUM_SENSOR_TYPE
}
 Enumeration type for supported sensor types. More...
 
enum  colorid_t {
  COLOR_NONE = 0,
  COLOR_BLACK = 1,
  COLOR_BLUE = 2,
  COLOR_GREEN = 3,
  COLOR_YELLOW = 4,
  COLOR_RED = 5,
  COLOR_WHITE = 6,
  COLOR_BROWN = 7,
  TNUM_COLOR
}
 Enumeration type for colors that can be detected by color sensor. More...
 

Functions

ER ev3_sensor_config (sensor_port_t port, sensor_type_t type)
 Configure a sensor port. More...
 
ER_UINT ev3_sensor_get_type (sensor_port_t port)
 Get the type of a sensor port. More...
 
colorid_t ev3_color_sensor_get_color (sensor_port_t port)
 Get the color by a color sensor. More...
 
uint8_t ev3_color_sensor_get_reflect (sensor_port_t port)
 Get the reflect light intensity by a color sensor. More...
 
uint8_t ev3_color_sensor_get_ambient (sensor_port_t port)
 Get the ambient light intensity by a color sensor. More...
 
void ev3_color_sensor_get_rgb_raw (sensor_port_t port, rgb_raw_t *val)
 Get the RGB raw value by a color sensor. More...
 
int16_t ev3_gyro_sensor_get_angle (sensor_port_t port)
 Get the angular position by a gyroscope sensor. More...
 
int16_t ev3_gyro_sensor_get_rate (sensor_port_t port)
 Get the angular speed by a gyroscope sensor. More...
 
ER ev3_gyro_sensor_reset (sensor_port_t port)
 Reset the angular position of a gyroscope sensor to zero. More...
 
int16_t ev3_ultrasonic_sensor_get_distance (sensor_port_t port)
 Get the distance by a ultrasonic sensor. More...
 
bool_t ev3_ultrasonic_sensor_listen (sensor_port_t port)
 Get a ultrasonic signal by a ultrasonic sensor. More...
 
int8_t ev3_infrared_sensor_get_distance (sensor_port_t port)
 Get the distance using the infrared sensor. More...
 
ir_seek_t ev3_infrared_sensor_seek (sensor_port_t port)
 Gets values to seek a remote controller in beacon mode. More...
 
ir_remote_t ev3_infrared_sensor_get_remote (sensor_port_t port)
 Gets commands from IR remote controllers. More...
 
bool_t ev3_touch_sensor_is_pressed (sensor_port_t port)
 Get the status of a touch sensor. More...
 
bool_t ht_nxt_accel_sensor_measure (sensor_port_t port, int16_t axes[3])
 Measure acceleration with a HiTechnic NXT acceleration sensor. More...
 
bool_t nxt_temp_sensor_measure (sensor_port_t port, float *temp)
 Measure temperature with a NXT temperature sensor (9749). More...
 

Detailed Description

Definitions of API for controlling sensors.

Enumeration Type Documentation

enum colorid_t

Enumeration type for colors that can be detected by color sensor.

Enumerator
COLOR_NONE 

None.

COLOR_BLACK 

Black.

COLOR_BLUE 

Blue.

COLOR_GREEN 

Green.

COLOR_YELLOW 

Yellow.

COLOR_RED 

Red.

COLOR_WHITE 

White.

COLOR_BROWN 

Brown.

TNUM_COLOR 

Number of colors.

Enumeration type for supported sensor ports.

Enumerator
EV3_PORT_1 

Port 1.

EV3_PORT_2 

Port 2.

EV3_PORT_3 

Port 3.

EV3_PORT_4 

Port 4.

TNUM_SENSOR_PORT 

Number of sensor ports.

Enumeration type for supported sensor types.

Enumerator
NONE_SENSOR 

Not connected.

ULTRASONIC_SENSOR 

Ultrasonic sensor.

GYRO_SENSOR 

Gyroscope sensor.

TOUCH_SENSOR 

Touch sensor.

COLOR_SENSOR 

Color sensor.

INFRARED_SENSOR 

Infra-Red sensor.

HT_NXT_ACCEL_SENSOR 

HiTechnic NXT acceleration sensor.

NXT_TEMP_SENSOR 

NXT temperature sensor.

TNUM_SENSOR_TYPE 

Number of sensor types.

Function Documentation

uint8_t ev3_color_sensor_get_ambient ( sensor_port_t  port)

Get the ambient light intensity by a color sensor.

Always returns 0 (error log is outputted) when an invalid sensor number is specified.

Parameters
portSensor port to be inquired
Returns
Ambient light intensity, ranging from 0 to 100
colorid_t ev3_color_sensor_get_color ( sensor_port_t  port)

Get the color by a color sensor.

Always return COLOR_NONE (error is outputted) when an incorrect sensor number is specified.

Parameters
portSensor port to be inquired
Returns
Color detected
uint8_t ev3_color_sensor_get_reflect ( sensor_port_t  port)

Get the reflect light intensity by a color sensor.

Always returns 0 (error log is outputted) when an invalid sensor number is specified.

Parameters
portSensor port to be inquired
Returns
Reflect light intensity, ranging from 0 to 100
void ev3_color_sensor_get_rgb_raw ( sensor_port_t  port,
rgb_raw_t val 
)

Get the RGB raw value by a color sensor.

If an invalid sensor number is specified, val is not updated (error log is output).

Parameters
portSensor port to be inquired
valPointer for storing sensor value
int16_t ev3_gyro_sensor_get_angle ( sensor_port_t  port)

Get the angular position by a gyroscope sensor.

Always returns 0 (error log is outputted) when an invalid sensor number is specified.

Parameters
portSensor port to be inquired
Returns
Angular position in degrees
int16_t ev3_gyro_sensor_get_rate ( sensor_port_t  port)

Get the angular speed by a gyroscope sensor.

Always returns 0 (error log is outputted) when an invalid sensor number is specified.

Parameters
portSensor port to be inquired
Returns
Angular speed in degrees/second.
ER ev3_gyro_sensor_reset ( sensor_port_t  port)

Reset the angular position of a gyroscope sensor to zero.

Parameters
portSensor port to be reset
Return values
E_OKSuccessful completion
E_IDIllegal sensor port number
int8_t ev3_infrared_sensor_get_distance ( sensor_port_t  port)

Get the distance using the infrared sensor.

Always returns 0 (error log is outputted) when an invalid sensor number is specified.

Parameters
portSensor port to be inquired.
Returns
Distance in percentage (0-100).
ir_remote_t ev3_infrared_sensor_get_remote ( sensor_port_t  port)

Gets commands from IR remote controllers.

When an invalid sensor support number is specified, always return 0 pattern (error log is output).

Parameters
portSensor port to be inquired.
Returns
Struct with details of the IR remote buttons pressed.
ir_seek_t ev3_infrared_sensor_seek ( sensor_port_t  port)

Gets values to seek a remote controller in beacon mode.

When an invalid sensor support number is specified, always return 0 direction and distance of -128 (error log is output).

Parameters
portSensor port to be inquired.
Returns
Struct with heading/distance for all (4) channels.
ER ev3_sensor_config ( sensor_port_t  port,
sensor_type_t  type 
)

Configure a sensor port.

Always returns 0 when an invalid sensor number is specified.

Parameters
portSensor port to be configured
typeSensor type for the specified sensor port
Return values
E_OKSuccessful completion
E_IDIllegal sensor port number
E_PARIllegal sensor type
ER_UINT ev3_sensor_get_type ( sensor_port_t  port)

Get the type of a sensor port.

Parameters
portSensor port to be inquired
Return values
>=0Specified sensor type of supported sensor
E_IDIncorrect sensor port number
bool_t ev3_touch_sensor_is_pressed ( sensor_port_t  port)

Get the status of a touch sensor.

When an invalid sensor support number is specified, always returns false (error log is output)

Parameters
portSensor port to be inquired
Return values
truePressed pressed
falseUnpressed pressed
int16_t ev3_ultrasonic_sensor_get_distance ( sensor_port_t  port)

Get the distance by a ultrasonic sensor.

Always returns 0 (error log is outputted) when an invalid sensor number is specified.

Parameters
portSensor port to be inquired
Returns
Distance in centimeters.
bool_t ev3_ultrasonic_sensor_listen ( sensor_port_t  port)

Get a ultrasonic signal by a ultrasonic sensor.

When an invalid sensor support number is specified, always returns false (error log is output).

Parameters
portSensor port to be inquired
Return values
trueA signal has been received
falseNo signal has been received
bool_t ht_nxt_accel_sensor_measure ( sensor_port_t  port,
int16_t  axes[3] 
)

Measure acceleration with a HiTechnic NXT acceleration sensor.

When an invalid sensor support number is specified, always returns false (error log is output)

Parameters
portSensor port to be inquired
axesArray to store the x/y/z axes data
Return values
trueAxes [] is updated
falseAxes[] is unchanged due to I2C busy
bool_t nxt_temp_sensor_measure ( sensor_port_t  port,
float *  temp 
)

Measure temperature with a NXT temperature sensor (9749).

When an invalid sensor support number is specified, always returns false (error log is output)

Parameters
portSensor port to be inquired
tempVariable to store the temperature value
Return values
trueTemp is updated)
falseTemp is unchanged due to I2C busy