Pogosim
Loading...
Searching...
No Matches
PogobotObject Class Reference

Class representing a simulated Pogobot. More...

#include <robot.h>

Inheritance diagram for PogobotObject:
PhysicalObject Object ActiveObject PogobjectObject Pogowall MembraneObject

Public Member Functions

 PogobotObject (uint16_t _id, float _x, float _y, ObjectGeometry &geom, b2WorldId world_id, size_t _userdatasize, float _communication_radius=80.0f, std::unique_ptr< MsgSuccessRate > _msg_success_rate=std::make_unique< ConstMsgSuccessRate >(0.5), float _temporal_noise_stddev=0.0f, float _linear_damping=0.0f, float _angular_damping=0.0f, float _density=10.0f, float _friction=0.3f, float _restitution=0.5f, float _max_linear_speed=100.0f, float _max_angular_speed=1.0f, float _linear_noise_stddev=0.0f, float _angular_noise_stddev=0.0f, bool _rotate_LEDs_45_deg=false, std::pair< int16_t, int16_t > angular_systematic_bias_domain={0, 0}, std::pair< int16_t, int16_t > photosensors_systematic_bias_domain={0, 0}, float _photosensors_noise_stddev=0.0f, std::string const &_category="robots", bool dummy=false)
 PogobotObject (Simulation *simulation, uint16_t _id, float _x, float _y, b2WorldId world_id, size_t _userdatasize, Configuration const &config, std::string const &_category="robots")
 Constructs a PogobotObject from a configuration entry.
virtual void launch_user_step (float t) override
 Launches the user-defined step function.
void register_stop_watch (time_reference_t *sw)
 Registers a stop watch with the robot.
void enable_stop_watches ()
 Enables all registered stop watches.
void disable_stop_watches ()
 Disables all registered stop watches.
virtual void update_time ()
 Updates the object's current time.
virtual void render (SDL_Renderer *, b2WorldId) const override
 Renders the object on the given SDL renderer.
virtual void render_communication_channels (SDL_Renderer *, b2WorldId) const
 Renders the communication channels originating from this robot.
virtual void set_motor (motor_id motor, int speed)
 Updates the motor speed of the robot and recalculates its velocities.
virtual b2Vec2 get_IR_emitter_position (ir_direction dir) const
 Retrieves the IR emitters current positions.
virtual float get_IR_emitter_angle (ir_direction dir) const
 World-frame bearing of the chosen IR emitter.
virtual b2Vec2 get_photosensor_position (uint8_t sensor_number) const
 Returns the position of a photosensor.
void send_to_neighbors (ir_direction dir, short_message_t *const message)
 Sends a short message to neighboring robots.
void send_to_neighbors (ir_direction dir, message_t *const message)
 Sends a message to neighboring robots.
void receive_message (message_t *const message, PogobotObject *source)
 Receive a message from another robot.
bool enable_user_steps () const
 Check if user steps are enabled.
void sleep_µs (uint64_t microseconds)
 Simulate a sleep on a single robot.
Public Member Functions inherited from PhysicalObject
 PhysicalObject (uint16_t _id, float _x, float _y, ObjectGeometry &geom, b2WorldId world_id, float _linear_damping=0.0f, float _angular_damping=0.0f, float _density=10.0f, float _friction=0.3f, float _restitution=0.5f, std::string const &_category="objects")
 Constructs a PhysicalObject.
 PhysicalObject (Simulation *simulation, uint16_t _id, float _x, float _y, b2WorldId world_id, Configuration const &config, std::string const &_category="objects")
 Constructs a PhysicalObject from a configuration entry.
virtual b2Vec2 get_position () const
 Retrieves the object's current position.
float get_angle () const
 Retrieves the object's current orientation angle.
float get_angular_velocity () const
 Retrieves the object's current angular velocity.
b2Vec2 get_linear_acceleration () const
 Retrieves the object's current angular velocity.
virtual void move (float x, float y, float theta=NAN) override
 Move the object to a given coordinate.
virtual bool is_tangible () const override
 Returns whether this object is tangible (e.g. collisions, etc) or not.
virtual arena_polygons_t generate_contours (std::size_t points_per_contour=0) const override
 Return one or more polygonal contours that represent the geometry of the object.
Public Member Functions inherited from Object
 Object (float _x, float _y, ObjectGeometry &_geom, std::string const &_category="objects")
 Constructs an Object.
 Object (Simulation *simulation, float _x, float _y, Configuration const &config, std::string const &_category="objects")
 Constructs an Object from a configuration entry.
virtual ~Object ()
 Destructor.
ObjectGeometryget_geometry ()
 Return the object's geometry.

Public Attributes

void * data = nullptr
 Pointer to user data.
void(* user_init )(void) = nullptr
 Pointer to a user-defined initialization function.
void(* user_step )(void) = nullptr
 Pointer to a user-defined step function.
bool _enable_user_steps = true
 Whether we allow user programs to be executed.
void(* callback_export_data )(void) = nullptr
 Callback to export data.
uint32_t pogobot_ticks = 0
 Simulation ticks counter.
uint8_t main_loop_hz = 60
 Main loop frequency in Hz.
uint8_t max_nb_processed_msg_per_tick = 3
 Maximum number of messages processed per tick.
void(* msg_rx_fn )(message_t *) = nullptr
 Function pointer for message reception.
bool(* msg_tx_fn )(void) = nullptr
 Function pointer for message transmission.
int8_t error_codes_led_idx = 3
 LED index for error codes.
time_reference_t _global_timer
 Global timer reference.
time_reference_t timer_main_loop
 Main loop timer reference.
uint32_t _current_time_milliseconds = 0
 Current time in milliseconds.
uint32_t _error_code_initial_time = 0
 Initial time for error code reporting.
uint8_t percent_msgs_sent_per_ticks = 20
 Percentage of messages sent per tick.
uint32_t nb_msgs_sent = 0
 Counter for messages sent.
uint32_t nb_msgs_recv = 0
 Counter for messages received.
std::set< time_reference_t * > stop_watches
 Set of registered stop watches.
float radius
 Radius of this robot.
float left_motor_speed = 0
 Current speed of the left motor.
float right_motor_speed = 0
 Current speed of the right motor.
bool show_lateral_leds = false
 Whether to render lateral LEDs.
std::vector< color_tleds = std::vector<color_t>(5, {0, 0, 0})
 LED colors for the robot.
std::vector< std::vector< PogobotObject * > > neighbors {ir_all+1}
 Pointers to neighboring robots.
std::queue< message_tmessages
 Queue of incoming messages.
float communication_radius
 Communication radius of each IR emitter.
std::unique_ptr< MsgSuccessRatemsg_success_rate
 Probability of successfully sending a message.
uint64_t current_time_microseconds = 0LL
 Current time in microseconds.
uint8_t motor_dir_mem [3] = {0, 1, 0}
 Motors current direction and power ([R, L, B]).
uint8_t motor_dir [3] = {0, 1, 0}
uint16_t motor_power_mem [3] = {512, 512, 0}
std::vector< int16_t > photosensors_biases = {0, 0, 0}
 Level of systematic bias to apply to each photosensor.
float photosensors_noise_stddev = 0.0f
 Stddev of the Gaussian noise to apply to photosensors light levels.
int16_t angular_bias = 0
Public Attributes inherited from PhysicalObject
uint16_t id
 Object identifier.
Public Attributes inherited from Object
float x
 X position.
float y
 Y position.
float theta
 Orientation (in rad).
std::string category
 Category of the object.

Protected Member Functions

void create_robot_body (b2WorldId world_id)
 Creates the object's physical body in the simulation.
void initialize_time ()
 Initialize time-related operations.
virtual void parse_configuration (Configuration const &config, Simulation *simulation) override
 Parse a provided configuration and set associated members values.
virtual void initialize_photosensors_bias (std::pair< int16_t, int16_t > &domain)
 Initialize the level of bias each photosensor has, based on provided configuration/parameters.
virtual void initialize_angular_bias (std::pair< int16_t, int16_t > &domain)
 Initialize the level of angular bias, based on provided configuration/parameters.
Protected Member Functions inherited from PhysicalObject
virtual void create_body (b2WorldId world_id)
 Creates the object's physical body in the simulation.

Protected Attributes

float temporal_noise = 0
float temporal_noise_stddev
float max_linear_speed
float max_angular_speed
float linear_noise_stddev
float angular_noise_stddev
bool rotate_LEDs_45_deg
Protected Attributes inherited from PhysicalObject
float linear_damping
float angular_damping
float density
float friction
float restitution
b2BodyId body_id
 Box2D body identifier.
float _estimated_dt = 0.0f
float _last_time = 0.0f
b2Vec2 _prev_v = {NAN, NAN}
b2Vec2 _lin_acc = {NAN, NAN}
Protected Attributes inherited from Object
ObjectGeometrygeom
 Geometry of the object.

Detailed Description

Class representing a simulated Pogobot.

The PogobotObject class encapsulates the properties and behaviors of a simulated Pogobot robot, including physical properties, timing, LED control, messaging, and rendering.

Constructor & Destructor Documentation

◆ PogobotObject() [1/2]

PogobotObject::PogobotObject ( uint16_t _id,
float _x,
float _y,
ObjectGeometry & geom,
b2WorldId world_id,
size_t _userdatasize,
float _communication_radius = 80.0f,
std::unique_ptr< MsgSuccessRate > _msg_success_rate = std::make_unique<ConstMsgSuccessRate>(0.5),
float _temporal_noise_stddev = 0.0f,
float _linear_damping = 0.0f,
float _angular_damping = 0.0f,
float _density = 10.0f,
float _friction = 0.3f,
float _restitution = 0.5f,
float _max_linear_speed = 100.0f,
float _max_angular_speed = 1.0f,
float _linear_noise_stddev = 0.0f,
float _angular_noise_stddev = 0.0f,
bool _rotate_LEDs_45_deg = false,
std::pair< int16_t, int16_t > angular_systematic_bias_domain = {0, 0},
std::pair< int16_t, int16_t > photosensors_systematic_bias_domain = {0, 0},
float _photosensors_noise_stddev = 0.0f,
std::string const & _category = "robots",
bool dummy = false )

Initializes a new Pogobot robot with the specified identifier, user data size, initial position, radius, associated Box2D world, and message success rate. It also allows customization of the body's physical properties (linear and angular damping, density, friction, and restitution).

Parameters
_idUnique object identifier.
xInitial x-coordinate in the simulation.
yInitial y-coordinate in the simulation.
geomObject's geometry.
world_idThe Box2D world identifier.
_userdatasizeSize of the memory block allocated for user data.
_communication_radiuscommunication radius of each IR emitter
_msg_success_ratestd::unique_ptr<MsgSuccessRate> describing the probability of successfully sending a message.
_temporal_noise_stddevStandard deviation of the gaussian noise to apply to time on each object, or 0.0 for deterministic time
_linear_dampingLinear damping value for the physical body (default is 0.0f).
_angular_dampingAngular damping value for the physical body (default is 0.0f).
_densityDensity of the body shape (default is 10.0f).
_frictionFriction coefficient of the body shape (default is 0.3f).
_restitutionRestitution (bounciness) of the body shape (default is 0.5f).
_max_linear_speedMax speed value in mm.s^-1.
_max_angular_speedMax speed value in rad.s^-1.
_linear_noise_stddevStandard deviation of the gaussian noise to apply to linear velocity, or 0.0 for deterministic velocity.
_angular_noise_stddevStandard deviation of the gaussian noise to apply to angular velocity, or 0.0 for deterministic velocity.
_rotate_LEDs_45_degWhether or not the LEDs are rotated by 45 degrees to prevent the front LED from overlapping with the arrow.
categoryName of the category of the object.

◆ PogobotObject() [2/2]

PogobotObject::PogobotObject ( Simulation * simulation,
uint16_t _id,
float _x,
float _y,
b2WorldId world_id,
size_t _userdatasize,
Configuration const & config,
std::string const & _category = "robots" )

Constructs a PogobotObject from a configuration entry.

Parameters
simulationPointer to the underlying simulation.
_idUnique object identifier.
xInitial x-coordinate in the simulation.
yInitial y-coordinate in the simulation.
world_idThe Box2D world identifier.
_userdatasizeSize of the memory block allocated for user data.
configConfiguration entry describing the object properties.

Member Function Documentation

◆ create_robot_body()

void PogobotObject::create_robot_body ( b2WorldId world_id)
protected

Creates the object's physical body in the simulation.

Parameters
world_idThe Box2D world identifier.

◆ disable_stop_watches()

void PogobotObject::disable_stop_watches ( )

Disables all registered stop watches.

Iterates through all registered stop watches and disables them.

◆ enable_stop_watches()

void PogobotObject::enable_stop_watches ( )

Enables all registered stop watches.

Iterates through all registered stop watches and enables them.

◆ enable_user_steps()

bool PogobotObject::enable_user_steps ( ) const
inline

Check if user steps are enabled.

Returns
Whether user steps are enabled/executed or not

◆ get_IR_emitter_angle()

float PogobotObject::get_IR_emitter_angle ( ir_direction dir) const
virtual

World-frame bearing of the chosen IR emitter.

For the four perimeter LEDs the bearing is the angle of the outward normal of the robot’s hull at that LED (i.e. ±90° from the tangent). For dir == MIDDLE we return the robot’s forward heading, so the caller still receives a meaningful direction.

Reimplemented in Pogowall.

◆ get_IR_emitter_position()

b2Vec2 PogobotObject::get_IR_emitter_position ( ir_direction dir) const
virtual

Retrieves the IR emitters current positions.

Returns the position of one of the robot's IR emitter as a Box2D vector.

Returns
b2Vec2 The current position.

Reimplemented in PogobjectObject, and Pogowall.

◆ get_photosensor_position()

b2Vec2 PogobotObject::get_photosensor_position ( uint8_t sensor_number) const
virtual

Returns the position of a photosensor.

Parameters
sensor_numberthe id (0-2) of the sensor.
Returns
the position of photosensor 'sensor_number'.

◆ initialize_angular_bias()

void PogobotObject::initialize_angular_bias ( std::pair< int16_t, int16_t > & domain)
protectedvirtual

Initialize the level of angular bias, based on provided configuration/parameters.

◆ initialize_photosensors_bias()

void PogobotObject::initialize_photosensors_bias ( std::pair< int16_t, int16_t > & domain)
protectedvirtual

Initialize the level of bias each photosensor has, based on provided configuration/parameters.

◆ initialize_time()

void PogobotObject::initialize_time ( )
protected

Initialize time-related operations.

◆ launch_user_step()

void PogobotObject::launch_user_step ( float t)
overridevirtual

Launches the user-defined step function.

Updates the object's time, enables all registered stop watches, executes the user step function via pogo_main_loop_step, and then disables the stop watches.

Reimplemented from PhysicalObject.

◆ parse_configuration()

void PogobotObject::parse_configuration ( Configuration const & config,
Simulation * simulation )
overrideprotectedvirtual

Parse a provided configuration and set associated members values.

Parameters
configConfiguration entry describing the object properties.

Reimplemented from PhysicalObject.

Reimplemented in ActiveObject, and MembraneObject.

◆ receive_message()

void PogobotObject::receive_message ( message_t *const message,
PogobotObject * source )

Receive a message from another robot.

Parameters
messagePointer to the message_t to receive.
sourcePointer to the originating robot.

◆ register_stop_watch()

void PogobotObject::register_stop_watch ( time_reference_t * sw)

Registers a stop watch with the robot.

Adds the given stop watch pointer to the set of stop watches.

Parameters
swPointer to the stop watch to register.

◆ render()

void PogobotObject::render ( SDL_Renderer * renderer,
b2WorldId worldId ) const
overridevirtual

Renders the object on the given SDL renderer.

Parameters
rendererPointer to the SDL_Renderer.
world_idThe Box2D world identifier (unused in rendering).

Implements PhysicalObject.

Reimplemented in ActiveObject, MembraneObject, PogobjectObject, and Pogowall.

◆ render_communication_channels()

void PogobotObject::render_communication_channels ( SDL_Renderer * renderer,
b2WorldId worldId ) const
virtual

Renders the communication channels originating from this robot.

Parameters
rendererPointer to the SDL_Renderer.
world_idThe Box2D world identifier (unused in rendering).

Reimplemented in ActiveObject, and Pogowall.

◆ send_to_neighbors() [1/2]

void PogobotObject::send_to_neighbors ( ir_direction dir,
message_t *const message )

Sends a message to neighboring robots.

Iterates over neighboring robots and, based on a random probability and the message success rate, enqueues the message in each neighbor's message queue.

Parameters
dirDirection in which the message is sent (i.e. the number of the IR emitter)
messagePointer to the message_t to send.

◆ send_to_neighbors() [2/2]

void PogobotObject::send_to_neighbors ( ir_direction dir,
short_message_t *const message )

Sends a short message to neighboring robots.

Converts a short message to a full message and forwards it to all neighboring robots.

Parameters
dirDirection in which the message is sent (i.e. the number of the IR emitter)
messagePointer to the short_message_t to send.

◆ set_motor()

void PogobotObject::set_motor ( motor_id motor,
int speed )
virtual

Updates the motor speed of the robot and recalculates its velocities.

This method sets the motor speed (left or right) and then computes the robot's linear and angular velocities. It applies the damping values that were provided in the constructor. If the noise standard deviations (for linear or angular velocities) are greater than 0.0, a Gaussian noise component is added to the respective velocity.

Parameters
motorThe identifier of the motor to update.
speedThe new speed value for the selected motor.

Reimplemented in ActiveObject, MembraneObject, PogobjectObject, and Pogowall.

◆ sleep_µs()

void PogobotObject::sleep_µs ( uint64_t microseconds)

Simulate a sleep on a single robot.

Parameters
microsecondsNumber of microseconds to sleep for

◆ update_time()

void PogobotObject::update_time ( )
virtual

Updates the object's current time.

Computes the current time in microseconds relative to the simulation start.

Member Data Documentation

◆ _current_time_milliseconds

uint32_t PogobotObject::_current_time_milliseconds = 0

Current time in milliseconds.

◆ _enable_user_steps

bool PogobotObject::_enable_user_steps = true

Whether we allow user programs to be executed.

◆ _error_code_initial_time

uint32_t PogobotObject::_error_code_initial_time = 0

Initial time for error code reporting.

◆ _global_timer

time_reference_t PogobotObject::_global_timer

Global timer reference.

◆ angular_bias

int16_t PogobotObject::angular_bias = 0

◆ angular_noise_stddev

float PogobotObject::angular_noise_stddev
protected

◆ callback_export_data

void(* PogobotObject::callback_export_data) (void) = nullptr

Callback to export data.

◆ communication_radius

float PogobotObject::communication_radius

Communication radius of each IR emitter.

◆ current_time_microseconds

uint64_t PogobotObject::current_time_microseconds = 0LL

Current time in microseconds.

◆ data

void* PogobotObject::data = nullptr

Pointer to user data.

◆ error_codes_led_idx

int8_t PogobotObject::error_codes_led_idx = 3

LED index for error codes.

◆ leds

std::vector<color_t> PogobotObject::leds = std::vector<color_t>(5, {0, 0, 0})

LED colors for the robot.

◆ left_motor_speed

float PogobotObject::left_motor_speed = 0

Current speed of the left motor.

◆ linear_noise_stddev

float PogobotObject::linear_noise_stddev
protected

◆ main_loop_hz

uint8_t PogobotObject::main_loop_hz = 60

Main loop frequency in Hz.

◆ max_angular_speed

float PogobotObject::max_angular_speed
protected

◆ max_linear_speed

float PogobotObject::max_linear_speed
protected

◆ max_nb_processed_msg_per_tick

uint8_t PogobotObject::max_nb_processed_msg_per_tick = 3

Maximum number of messages processed per tick.

◆ messages

std::queue<message_t> PogobotObject::messages

Queue of incoming messages.

◆ motor_dir

uint8_t PogobotObject::motor_dir[3] = {0, 1, 0}

◆ motor_dir_mem

uint8_t PogobotObject::motor_dir_mem[3] = {0, 1, 0}

Motors current direction and power ([R, L, B]).

◆ motor_power_mem

uint16_t PogobotObject::motor_power_mem[3] = {512, 512, 0}

◆ msg_rx_fn

void(* PogobotObject::msg_rx_fn) (message_t *) = nullptr

Function pointer for message reception.

◆ msg_success_rate

std::unique_ptr<MsgSuccessRate> PogobotObject::msg_success_rate

Probability of successfully sending a message.

◆ msg_tx_fn

bool(* PogobotObject::msg_tx_fn) (void) = nullptr

Function pointer for message transmission.

◆ nb_msgs_recv

uint32_t PogobotObject::nb_msgs_recv = 0

Counter for messages received.

◆ nb_msgs_sent

uint32_t PogobotObject::nb_msgs_sent = 0

Counter for messages sent.

◆ neighbors

std::vector<std::vector<PogobotObject*> > PogobotObject::neighbors {ir_all+1}

Pointers to neighboring robots.

◆ percent_msgs_sent_per_ticks

uint8_t PogobotObject::percent_msgs_sent_per_ticks = 20

Percentage of messages sent per tick.

◆ photosensors_biases

std::vector<int16_t> PogobotObject::photosensors_biases = {0, 0, 0}

Level of systematic bias to apply to each photosensor.

◆ photosensors_noise_stddev

float PogobotObject::photosensors_noise_stddev = 0.0f

Stddev of the Gaussian noise to apply to photosensors light levels.

◆ pogobot_ticks

uint32_t PogobotObject::pogobot_ticks = 0

Simulation ticks counter.

◆ radius

float PogobotObject::radius

Radius of this robot.

◆ right_motor_speed

float PogobotObject::right_motor_speed = 0

Current speed of the right motor.

◆ rotate_LEDs_45_deg

bool PogobotObject::rotate_LEDs_45_deg
protected

◆ show_lateral_leds

bool PogobotObject::show_lateral_leds = false

Whether to render lateral LEDs.

◆ stop_watches

std::set<time_reference_t*> PogobotObject::stop_watches

Set of registered stop watches.

◆ temporal_noise

float PogobotObject::temporal_noise = 0
protected

◆ temporal_noise_stddev

float PogobotObject::temporal_noise_stddev
protected

◆ timer_main_loop

time_reference_t PogobotObject::timer_main_loop

Main loop timer reference.

◆ user_init

void(* PogobotObject::user_init) (void) = nullptr

Pointer to a user-defined initialization function.

◆ user_step

void(* PogobotObject::user_step) (void) = nullptr

Pointer to a user-defined step function.


The documentation for this class was generated from the following files: