Class representing a simulated Pogobot. More...
#include <robot.h>
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. | |
| ObjectGeometry * | get_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_t > | leds = 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_t > | messages |
| Queue of incoming messages. | |
| float | communication_radius |
| Communication radius of each IR emitter. | |
| std::unique_ptr< MsgSuccessRate > | msg_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 | |
| ObjectGeometry * | geom |
| Geometry of the object. | |
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.
| 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).
| _id | Unique object identifier. |
| x | Initial x-coordinate in the simulation. |
| y | Initial y-coordinate in the simulation. |
| geom | Object's geometry. |
| world_id | The Box2D world identifier. |
| _userdatasize | Size of the memory block allocated for user data. |
| _communication_radius | communication radius of each IR emitter |
| _msg_success_rate | std::unique_ptr<MsgSuccessRate> describing the probability of successfully sending a message. |
| _temporal_noise_stddev | Standard deviation of the gaussian noise to apply to time on each object, or 0.0 for deterministic time |
| _linear_damping | Linear damping value for the physical body (default is 0.0f). |
| _angular_damping | Angular damping value for the physical body (default is 0.0f). |
| _density | Density of the body shape (default is 10.0f). |
| _friction | Friction coefficient of the body shape (default is 0.3f). |
| _restitution | Restitution (bounciness) of the body shape (default is 0.5f). |
| _max_linear_speed | Max speed value in mm.s^-1. |
| _max_angular_speed | Max speed value in rad.s^-1. |
| _linear_noise_stddev | Standard deviation of the gaussian noise to apply to linear velocity, or 0.0 for deterministic velocity. |
| _angular_noise_stddev | Standard deviation of the gaussian noise to apply to angular velocity, or 0.0 for deterministic velocity. |
| _rotate_LEDs_45_deg | Whether or not the LEDs are rotated by 45 degrees to prevent the front LED from overlapping with the arrow. |
| category | Name of the category of the object. |
| 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.
| simulation | Pointer to the underlying simulation. |
| _id | Unique object identifier. |
| x | Initial x-coordinate in the simulation. |
| y | Initial y-coordinate in the simulation. |
| world_id | The Box2D world identifier. |
| _userdatasize | Size of the memory block allocated for user data. |
| config | Configuration entry describing the object properties. |
|
protected |
Creates the object's physical body in the simulation.
| world_id | The Box2D world identifier. |
| void PogobotObject::disable_stop_watches | ( | ) |
Disables all registered stop watches.
Iterates through all registered stop watches and disables them.
| void PogobotObject::enable_stop_watches | ( | ) |
Enables all registered stop watches.
Iterates through all registered stop watches and enables them.
|
inline |
Check if user steps are enabled.
|
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.
|
virtual |
Retrieves the IR emitters current positions.
Returns the position of one of the robot's IR emitter as a Box2D vector.
Reimplemented in PogobjectObject, and Pogowall.
|
virtual |
Returns the position of a photosensor.
| sensor_number | the id (0-2) of the sensor. |
|
protectedvirtual |
Initialize the level of angular bias, based on provided configuration/parameters.
|
protectedvirtual |
Initialize the level of bias each photosensor has, based on provided configuration/parameters.
|
protected |
Initialize time-related operations.
|
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.
|
overrideprotectedvirtual |
Parse a provided configuration and set associated members values.
| config | Configuration entry describing the object properties. |
Reimplemented from PhysicalObject.
Reimplemented in ActiveObject, and MembraneObject.
| void PogobotObject::receive_message | ( | message_t *const | message, |
| PogobotObject * | source ) |
Receive a message from another robot.
| message | Pointer to the message_t to receive. |
| source | Pointer to the originating robot. |
| 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.
| sw | Pointer to the stop watch to register. |
|
overridevirtual |
Renders the object on the given SDL renderer.
| renderer | Pointer to the SDL_Renderer. |
| world_id | The Box2D world identifier (unused in rendering). |
Implements PhysicalObject.
Reimplemented in ActiveObject, MembraneObject, PogobjectObject, and Pogowall.
|
virtual |
Renders the communication channels originating from this robot.
| renderer | Pointer to the SDL_Renderer. |
| world_id | The Box2D world identifier (unused in rendering). |
Reimplemented in ActiveObject, and Pogowall.
| 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.
| dir | Direction in which the message is sent (i.e. the number of the IR emitter) |
| message | Pointer to the message_t to send. |
| 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.
| dir | Direction in which the message is sent (i.e. the number of the IR emitter) |
| message | Pointer to the short_message_t to send. |
|
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.
| motor | The identifier of the motor to update. |
| speed | The new speed value for the selected motor. |
Reimplemented in ActiveObject, MembraneObject, PogobjectObject, and Pogowall.
| void PogobotObject::sleep_µs | ( | uint64_t | microseconds | ) |
Simulate a sleep on a single robot.
| microseconds | Number of microseconds to sleep for |
|
virtual |
Updates the object's current time.
Computes the current time in microseconds relative to the simulation start.
| uint32_t PogobotObject::_current_time_milliseconds = 0 |
Current time in milliseconds.
| bool PogobotObject::_enable_user_steps = true |
Whether we allow user programs to be executed.
| uint32_t PogobotObject::_error_code_initial_time = 0 |
Initial time for error code reporting.
| time_reference_t PogobotObject::_global_timer |
Global timer reference.
| int16_t PogobotObject::angular_bias = 0 |
|
protected |
| void(* PogobotObject::callback_export_data) (void) = nullptr |
Callback to export data.
| float PogobotObject::communication_radius |
Communication radius of each IR emitter.
| uint64_t PogobotObject::current_time_microseconds = 0LL |
Current time in microseconds.
| void* PogobotObject::data = nullptr |
Pointer to user data.
| int8_t PogobotObject::error_codes_led_idx = 3 |
LED index for error codes.
LED colors for the robot.
| float PogobotObject::left_motor_speed = 0 |
Current speed of the left motor.
|
protected |
| uint8_t PogobotObject::main_loop_hz = 60 |
Main loop frequency in Hz.
|
protected |
|
protected |
| uint8_t PogobotObject::max_nb_processed_msg_per_tick = 3 |
Maximum number of messages processed per tick.
| std::queue<message_t> PogobotObject::messages |
Queue of incoming messages.
| uint8_t PogobotObject::motor_dir[3] = {0, 1, 0} |
| uint8_t PogobotObject::motor_dir_mem[3] = {0, 1, 0} |
Motors current direction and power ([R, L, B]).
| uint16_t PogobotObject::motor_power_mem[3] = {512, 512, 0} |
| void(* PogobotObject::msg_rx_fn) (message_t *) = nullptr |
Function pointer for message reception.
| std::unique_ptr<MsgSuccessRate> PogobotObject::msg_success_rate |
Probability of successfully sending a message.
| bool(* PogobotObject::msg_tx_fn) (void) = nullptr |
Function pointer for message transmission.
| uint32_t PogobotObject::nb_msgs_recv = 0 |
Counter for messages received.
| uint32_t PogobotObject::nb_msgs_sent = 0 |
Counter for messages sent.
| std::vector<std::vector<PogobotObject*> > PogobotObject::neighbors {ir_all+1} |
Pointers to neighboring robots.
| uint8_t PogobotObject::percent_msgs_sent_per_ticks = 20 |
Percentage of messages sent per tick.
| std::vector<int16_t> PogobotObject::photosensors_biases = {0, 0, 0} |
Level of systematic bias to apply to each photosensor.
| float PogobotObject::photosensors_noise_stddev = 0.0f |
Stddev of the Gaussian noise to apply to photosensors light levels.
| uint32_t PogobotObject::pogobot_ticks = 0 |
Simulation ticks counter.
| float PogobotObject::radius |
Radius of this robot.
| float PogobotObject::right_motor_speed = 0 |
Current speed of the right motor.
|
protected |
| bool PogobotObject::show_lateral_leds = false |
Whether to render lateral LEDs.
| std::set<time_reference_t*> PogobotObject::stop_watches |
Set of registered stop watches.
|
protected |
|
protected |
| time_reference_t PogobotObject::timer_main_loop |
Main loop timer reference.
| void(* PogobotObject::user_init) (void) = nullptr |
Pointer to a user-defined initialization function.
| void(* PogobotObject::user_step) (void) = nullptr |
Pointer to a user-defined step function.