Koala Library
|
Functions for commanding the Koala robot. More...
Go to the source code of this file.
Defines | |
#define | MAX_I2C_ADDRESS 128 |
Functions | |
int | process_param (char *source, int *destination, int nb_arg) |
int | koala_robot_init (void) |
int | koala_robot_release (void) |
int | koala_getcommand (char *command, int read_len) |
int | koala_getcommand_line (char *command) |
int | koala_getcommand_line_nowait (char *command) |
int | koala_sendcommand (char *command, int send_len) |
int | koala_configure_auto_monitoring_mode (unsigned int bit_config) |
int | koala_get_firmware_version_revision (char *version, char *revision) |
int | koala_configure_us_io (int us_mask, unsigned char io_dir) |
int | koala_set_motor_speed (int left, int right) |
int | koala_read_motor_speed (int *left, int *right) |
int | koala_set_motor_target_position (int left, int right) |
int | koala_read_us_sensors (int *values_array) |
int | koala_read_magnetometer (int *values_array) |
int | koala_configure_pid (int kp, int ki, int kd) |
int | koala_set_position_encoders (int left, int right) |
int | koala_set_speed_profile (int acc_inc, int acc_div, int min_speed, int cst_speed, int pos_margin, int max_current) |
int | koala_set_motor_speed_accel (int left, int right) |
int | koala_set_motor_speed_open_loop (int left, int right) |
int | koala_read_accelerometer (int *values_array) |
int | koala_read_gyroscope (int *values_array) |
int | koala_read_motor_current (int *left, int *right) |
int | koala_read_motor_position (int *left, int *right) |
int | koala_gps_data (char *valid_sat, int *sat_nb, double *lat_val, char *lat_car, double *long_val, char *long_car, struct tm *date_time, double *speed, int *altitude) |
int | koala_read_i2c (int i2c_add, int i2c_reg, int nb_read, int *data) |
int | koala_set_pwr_io_output (int power_out, int IO0, int IO1, int IO2, int IO3) |
int | koala_read_io (int *io_state, int *in_state) |
int | koala_read_ad (int *ad_0, int *ad_1) |
int | koala_get_battery_data (int *bat_type, int *bat_voltage, int *bat_current, int *chrg_current) |
int | koala_write_i2c (int i2c_add, int i2c_reg, int nb_data, int *data) |
int | koala_send_gps_cmd (char *gps_cmd) |
int | koala_get_motor_status (int *left_status, int *right_status, int *left_pos, int *right_pos) |
int | koala_reset_microcontroller () |
int | koala_scan_i2c (int *nb_devices, int *address) |
int | koala_get_from_auto_mode (koala_auto_data_t *data) |
Variables | |
koala_rs232_t * | koala_rs232 |
const char * | KOALA_US_SENSOR_NAMES [] = {"Left rear","Left front","Front left","Front","Front right","Right front","Right rear","Back right","Back left"} |
Functions for commanding the Koala robot.
Definition in file koala_robot.c.
#define MAX_I2C_ADDRESS 128 |
Scan I2C external bus
nb_devices | number of devices found |
address | array of address found |
Definition at line 1105 of file koala_robot.c.
Referenced by koala_scan_i2c().
int koala_configure_auto_monitoring_mode | ( | unsigned int | bit_config | ) |
Configure the auto monitoring mode. Enable a peripheral to return automatically without asking its value when refreshed.
bit_config | binary OR bit mask configuration for auto monitoring mode (default: all OFF) see koala_robot.h for constant definition of each Bit 0: US sensor Bit 1: Motor Speed Bit 2: Motor Position Bit 3: Motor Current Bit 4: Accelerometer value Bit 5: Gyroscope value Bit 6: GPS data Bit 7: GPS NEMA Data (will return all GPS raw data) Bit 8: Magnometer value |
Definition at line 232 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by braitenbergAvoidance(), and main().
int koala_configure_pid | ( | int | kp, |
int | ki, | ||
int | kd | ||
) |
Configure the PID controller value used for the speed control.
kp | P parameter |
ki | I parameter |
kd | D parameter |
Definition at line 491 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by main().
int koala_configure_us_io | ( | int | us_mask, |
unsigned char | io_dir | ||
) |
Configure the auto monitoring mode. Enable a peripheral to return automatically without asking its value when refreshed.
us_mask | binary OR bit mask configuration for use of Ultrasonic sensors (default: all active) see koala_robot.h for constant definition of each Bit 0: Left rear Bit 1: Left front Bit 2: Front left Bit 3: Front Bit 4: Front right Bit 5: Right front Bit 6: Right rear Bit 7: Back right Bit 8: Back left |
io_dir | binary OR bit mask configuration for direction of the four IO (0..3). Each IO is configure with two following bits: (IO0 = bit0 & 1, IO1 = bit2&3,…). Default: 0 = all output 00 = output 01 = input 10 = PWM servo (50Hz). see koala_robot.h for constant definition of each |
Definition at line 316 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by braitenbergAvoidance(), and main().
int koala_get_battery_data | ( | int * | bat_type, |
int * | bat_voltage, | ||
int * | bat_current, | ||
int * | chrg_current | ||
) |
Read the different values of the battery
bat_type | 0 = Li-ION, 1 = NiMH, 2 = not initialised |
bat_voltage | Voltage of the battery (unit is 0.1V) |
bat_current | Current of the battery (unit is 0.1A) |
chrg_current | Charge Current (unit is 10mA) |
Definition at line 941 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by braitenbergAvoidance(), and main().
int koala_get_firmware_version_revision | ( | char * | version, |
char * | revision | ||
) |
retrieves the current OS Firmware version/revision
version | version |
revision | revision |
Definition at line 258 of file koala_robot.c.
References koala_getcommand(), and koala_sendcommand().
Referenced by main().
int koala_get_from_auto_mode | ( | koala_auto_data_t * | data | ) |
Get values from auto mode
data | data received (see koala_robot.h for type definition) |
Definition at line 1164 of file koala_robot.c.
References auto_struct_s::accel, gps_data_s::altitude, gps_data_s::date_time, auto_struct_s::gps, auto_struct_s::gps_raw, auto_struct_s::gyro, KOALA_ACCEL_VALUES_NUMBER, koala_getcommand_line_nowait(), KOALA_GYRO_VALUES_NUMBER, KOALA_MAGNE_VALUES_NUMBER, KOALA_MAX_BUFFER, KOALA_US_SENSORS_NUMBER, gps_data_s::lat_car, gps_data_s::lat_val, auto_struct_s::left_current, auto_struct_s::left_position, auto_struct_s::left_speed, gps_data_s::long_car, gps_data_s::long_val, auto_struct_s::magne, auto_struct_s::mode, process_param(), auto_struct_s::right_current, auto_struct_s::right_position, auto_struct_s::right_speed, gps_data_s::sat_nb, gps_data_s::speed, auto_struct_s::us, and gps_data_s::valid_sat.
Referenced by braitenbergAvoidance(), and main().
int koala_get_motor_status | ( | int * | left_status, |
int * | right_status, | ||
int * | left_pos, | ||
int * | right_pos | ||
) |
Get Motor control status
Read the actual status of the motor control
left_status | left motor control status Type of actual control: 0: Idle 1: Speed 2: Speed with Acceleration 3: Position 4: Open Loop 5: Current Limitation 6: Error |
right_status | right motor control status |
left_pos | left motor: 1 if the target is reach (position control) |
right_pos | right motor: 1 if the target is reach (position control) |
Definition at line 1053 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by main().
int koala_getcommand | ( | char * | command, |
int | read_len | ||
) |
gets a command frame from the robot.
Normally an end user don't want to use these function as they are assumed as "low level functions".
read_len | is the size of the message received |
command | is a pointer to a buffer where the command frame will be stored in. |
Definition at line 145 of file koala_robot.c.
References koala_rs232_read().
Referenced by koala_get_firmware_version_revision().
int koala_getcommand_line | ( | char * | command | ) |
gets a command line from the robot.
Normally an end user don't want to use these function as they are assumed as "low level functions".
command | is a pointer to a buffer where the command frame will be stored in. |
Definition at line 168 of file koala_robot.c.
References koala_rs232_readLine().
Referenced by koala_configure_auto_monitoring_mode(), koala_configure_pid(), koala_configure_us_io(), koala_get_battery_data(), koala_get_motor_status(), koala_gps_data(), koala_read_accelerometer(), koala_read_ad(), koala_read_gyroscope(), koala_read_i2c(), koala_read_io(), koala_read_magnetometer(), koala_read_motor_current(), koala_read_motor_position(), koala_read_motor_speed(), koala_read_us_sensors(), koala_reset_microcontroller(), koala_scan_i2c(), koala_send_gps_cmd(), koala_set_motor_speed(), koala_set_motor_speed_accel(), koala_set_motor_speed_open_loop(), koala_set_motor_target_position(), koala_set_position_encoders(), koala_set_pwr_io_output(), koala_set_speed_profile(), and koala_write_i2c().
int koala_getcommand_line_nowait | ( | char * | command | ) |
Definition at line 179 of file koala_robot.c.
References koala_rs232_readLine_nowait().
Referenced by koala_get_from_auto_mode(), and main().
int koala_gps_data | ( | char * | valid_sat, |
int * | sat_nb, | ||
double * | lat_val, | ||
char * | lat_car, | ||
double * | long_val, | ||
char * | long_car, | ||
struct tm * | date_time, | ||
double * | speed, | ||
int * | altitude | ||
) |
Get GPS data
valid_sat | Valid data flag (V = Warning, A = Valid) |
sat_nb | number of satellites used |
lat_val | latitude |
lat_car | latitude N or S |
long_val | longitude |
long_car | longitude W or E |
date_time | UTC time and time of the latest fix |
speed | Speed over ground (in knots) |
altitude | Actual altitude (in meters) |
Definition at line 760 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by main().
int koala_read_accelerometer | ( | int * | values_array | ) |
Get Accelerometer value: read the last 10 value of the XYZ acceleration.
values_array | in order x0,y0,z0,x1,y1,z1,...,x9,y9,z9; new values first |
Definition at line 635 of file koala_robot.c.
References KOALA_ACCEL_VALUES_NUMBER, koala_getcommand_line(), KOALA_MAX_BUFFER, koala_sendcommand(), and process_param().
Referenced by main().
int koala_read_ad | ( | int * | ad_0, |
int * | ad_1 | ||
) |
Read the two AD input values (0-1024 => 0 - 3.3V).
ad_0 | analog input port 0 |
ad_1 | analog input port 1 |
Definition at line 910 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by main().
int koala_read_gyroscope | ( | int * | values_array | ) |
Get Gyroscope value: read the last 10 value of the XYZ.
values_array | in order x0,y0,z0,x1,y1,z1,...,x9,y9,z9; new values first |
Definition at line 664 of file koala_robot.c.
References koala_getcommand_line(), KOALA_GYRO_VALUES_NUMBER, KOALA_MAX_BUFFER, koala_sendcommand(), and process_param().
Referenced by main().
int koala_read_i2c | ( | int | i2c_add, |
int | i2c_reg, | ||
int | nb_read, | ||
int * | data | ||
) |
Read I2C external bus
i2c_add | i2c address |
i2c_reg | i2c register |
nb_read | number of bytes to read (max 128) |
data | bytes read |
Definition at line 795 of file koala_robot.c.
References KOALA_DELIM, koala_getcommand_line(), KOALA_MAX_BUFFER, KOALA_MAX_I2C_DATA, and koala_sendcommand().
Referenced by main().
int koala_read_io | ( | int * | io_state, |
int * | in_state | ||
) |
Read IO state Read the four IO and the two Input state. If the IO are define as output, will be the same value as set with S command, if define as PWM servo output, will be return as 0.
io_state | 4 IO in binary OR bit configuration (lsb=0, msb = 3) |
in_state | 2 digital input |
Definition at line 881 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by main().
int koala_read_magnetometer | ( | int * | values_array | ) |
Read the magnometer
values_array | sensors values x,y,z in [mGauss] |
Definition at line 459 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAGNE_VALUES_NUMBER, KOALA_MAX_BUFFER, koala_sendcommand(), and process_param().
Referenced by main().
int koala_read_motor_current | ( | int * | left, |
int * | right | ||
) |
Read the motor current
left | current of left motor [0.1 A] |
right | current of right motor [0.1 A] |
Definition at line 693 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by main().
int koala_read_motor_position | ( | int * | left, |
int * | right | ||
) |
Read the motor position [pulse]
left | encoder value of left motor |
right | encoder value of right motor |
Definition at line 722 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by braitenbergAvoidance(), and main().
int koala_read_motor_speed | ( | int * | left, |
int * | right | ||
) |
Read the motor actual speed [pulses / KOALA_TIME_BTWN ms].
left | left speed |
right | right speed |
Definition at line 369 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by drive_robot(), and main().
int koala_read_us_sensors | ( | int * | values_array | ) |
Read the ultrasonic sensors
values_array | sensors values array 0: Obstacle <25cm 25-250: Obstacle distance in cm 1000: No obstacle detected 2000: Sensor disable |
Definition at line 427 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, koala_sendcommand(), KOALA_US_SENSORS_NUMBER, and process_param().
Referenced by main().
int koala_reset_microcontroller | ( | ) |
Reset microcontroller
Definition at line 1081 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by main().
int koala_robot_init | ( | void | ) |
initializes. This function needs to be called BEFORE any other functions. But default it is already called inside koala_init!
(none) |
Definition at line 98 of file koala_robot.c.
References koala_rs232_open(), KOALA_SERIAL_PORT_BAUDRATE, and KOALA_SERIAL_PORT_NAME.
Referenced by koala_init().
int koala_robot_release | ( | void | ) |
release the robot. This function needs to be called AFTER any other functions.
(none) |
Definition at line 124 of file koala_robot.c.
References koala_rs232_close().
Referenced by koala_exit().
int koala_scan_i2c | ( | int * | nb_devices, |
int * | address | ||
) |
Definition at line 1106 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, koala_sendcommand(), and MAX_I2C_ADDRESS.
Referenced by main().
int koala_send_gps_cmd | ( | char * | gps_cmd | ) |
Send GPS command
gps_cmd | gps command |
Definition at line 1012 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by main().
int koala_sendcommand | ( | char * | command, |
int | send_len | ||
) |
send a command frame from the robot.
Normally an end user don't want to use these function as they are assumed as "low level functions".
send_len | is the size of the message received |
command | is a pointer to a buffer where the command frame to send |
Definition at line 204 of file koala_robot.c.
References koala_rs232_write().
Referenced by koala_configure_auto_monitoring_mode(), koala_configure_pid(), koala_configure_us_io(), koala_get_battery_data(), koala_get_firmware_version_revision(), koala_get_motor_status(), koala_gps_data(), koala_read_accelerometer(), koala_read_ad(), koala_read_gyroscope(), koala_read_i2c(), koala_read_io(), koala_read_magnetometer(), koala_read_motor_current(), koala_read_motor_position(), koala_read_motor_speed(), koala_read_us_sensors(), koala_reset_microcontroller(), koala_scan_i2c(), koala_send_gps_cmd(), koala_set_motor_speed(), koala_set_motor_speed_accel(), koala_set_motor_speed_open_loop(), koala_set_motor_target_position(), koala_set_position_encoders(), koala_set_pwr_io_output(), koala_set_speed_profile(), and koala_write_i2c().
int koala_set_motor_speed | ( | int | left, |
int | right | ||
) |
Set the motor speed [pulses / KOALA_TIME_BTWN ms]. The PID controller will manage the speed in closed loop.
left | left speed |
right | right speed |
Definition at line 343 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by braitenbergAvoidance(), drive_robot(), and main().
int koala_set_motor_speed_accel | ( | int | left, |
int | right | ||
) |
Set Motor Speed with acceleration ramp [pulses / KOALA_TIME_BTWN ms].
Set a speed order to reach with acceleration ramp. The parameters used for this mode are the same as the position control.
left | left speed |
right | right speed |
Definition at line 582 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by braitenbergAvoidance(), drive_robot(), and main().
int koala_set_motor_speed_open_loop | ( | int | left, |
int | right | ||
) |
Set speed in open loop control.
Set a PWM value for each motor. Value can be from -2000 to +2000 (corresponding to -100 to 100% of PWM).
left | left pwm |
right | right pwm |
Definition at line 610 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by ctrlc_handler(), and main().
int koala_set_motor_target_position | ( | int | left, |
int | right | ||
) |
Set the motor target position [pulses].
left | left target position |
right | right target position |
Definition at line 398 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by main().
int koala_set_position_encoders | ( | int | left, |
int | right | ||
) |
Set the position encoder value [pulses].
Reset the position encoder value of the motor. If set during a position control move, the motors will be stopped to avoid an incorrect behaviour.
left | left encoder position |
right | right encoder position |
Definition at line 521 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by main().
int koala_set_pwr_io_output | ( | int | power_out, |
int | IO0, | ||
int | IO1, | ||
int | IO2, | ||
int | IO3 | ||
) |
Set the PWR and IO output value Set the state of the four PWR output and four IO (if set as output, 0 = GND, 1 = +3.3V, if set as PWM servo, define the position of the servo for 0 to 250 ).
power_out | power output binary OR bit mask configuration see koala_robot.h for constant definition of each bit |
IO0 | IO 0 |
IO1 | IO 1 |
IO2 | IO 2 |
IO3 | IO 4 |
Definition at line 851 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by main().
int koala_set_speed_profile | ( | int | acc_inc, |
int | acc_div, | ||
int | min_speed, | ||
int | cst_speed, | ||
int | pos_margin, | ||
int | max_current | ||
) |
Configure the parameters used for the position control.
acc_inc | Increment of the speed added every “Acc_Div+1” control loop. |
acc_div | Number of control loop before adding the Acc_Inc to the speed order |
min_speed | Minimum speed order used during the position control |
cst_speed | Constant speed used during the position control after acceleration |
pos_margin | Margin of the position control to detect when the robot reach its target. |
max_current | Maximum current for each motor. If above this value, the controller will limit the motor command. (unit is mA, 0 = disable (default)). |
Definition at line 553 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by main().
int koala_write_i2c | ( | int | i2c_add, |
int | i2c_reg, | ||
int | nb_data, | ||
int * | data | ||
) |
Write on the I2C external bus
i2c_add | i2c address |
i2c_reg | i2c register |
nb_data | number of data to send |
data | bytes to be written |
Definition at line 973 of file koala_robot.c.
References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().
Referenced by main().
int process_param | ( | char * | source, |
int * | destination, | ||
int | nb_arg | ||
) |
process integer parameters from a string into a integer array
source | array of char containing input parameters sperated by DELIM |
destination | array of integer containing parameters |
nb_arg | number of parameters found |
Definition at line 61 of file koala_robot.c.
References KOALA_DELIM.
Referenced by koala_get_from_auto_mode(), koala_read_accelerometer(), koala_read_gyroscope(), koala_read_magnetometer(), and koala_read_us_sensors().
Definition at line 45 of file koala_robot.c.
const char* KOALA_US_SENSOR_NAMES[] = {"Left rear","Left front","Front left","Front","Front right","Right front","Right rear","Back right","Back left"} |
Definition at line 85 of file koala_robot.c.
Referenced by main().