Koala Library
koala_robot.c File Reference

Functions for commanding the Koala robot. More...

Include dependency graph for koala_robot.c:

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_tkoala_rs232
const char * KOALA_US_SENSOR_NAMES [] = {"Left rear","Left front","Front left","Front","Front right","Right front","Right rear","Back right","Back left"}

Detailed Description

Functions for commanding the Koala robot.

Definition in file koala_robot.c.


Define Documentation

#define MAX_I2C_ADDRESS   128

Scan I2C external bus

Parameters:
nb_devicesnumber of devices found
addressarray of address found
Returns:
- >=0 OK
  • <0 error

Definition at line 1105 of file koala_robot.c.

Referenced by koala_scan_i2c().


Function Documentation

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.

Parameters:
bit_configbinary 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
Returns:
- >=0 OK
  • <0 error

Definition at line 232 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by braitenbergAvoidance(), and main().

Here is the call graph for this function:

int koala_configure_pid ( int  kp,
int  ki,
int  kd 
)

Configure the PID controller value used for the speed control.

Parameters:
kpP parameter
kiI parameter
kdD parameter
Returns:
- >=0 OK
  • <0 error

Definition at line 491 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by main().

Here is the call graph for this function:

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.

Parameters:
us_maskbinary 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_dirbinary 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
Returns:
- >=0 OK
  • <0 error

Definition at line 316 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by braitenbergAvoidance(), and main().

Here is the call graph for this function:

int koala_get_battery_data ( int *  bat_type,
int *  bat_voltage,
int *  bat_current,
int *  chrg_current 
)

Read the different values of the battery

Parameters:
bat_type0 = Li-ION, 1 = NiMH, 2 = not initialised
bat_voltageVoltage of the battery (unit is 0.1V)
bat_currentCurrent of the battery (unit is 0.1A)
chrg_currentCharge Current (unit is 10mA)
Returns:
- >=0 OK
  • <0 error

Definition at line 941 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by braitenbergAvoidance(), and main().

Here is the call graph for this function:

int koala_get_firmware_version_revision ( char *  version,
char *  revision 
)

retrieves the current OS Firmware version/revision

Parameters:
versionversion
revisionrevision
Returns:
- >=0 OK
  • - <0 error

Definition at line 258 of file koala_robot.c.

References koala_getcommand(), and koala_sendcommand().

Referenced by main().

Here is the call graph for this function:

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

Parameters:
left_statusleft 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_statusright motor control status
left_posleft motor: 1 if the target is reach (position control)
right_posright motor: 1 if the target is reach (position control)
Returns:
- >=0 OK
  • <0 error

Definition at line 1053 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by main().

Here is the call graph for this function:

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".

Parameters:
read_lenis the size of the message received
commandis a pointer to a buffer where the command frame will be stored in.
Returns:
an error code:
  • <0 standard error code. See errno.h
  • >=0 on success

Definition at line 145 of file koala_robot.c.

References koala_rs232_read().

Referenced by koala_get_firmware_version_revision().

Here is the call graph for this function:

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".

Parameters:
commandis a pointer to a buffer where the command frame will be stored in.
Returns:
an error code:
  • <0 standard error code. See errno.h
  • >=0 on success

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().

Here is the call graph for this function:

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().

Here is the call graph for this function:

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

Parameters:
valid_satValid data flag (V = Warning, A = Valid)
sat_nbnumber of satellites used
lat_vallatitude
lat_carlatitude N or S
long_vallongitude
long_carlongitude W or E
date_timeUTC time and time of the latest fix
speedSpeed over ground (in knots)
altitudeActual altitude (in meters)
Returns:
- >=0 OK
  • <0 error

Definition at line 760 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by main().

Here is the call graph for this function:

int koala_read_accelerometer ( int *  values_array)

Get Accelerometer value: read the last 10 value of the XYZ acceleration.

Parameters:
values_arrayin order x0,y0,z0,x1,y1,z1,...,x9,y9,z9; new values first
Returns:
- >=0 OK
  • <0 error

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().

Here is the call graph for this function:

int koala_read_ad ( int *  ad_0,
int *  ad_1 
)

Read the two AD input values (0-1024 => 0 - 3.3V).

Parameters:
ad_0analog input port 0
ad_1analog input port 1
Returns:
- >=0 OK
  • <0 error

Definition at line 910 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by main().

Here is the call graph for this function:

int koala_read_gyroscope ( int *  values_array)

Get Gyroscope value: read the last 10 value of the XYZ.

Parameters:
values_arrayin order x0,y0,z0,x1,y1,z1,...,x9,y9,z9; new values first
Returns:
- >=0 OK
  • <0 error

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().

Here is the call graph for this function:

int koala_read_i2c ( int  i2c_add,
int  i2c_reg,
int  nb_read,
int *  data 
)

Read I2C external bus

Parameters:
i2c_addi2c address
i2c_regi2c register
nb_readnumber of bytes to read (max 128)
databytes read
Returns:
- >=0 OK
  • <0 error

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().

Here is the call graph for this function:

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.

Parameters:
io_state4 IO in binary OR bit configuration (lsb=0, msb = 3)
in_state2 digital input
Returns:
- >=0 OK
  • <0 error

Definition at line 881 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by main().

Here is the call graph for this function:

int koala_read_magnetometer ( int *  values_array)

Read the magnometer

Parameters:
values_arraysensors values x,y,z in [mGauss]
Returns:
- >=0 OK
  • <0 error

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().

Here is the call graph for this function:

int koala_read_motor_current ( int *  left,
int *  right 
)

Read the motor current

Parameters:
leftcurrent of left motor [0.1 A]
rightcurrent of right motor [0.1 A]
Returns:
- >=0 OK
  • <0 error

Definition at line 693 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by main().

Here is the call graph for this function:

int koala_read_motor_position ( int *  left,
int *  right 
)

Read the motor position [pulse]

Parameters:
leftencoder value of left motor
rightencoder value of right motor
Returns:
- >=0 OK
  • <0 error

Definition at line 722 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by braitenbergAvoidance(), and main().

Here is the call graph for this function:

int koala_read_motor_speed ( int *  left,
int *  right 
)

Read the motor actual speed [pulses / KOALA_TIME_BTWN ms].

Parameters:
leftleft speed
rightright speed
Returns:
- >=0 OK
  • <0 error

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().

Here is the call graph for this function:

int koala_read_us_sensors ( int *  values_array)

Read the ultrasonic sensors

Parameters:
values_arraysensors values array 0: Obstacle <25cm 25-250: Obstacle distance in cm 1000: No obstacle detected 2000: Sensor disable
Returns:
- >=0 OK
  • <0 error

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().

Here is the call graph for this function:

Reset microcontroller

Returns:
- >=0 OK
  • <0 error

Definition at line 1081 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by main().

Here is the call graph for this function:

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!

Parameters:
(none)
Returns:
A value:
  • <0 on error
  • 0 on success

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().

Here is the call graph for this function:

int koala_robot_release ( void  )

release the robot. This function needs to be called AFTER any other functions.

Parameters:
(none)
Returns:
A value:
  • <0 on error
  • 0 on success

Definition at line 124 of file koala_robot.c.

References koala_rs232_close().

Referenced by koala_exit().

Here is the call graph for this function:

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().

Here is the call graph for this function:

int koala_send_gps_cmd ( char *  gps_cmd)

Send GPS command

Parameters:
gps_cmdgps command
Returns:
- >=0 OK
  • <0 error

Definition at line 1012 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by main().

Here is the call graph for this function:

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".

Parameters:
send_lenis the size of the message received
commandis a pointer to a buffer where the command frame to send
Returns:
an error code:
  • <0 standard error code. See errno.h
  • >=0 on success

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().

Here is the call graph for this function:

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.

Parameters:
leftleft speed
rightright speed
Returns:
- >=0 OK
  • <0 error

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().

Here is the call graph for this function:

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.

Parameters:
leftleft speed
rightright speed
Returns:
- >=0 OK
  • <0 error

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().

Here is the call graph for this function:

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).

Parameters:
leftleft pwm
rightright pwm
Returns:
- >=0 OK
  • <0 error

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().

Here is the call graph for this function:

int koala_set_motor_target_position ( int  left,
int  right 
)

Set the motor target position [pulses].

Parameters:
leftleft target position
rightright target position
Returns:
- >=0 OK
  • <0 error

Definition at line 398 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by main().

Here is the call graph for this function:

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.

Parameters:
leftleft encoder position
rightright encoder position
Returns:
- >=0 OK
  • <0 error

Definition at line 521 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by main().

Here is the call graph for this function:

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 ).

Parameters:
power_outpower output binary OR bit mask configuration see koala_robot.h for constant definition of each bit
IO0IO 0
IO1IO 1
IO2IO 2
IO3IO 4
Returns:
- >=0 OK
  • <0 error

Definition at line 851 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by main().

Here is the call graph for this function:

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.

Parameters:
acc_incIncrement of the speed added every “Acc_Div+1” control loop.
acc_divNumber of control loop before adding the Acc_Inc to the speed order
min_speedMinimum speed order used during the position control
cst_speedConstant speed used during the position control after acceleration
pos_marginMargin of the position control to detect when the robot reach its target.
max_currentMaximum current for each motor. If above this value, the controller will limit the motor command. (unit is mA, 0 = disable (default)).
Returns:
- >=0 OK
  • <0 error

Definition at line 553 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by main().

Here is the call graph for this function:

int koala_write_i2c ( int  i2c_add,
int  i2c_reg,
int  nb_data,
int *  data 
)

Write on the I2C external bus

Parameters:
i2c_addi2c address
i2c_regi2c register
nb_datanumber of data to send
databytes to be written
Returns:
- >=0 OK
  • <0 error

Definition at line 973 of file koala_robot.c.

References koala_getcommand_line(), KOALA_MAX_BUFFER, and koala_sendcommand().

Referenced by main().

Here is the call graph for this function:

int process_param ( char *  source,
int *  destination,
int  nb_arg 
)

process integer parameters from a string into a integer array

Parameters:
sourcearray of char containing input parameters sperated by DELIM
destinationarray of integer containing parameters
nb_argnumber of parameters found
Returns:
A value:
  • <0 on error
  • 0 on success

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().


Variable Documentation

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().