Pogosim
Loading...
Searching...
No Matches
spogobot.cpp File Reference
#include <iostream>
#include <thread>
#include <chrono>
#include <cstdarg>
#include <sstream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdint>
#include "SDL2_gfxPrimitives.h"
#include "spogobot.h"
#include "robot.h"
#include "pogosim.h"
#include "simulator.h"
#include "version.h"

Functions

uint64_t get_current_time_microseconds ()
 Retrieves the current time in microseconds.
std::string log_current_robot ()
 Returns a log string for the current robot.
void pogobot_init ()
void pogobot_infrared_ll_init (void)
void pogobot_infrared_update (void)
int pogobot_infrared_message_available (void)
void pogobot_infrared_recover_next_message (message_t *mes)
void pogobot_infrared_clear_message_queue (void)
void pogobot_infrared_set_power (uint8_t power)
uint32_t pogobot_infrared_sendRawLongMessage (message_t *const message)
uint32_t pogobot_infrared_sendRawShortMessage (ir_direction dir, short_message_t *const message)
uint32_t pogobot_infrared_sendLongMessage_uniSpe (ir_direction dir, uint8_t *message, uint16_t message_size)
uint32_t pogobot_infrared_sendLongMessage_omniGen (uint8_t *message, uint16_t message_size)
uint32_t pogobot_infrared_sendLongMessage_omniSpe (uint8_t *message, uint16_t message_size)
uint32_t pogobot_infrared_sendShortMessage_uni (ir_direction dir, uint8_t *message, uint16_t message_size)
uint32_t pogobot_infrared_sendShortMessage_omni (uint8_t *message, uint16_t message_size)
void pogobot_infrared_get_receiver_error_counter (slip_error_counter_s *error_counter, uint8_t ir_index)
void pogobot_infrared_reset_receiver_error_counter (void)
void pogobot_led_setColor (const uint8_t r, const uint8_t g, const uint8_t b)
void pogobot_led_setColors (const uint8_t r, const uint8_t g, const uint8_t b, uint8_t id)
int16_t pogobot_photosensors_read (uint8_t sensor_number)
void pogobot_imu_read (float *acc, float *gyro)
float pogobot_imu_readTemp (void)
int16_t pogobot_battery_voltage_read (void)
void pogobot_motor_power_set (motor_id motor, uint16_t value)
void pogobot_motor_set (motor_id motor, uint16_t value)
uint32_t pogobot_motor_dir_current_status (void)
int8_t pogobot_motor_dir_mem_get (uint8_t *p_directions)
int8_t pogobot_motor_dir_mem_set (uint8_t *p_directions)
void pogobot_motor_dir_set (motor_id motor, uint8_t value)
uint8_t pogobot_motor_power_mem_get (uint16_t *p_powers)
uint8_t pogobot_motor_power_mem_set (uint16_t *p_powers)
uint16_t pogobot_helper_getid (void)
int16_t pogobot_helper_getRandSeed (void)
void pogobot_helper_print_version (void)
void pli_timer_sleep_stopwatch_init (void)
void pogobot_stopwatch_reset (time_reference_t *stopwatch)
int32_t pogobot_stopwatch_lap (time_reference_t *stopwatch)
int32_t pogobot_stopwatch_get_elapsed_microseconds (time_reference_t *stopwatch)
void pogobot_stopwatch_offset_origin_microseconds (time_reference_t *stopwatch, int32_t microseconds_offset)
void pogobot_timer_init (time_reference_t *timer, int32_t microseconds_to_go)
int32_t pogobot_timer_get_remaining_microseconds (time_reference_t *timer)
bool pogobot_timer_has_expired (time_reference_t *timer)
void pogobot_timer_wait_for_expiry (time_reference_t *timer)
void pogobot_timer_offset_origin_microseconds (time_reference_t *timer, int32_t microseconds_offset)
void msleep (int milliseconds)
std::string _format_args_to_string (const char *format, va_list args)
void pogosim_printf (const char *format,...)
int pogosim_putchar (int ch)
uint32_t get_nb_robots (void)
void stop_simulation (void)
void enable_data_export (void)
void disable_data_export (void)
void data_add_column_int8 (char const *name)
void data_add_column_int16 (char const *name)
void data_add_column_int32 (char const *name)
void data_add_column_int64 (char const *name)
void data_add_column_double (char const *name)
void data_add_column_string (char const *name)
void data_add_column_bool (char const *name)
void data_add_column_float16 (char const *name)
void data_set_value_int8 (char const *name, int8_t value)
void data_set_value_int16 (char const *name, int16_t value)
void data_set_value_int32 (char const *name, int32_t value)
void data_set_value_int64 (char const *name, int64_t value)
void data_set_value_double (char const *name, double value)
void data_set_value_string (char const *name, char const *value)
void data_set_value_bool (char const *name, bool value)
void data_set_value_float16 (char const *name, float value)
void init_bool_from_configuration (bool *var, char const *name, bool const default_value)
void init_double_from_configuration (double *var, char const *name, double const default_value)
void init_float_from_configuration (float *var, char const *name, float const default_value)
void init_int32_from_configuration (int32_t *var, char const *name, int32_t const default_value)
void init_uint32_from_configuration (uint32_t *var, char const *name, uint32_t const default_value)
void init_int16_from_configuration (int16_t *var, char const *name, int16_t const default_value)
void init_uint16_from_configuration (uint16_t *var, char const *name, uint16_t const default_value)
void init_int8_from_configuration (int8_t *var, char const *name, int8_t const default_value)
void init_uint8_from_configuration (uint8_t *var, char const *name, uint8_t const default_value)
void init_string_from_configuration (char *var, char const *name, std::size_t size)
void init_float_array_from_configuration (float *var, char const *name, size_t const size)
void init_double_array_from_configuration (double *var, char const *name, size_t const size)

Variables

uint8_t const _selected_power = 1
slip_error_counter_s _slip_error_counter = {0, 0, 0}

Function Documentation

◆ _format_args_to_string()

std::string _format_args_to_string ( const char * format,
va_list args )

◆ data_add_column_bool()

void data_add_column_bool ( char const * name)

◆ data_add_column_double()

void data_add_column_double ( char const * name)

◆ data_add_column_float16()

void data_add_column_float16 ( char const * name)

◆ data_add_column_int16()

void data_add_column_int16 ( char const * name)

◆ data_add_column_int32()

void data_add_column_int32 ( char const * name)

◆ data_add_column_int64()

void data_add_column_int64 ( char const * name)

◆ data_add_column_int8()

void data_add_column_int8 ( char const * name)

◆ data_add_column_string()

void data_add_column_string ( char const * name)

◆ data_set_value_bool()

void data_set_value_bool ( char const * name,
bool value )

◆ data_set_value_double()

void data_set_value_double ( char const * name,
double value )

◆ data_set_value_float16()

void data_set_value_float16 ( char const * name,
float value )

◆ data_set_value_int16()

void data_set_value_int16 ( char const * name,
int16_t value )

◆ data_set_value_int32()

void data_set_value_int32 ( char const * name,
int32_t value )

◆ data_set_value_int64()

void data_set_value_int64 ( char const * name,
int64_t value )

◆ data_set_value_int8()

void data_set_value_int8 ( char const * name,
int8_t value )

◆ data_set_value_string()

void data_set_value_string ( char const * name,
char const * value )

◆ disable_data_export()

void disable_data_export ( void )

◆ enable_data_export()

void enable_data_export ( void )

◆ get_current_time_microseconds()

uint64_t get_current_time_microseconds ( )

Retrieves the current time in microseconds.

Computes and returns the current simulation time in microseconds.

Returns
uint64_t Current time in microseconds.

◆ get_nb_robots()

uint32_t get_nb_robots ( void )

(get_nb_robots) Returns the number of robots in the simulation

Return

the number of robots in the simulation

◆ init_bool_from_configuration()

void init_bool_from_configuration ( bool * var,
char const * name,
bool const default_value )

◆ init_double_array_from_configuration()

void init_double_array_from_configuration ( double * var,
char const * name,
size_t const size )

◆ init_double_from_configuration()

void init_double_from_configuration ( double * var,
char const * name,
double const default_value )

◆ init_float_array_from_configuration()

void init_float_array_from_configuration ( float * var,
char const * name,
size_t const size )

◆ init_float_from_configuration()

void init_float_from_configuration ( float * var,
char const * name,
float const default_value )

◆ init_int16_from_configuration()

void init_int16_from_configuration ( int16_t * var,
char const * name,
int16_t const default_value )

◆ init_int32_from_configuration()

void init_int32_from_configuration ( int32_t * var,
char const * name,
int32_t const default_value )

◆ init_int8_from_configuration()

void init_int8_from_configuration ( int8_t * var,
char const * name,
int8_t const default_value )

◆ init_string_from_configuration()

void init_string_from_configuration ( char * var,
char const * name,
std::size_t size )

Initialise a fixed-size C string from the configuration.

Parameters
varDestination buffer supplied by the caller.
nameParameter name (same token the macro turns into a string).
sizeCapacity of var in bytes (including the final '\0').

The current contents of var are treated as the default value, so callers can write char run_law[128] = "levy"; and get an automatic fallback when the key is absent or invalid.

The result is always NUL-terminated, even when the configured value is longer than the buffer.

◆ init_uint16_from_configuration()

void init_uint16_from_configuration ( uint16_t * var,
char const * name,
uint16_t const default_value )

◆ init_uint32_from_configuration()

void init_uint32_from_configuration ( uint32_t * var,
char const * name,
uint32_t const default_value )

◆ init_uint8_from_configuration()

void init_uint8_from_configuration ( uint8_t * var,
char const * name,
uint8_t const default_value )

◆ log_current_robot()

std::string log_current_robot ( )

Returns a log string for the current robot.

This function gathers and returns a string containing relevant log information for the currently active robot.

Returns
std::string A string representing the current robot's log.

◆ msleep()

void msleep ( int milliseconds)

◆ pli_timer_sleep_stopwatch_init()

void pli_timer_sleep_stopwatch_init ( void )

Time API

◆ pogobot_battery_voltage_read()

int16_t pogobot_battery_voltage_read ( void )

Battery API

◆ pogobot_helper_getid()

uint16_t pogobot_helper_getid ( void )

Helper API

◆ pogobot_helper_getRandSeed()

int16_t pogobot_helper_getRandSeed ( void )

(pogobot_helper_getRandSeed) gives an seed base on the ADC read of the battery

Parameters

  • none

Return

Returns an random id on 16bits

◆ pogobot_helper_print_version()

void pogobot_helper_print_version ( void )

(pogobot_helper_print_version) print the version inside the prompt It is also possible to use the define RELEASE_VERSION in release.h

Parameters

  • none

Return

  • none

◆ pogobot_imu_read()

void pogobot_imu_read ( float * acc,
float * gyro )

IMU API

◆ pogobot_imu_readTemp()

float pogobot_imu_readTemp ( void )

(pogobot_imu_readTemp) Read the temparature sensor on the IMU.

Parameters

  • none

Return

Returns the temperature in degres celsius

◆ pogobot_infrared_clear_message_queue()

void pogobot_infrared_clear_message_queue ( void )

(pogobot_infrared_clear_message_queue) Clears Infrared message queue

Parameters

  • none

Return

  • none

◆ pogobot_infrared_get_receiver_error_counter()

void pogobot_infrared_get_receiver_error_counter ( slip_error_counter_s * error_counter,
uint8_t ir_index )

(pogobot_infrared_get_receiver_error_counter) Get the receiver error counter value

Parameters

  • 'error_counter' - allocated structure 'slip_error_counter_s'
  • 'ir_index' - index of the ir receiver (0 to 3)

Return

  • none

◆ pogobot_infrared_ll_init()

void pogobot_infrared_ll_init ( void )

Infrared communication API Functions

◆ pogobot_infrared_message_available()

int pogobot_infrared_message_available ( void )

(pogobot_infrared_message_available) Infrared new message checks fonction

Parameters

  • none

Return

  • none

◆ pogobot_infrared_recover_next_message()

void pogobot_infrared_recover_next_message ( message_t * mes)

(pogobot_infrared_recover_next_message) Recover the next message inside the message queue

Parameters

  • 'mes' - Allocated structure of type 'message_t'

Return

  • none

◆ pogobot_infrared_reset_receiver_error_counter()

void pogobot_infrared_reset_receiver_error_counter ( void )

(pogobot_infrared_reset_receiver_error_counter) Reset all reveiver error counter

Parameters

  • none

Return

  • none

◆ pogobot_infrared_sendLongMessage_omniGen()

uint32_t pogobot_infrared_sendLongMessage_omniGen ( uint8_t * message,
uint16_t message_size )

(pogobot_infrared_sendLongMessage_omniGen) Send the same message in all direction at defined power Use pogobot_infrared_sendRawLongMessage Their no infrared sender ID

Parameters

  • 'message' - the current payload to send
  • 'message_size' - the size of the payload

Return

  • '0' in case of success
  • '1' in case of payload too long

◆ pogobot_infrared_sendLongMessage_omniSpe()

uint32_t pogobot_infrared_sendLongMessage_omniSpe ( uint8_t * message,
uint16_t message_size )

(pogobot_infrared_sendLongMessage_omniSpe) Send successively the same message with the origin infrared ID on each Infrared It is 4 times slower that without ID Use pogobot_infrared_sendRawLongMessage

Parameters

  • 'message' - the current payload to send
  • 'message_size' - the size of the payload

Return

  • '0' in case of success
  • '1' in case of payload too long

◆ pogobot_infrared_sendLongMessage_uniSpe()

uint32_t pogobot_infrared_sendLongMessage_uniSpe ( ir_direction dir,
uint8_t * message,
uint16_t message_size )

(pogobot_infrared_sendLongMessage_uniSpe) Send a message in only direction at defined power Use pogobot_infrared_sendRawLongMessage

Parameters

  • 'dir' - indicates the direction to send the message
  • 'message' - the current payload to send
  • 'message_size' - the size of the payload

Return

  • '0' in case of success
  • '1' in case of payload too long

◆ pogobot_infrared_sendRawLongMessage()

uint32_t pogobot_infrared_sendRawLongMessage ( message_t *const message)

(pogobot_infrared_sendRawLongMessage) Prepare and send one packet, with the specified emitters and powers, to the recipient, containing the specified message.

Parameters

  • 'message' - fully filled message_t variable

Return

  • '0' in case of success
  • '1' in case of payload too long

◆ pogobot_infrared_sendRawShortMessage()

uint32_t pogobot_infrared_sendRawShortMessage ( ir_direction dir,
short_message_t *const message )

(pogobot_infrared_sendRawShortMessage) Prepare and send one packet, with a short header containing the specified message.

Parameters

  • 'dir' - indicates the direction to send the message
  • 'message' - fully filled short_message_t variable

Return

  • '0' in case of success
  • '1' in case of payload too long

◆ pogobot_infrared_sendShortMessage_omni()

uint32_t pogobot_infrared_sendShortMessage_omni ( uint8_t * message,
uint16_t message_size )

(pogobot_infrared_sendShortMessage_omni) Send a short header message in all direction at defined power Use pogobot_infrared_sendRawShortMessage

Parameters

  • 'message' - the current payload to send
  • 'message_size' - the size of the payload

Return

  • '0' in case of success
  • '1' in case of payload too long

◆ pogobot_infrared_sendShortMessage_uni()

uint32_t pogobot_infrared_sendShortMessage_uni ( ir_direction dir,
uint8_t * message,
uint16_t message_size )

(pogobot_infrared_sendShortMessage_uni) Send a short header message in only direction at defined power Use pogobot_infrared_sendRawShortMessage

Parameters

  • 'dir' - indicates the direction to send the message
  • 'message' - the current payload to send
  • 'message_size' - the size of the payload

Return

  • '0' in case of success
  • '1' in case of payload too long

◆ pogobot_infrared_set_power()

void pogobot_infrared_set_power ( uint8_t power)

(pogobot_infrared_set_power) set the power level used to send all the next messages

Parameters

  • 'power' - use the pogobot_infrared_emitter_power_* or the values {0,1,2,3}

Return

  • none

◆ pogobot_infrared_update()

void pogobot_infrared_update ( void )

(pogobot_infrared_update) Infrared checks for received data and send to decode messages Decoded messages are placed in a Fifo

Parameters

  • none

Return

  • none

◆ pogobot_init()

void pogobot_init ( void )

Global API

(pogobot_init) Global API Initialisation This function is mandatory inside your program

Parameters

  • none

Return

  • none

◆ pogobot_led_setColor()

void pogobot_led_setColor ( const uint8_t r,
const uint8_t g,
const uint8_t b )

RGB LED API

◆ pogobot_led_setColors()

void pogobot_led_setColors ( const uint8_t r,
const uint8_t g,
const uint8_t b,
uint8_t id )

(pogobot_led_setColors) Set the value of red, green and blue of the led with the number (ID) in static mode each value goes from 0 to 255 to determine the intensity. (only available with a belly with multiple LEDs)

Parameters

  • 'r' - value of the RED part
  • 'g' - value of the GREEN part
  • 'b' - value of the BLUE part
  • 'id' - Led ID (0 = head, 1 = belly front, 2 = belly right, 3 = belly back, 4 = belly left)

Return

  • none

◆ pogobot_motor_dir_current_status()

uint32_t pogobot_motor_dir_current_status ( void )

(pogobot_motor_dir_current_status) recover the value of the motor direction bit field.

Parameters

  • none

Return

  • bit field ( XXXX XMLR )

◆ pogobot_motor_dir_mem_get()

int8_t pogobot_motor_dir_mem_get ( uint8_t * p_directions)

(pogobot_motor_dir_mem_get) get the value of pwm that commands the motor.

Parameters

  • 'p_directions' - is an array of size 3 [R, L, B]. Each value is the chosen direction (0 or 1)

Return

  • the success or not of the read in memory (0: Ok, -1: NOk)

◆ pogobot_motor_dir_mem_set()

int8_t pogobot_motor_dir_mem_set ( uint8_t * p_directions)

(pogobot_motor_dir_mem_set) set the value of pwm that commands the motor (persistent).

Parameters

  • 'p_directions' - is an array of size 3 [R, L, B]. Each value is the chosen direction (0 or 1)

Return

  • the success or not of the read in memory (0: Ok, -1: NOk)

◆ pogobot_motor_dir_set()

void pogobot_motor_dir_set ( motor_id motor,
uint8_t value )

(pogobot_motor_dir_set) set the value of pwm that commands the motor (active).

Parameters

  • 'motor' - is the id of the motor you want to command (motorR, motorL, motorB)
  • 'value' - is the choosen direction (0 or 1)

Return

  • none

◆ pogobot_motor_power_mem_get()

uint8_t pogobot_motor_power_mem_get ( uint16_t * p_powers)

(pogobot_motor_power_mem_get) recover the value of the motor power memorized.

Parameters

  • 'p_powers' - is an array of size 3 [R, L, B]. Each value is the chosen power [0, 1023]

Return

  • the success or not of the read in memory (0: Ok, -1: NOK)

◆ pogobot_motor_power_mem_set()

uint8_t pogobot_motor_power_mem_set ( uint16_t * p_powers)

(pogobot_motor_power_mem_set) write the value of the motor power in memory (persistent).

Parameters

  • 'p_powers' - is an array of size 3 [R, L, B]. Each value is the chosen power [0, 1023]

Return

  • the success or not of the read in memory (0: Ok, -1: NOK)

◆ pogobot_motor_power_set()

void pogobot_motor_power_set ( motor_id motor,
uint16_t value )

Motors API Values

◆ pogobot_motor_set()

void pogobot_motor_set ( motor_id motor,
uint16_t value )

◆ pogobot_photosensors_read()

int16_t pogobot_photosensors_read ( uint8_t sensor_number)

Photosensors API Values

◆ pogobot_stopwatch_get_elapsed_microseconds()

int32_t pogobot_stopwatch_get_elapsed_microseconds ( time_reference_t * stopwatch)

(pogobot_stopwatch_get_elapsed_microseconds) provides the current number of elapsed microseconds without otherwise interfering with the stopwatch state.

Parameters

Return

Returns the number of microseconds elapsed on 32 bits (which may be negative if you offset the origin to the future)

◆ pogobot_stopwatch_lap()

int32_t pogobot_stopwatch_lap ( time_reference_t * stopwatch)

(pogobot_stopwatch_lap) measures time elapsed from origin and offsets so that origin is zero at this point in time.

Parameters

Return

Returns the number of microseconds elapsed on 32 bits (which may be negative if you offset the origin to the future)

◆ pogobot_stopwatch_offset_origin_microseconds()

void pogobot_stopwatch_offset_origin_microseconds ( time_reference_t * stopwatch,
int32_t microseconds_offset )

(pogobot_stopwatch_offset_origin_microseconds) offsets the origin of the stopwatch by the specified number of microseconds.

Parameters

  • 'stopwatch' - pointer to a time_reference_t structure
  • 'microseconds_offset' - number of microsenconds to offset the origin

Return

  • none

◆ pogobot_stopwatch_reset()

void pogobot_stopwatch_reset ( time_reference_t * stopwatch)

(pogobot_stopwatch_reset) reset a time_reference structure. To use a time_reference_t as a stopwatch you must reset it using pogobot_stopwatch_reset()

Parameters

Return

  • none

◆ pogobot_timer_get_remaining_microseconds()

int32_t pogobot_timer_get_remaining_microseconds ( time_reference_t * timer)

(pogobot_timer_get_remaining_microseconds) provides the current of microseconds until the timer has expired, without otherwise interfering with the timer state.

Parameters

Return

Returns the number of microseconds elapsed on 32 bits. The result is a signed number, positive when the timer has not expired yet, negative when the timer has expired.

◆ pogobot_timer_has_expired()

bool pogobot_timer_has_expired ( time_reference_t * timer)

(pogobot_timer_has_expired) Returns true when the timer has expired, false when the timer has not expired yet.

Parameters

Return

Returns a bool depending on the status (True: if expired, False: if not expired)

◆ pogobot_timer_init()

void pogobot_timer_init ( time_reference_t * timer,
int32_t microseconds_to_go )

(pogobot_timer_init) set a timer that will expire in the defined number of microseconds in the future.

Parameters

  • 'timer' - pointer to a time_reference_t structure
  • 'microseconds_to_go' - number of microsenconds to go

Return

  • none

◆ pogobot_timer_offset_origin_microseconds()

void pogobot_timer_offset_origin_microseconds ( time_reference_t * timer,
int32_t microseconds_offset )

(pogobot_timer_offset_origin_microseconds) offsets the origin of the timer by the specified number of microseconds.

Parameters

  • 'timer' - pointer to a time_reference_t structure
  • 'microseconds_offset' - number of microsenconds to offset the origin

Return

  • none

◆ pogobot_timer_wait_for_expiry()

void pogobot_timer_wait_for_expiry ( time_reference_t * timer)

(pogobot_timer_wait_for_expiry) waits until the timer has expired.

Parameters

Return

  • none

◆ pogosim_printf()

void pogosim_printf ( const char * format,
... )

◆ pogosim_putchar()

int pogosim_putchar ( int ch)

◆ stop_simulation()

void stop_simulation ( void )

(stop_simulation) Stops the simulation

Variable Documentation

◆ _selected_power

uint8_t const _selected_power = 1

◆ _slip_error_counter

slip_error_counter_s _slip_error_counter = {0, 0, 0}