10#include <box2d/box2d.h>
54 virtual double operator()(
double msg_size,
double p_send,
double cluster_size)
const = 0;
80 DynamicMsgSuccessRate(
double alpha = 0.000001,
double beta = 3.0708,
double gamma = 2.3234,
double delta = 1.1897);
90 double operator()(
double msg_size,
double p_send,
double cluster_size)
const override;
121 double operator()(
double msg_size,
double p_send,
double cluster_size)
const override;
174 size_t _userdatasize,
175 float _communication_radius = 80.0f,
176 std::unique_ptr<MsgSuccessRate> _msg_success_rate = std::make_unique<ConstMsgSuccessRate>(0.5),
177 float _temporal_noise_stddev = 0.0f,
178 float _linear_damping = 0.0f,
float _angular_damping = 0.0f,
179 float _density = 10.0f,
float _friction = 0.3f,
float _restitution = 0.5f,
180 float _max_linear_speed = 100.0f,
float _max_angular_speed = 1.0f,
181 float _linear_noise_stddev = 0.0f,
float _angular_noise_stddev = 0.0f,
182 bool _rotate_LEDs_45_deg =
false,
183 std::pair<int16_t, int16_t> angular_systematic_bias_domain = {0, 0},
184 std::pair<int16_t, int16_t> photosensors_systematic_bias_domain = {0, 0},
185 float _photosensors_noise_stddev = 0.0f,
186 std::string
const& _category =
"robots",
201 b2WorldId world_id,
size_t _userdatasize,
Configuration const& config,
202 std::string
const& _category =
"robots");
284 virtual void render(SDL_Renderer*, b2WorldId)
const override;
335 std::vector<color_t>
leds = std::vector<color_t>(5, {0, 0, 0});
385 void sleep_µs(uint64_t microseconds);
473 size_t _userdatasize,
474 float _communication_radius = 80.0f,
475 std::unique_ptr<MsgSuccessRate> _msg_success_rate = std::make_unique<ConstMsgSuccessRate>(0.5),
476 float _temporal_noise_stddev = 0.0f,
477 float _linear_damping = 0.0f,
float _angular_damping = 0.0f,
478 float _density = 10.0f,
float _friction = 0.3f,
float _restitution = 0.5f,
479 std::string
const& _category =
"robots");
493 b2WorldId world_id,
size_t _userdatasize,
Configuration const& config,
494 std::string
const& _category =
"robots");
520 virtual void render(SDL_Renderer*, b2WorldId)
const override;
552 Pogowall(uint16_t _id,
float _x,
float _y,
554 size_t _userdatasize,
555 float _communication_radius = 80.0f,
556 std::unique_ptr<MsgSuccessRate> _msg_success_rate = std::make_unique<ConstMsgSuccessRate>(0.5),
557 float _temporal_noise_stddev = 0.0f,
558 float _linear_damping = 0.0f,
float _angular_damping = 0.0f,
559 float _density = 10.0f,
float _friction = 0.3f,
float _restitution = 0.5f,
560 float _max_linear_speed = 100.0f,
float _max_angular_speed = 1.0f,
561 float _linear_noise_stddev = 0.0f,
float _angular_noise_stddev = 0.0f,
562 std::string
const& _category =
"robots");
576 b2WorldId world_id,
size_t _userdatasize,
Configuration const& config,
577 std::string
const& _category =
"robots");
586 virtual void set_motor([[maybe_unused]]
motor_id motor, [[maybe_unused]]
int speed)
override { }
613 virtual void render(SDL_Renderer*, b2WorldId)
const override { }
635 virtual void move([[maybe_unused]]
float x, [[maybe_unused]]
float y, [[maybe_unused]]
float theta = NAN)
override { }
678 size_t _userdatasize,
679 float _communication_radius = 80.0f,
680 std::unique_ptr<MsgSuccessRate> _msg_success_rate = std::make_unique<ConstMsgSuccessRate>(0.5),
681 float _temporal_noise_stddev = 0.0f,
682 float _linear_damping = 0.0f,
float _angular_damping = 0.0f,
683 float _density = 10.0f,
float _friction = 0.3f,
float _restitution = 0.5f,
684 float _max_linear_speed = 100.0f,
float _max_angular_speed = 1.0f,
685 float _linear_noise_stddev = 0.0f,
float _angular_noise_stddev = 0.0f,
686 unsigned int _num_dots = 100,
float _dot_radius = 10.0f,
int _cross_span = 3,
687 float _stiffness = 30.f,
688 std::string _colormap =
"rainbow",
689 std::string
const& _category =
"robots");
703 b2WorldId world_id,
size_t _userdatasize,
Configuration const& config,
704 std::string
const& _category =
"robots");
713 virtual void set_motor([[maybe_unused]]
motor_id motor, [[maybe_unused]]
int speed)
override { }
730 virtual void render(SDL_Renderer*, b2WorldId)
const override;
744 virtual void move([[maybe_unused]]
float x, [[maybe_unused]]
float y, [[maybe_unused]]
float theta = NAN)
override;
782 float stiffness_scale = 1.0f);
832 size_t _userdatasize,
833 float _communication_radius = 80.0f,
834 std::unique_ptr<MsgSuccessRate> _msg_success_rate = std::make_unique<ConstMsgSuccessRate>(0.5),
835 float _temporal_noise_stddev = 0.0f,
836 float _linear_damping = 0.0f,
float _angular_damping = 0.0f,
837 float _density = 10.0f,
float _friction = 0.3f,
float _restitution = 0.5f,
838 float _max_linear_speed = 100.0f,
float _max_angular_speed = 1.0f,
839 float _linear_noise_stddev = 0.0f,
float _angular_noise_stddev = 0.0f,
840 std::string _colormap =
"rainbow",
841 std::string
const& _category =
"active_objects");
855 b2WorldId world_id,
size_t _userdatasize,
Configuration const& config,
856 std::string
const& _category =
"active_objects");
865 virtual void set_motor([[maybe_unused]]
motor_id motor, [[maybe_unused]]
int speed)
override { }
873 virtual void render(SDL_Renderer*, b2WorldId)
const override;
ActiveObject(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, std::string _colormap="rainbow", std::string const &_category="active_objects")
Definition robot.cpp:1067
std::string colormap
Move the object to a given coordinate.
Definition robot.h:894
virtual void set_motor(motor_id motor, int speed) override
Updates the motor speed of the robot and recalculates its velocities. Pogobjects do not move,...
Definition robot.h:865
virtual void render(SDL_Renderer *, b2WorldId) const override
Renders the robot on the given SDL renderer.
Definition robot.cpp:1103
virtual void parse_configuration(Configuration const &config, Simulation *simulation) override
Parse a provided configuration and set associated members values.
Definition robot.cpp:1097
virtual void render_communication_channels(SDL_Renderer *, b2WorldId) const override
Renders the communication channels originating from this robot.
Definition robot.h:881
Class for managing hierarchical configuration parameters.
Definition configuration.h:64
double operator()(double msg_size, double p_send, double cluster_size) const override
Returns the constant success rate.
Definition robot.cpp:59
ConstMsgSuccessRate(double value)
Constructs a new ConstMsgSuccessRate object.
Definition robot.cpp:56
DynamicMsgSuccessRate(double alpha=0.000001, double beta=3.0708, double gamma=2.3234, double delta=1.1897)
Constructs a new DynamicMsgSuccessRate object.
Definition robot.cpp:47
double operator()(double msg_size, double p_send, double cluster_size) const override
Computes the dynamic success rate.
Definition robot.cpp:50
virtual void set_motor(motor_id motor, int speed) override
Updates the motor speed of the robot and recalculates its velocities. Pogobjects do not move,...
Definition robot.h:713
virtual b2Vec2 get_position() const override
Retrieves the object's current position.
Definition robot.cpp:862
int num_dots
Definition robot.h:785
float dot_radius
Definition robot.h:787
virtual void render(SDL_Renderer *, b2WorldId) const override
Renders the robot on the given SDL renderer.
Definition robot.cpp:872
std::vector< Dot > dots
Definition robot.h:791
void make_distance_joint(b2WorldId world_id, b2BodyId a, b2BodyId b, float stiffness_scale=1.0f)
Definition robot.cpp:900
std::vector< Joint > joints
Definition robot.h:792
virtual bool is_tangible() const override
Returns whether this object is tangible (e.g. collisions, etc) or not.
Definition robot.h:735
std::string colormap
Definition robot.h:790
int cross_span
Definition robot.h:788
virtual arena_polygons_t generate_contours(std::size_t points_per_contour=0) const override
Return one or more polygonal contours that represent the current geometry of the object.
Definition robot.cpp:1037
float stiffness
Definition robot.h:789
virtual void move(float x, float y, float theta=NAN) override
Move the object to a given coordinate.
Definition robot.cpp:987
std::vector< size_t > size_contours
Definition robot.h:786
virtual void parse_configuration(Configuration const &config, Simulation *simulation) override
Parse a provided configuration and set associated members values.
Definition robot.cpp:852
void create_robot_body(b2WorldId world_id)
Creates the object's physical body in the simulation.
Definition robot.cpp:923
MembraneObject(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, unsigned int _num_dots=100, float _dot_radius=10.0f, int _cross_span=3, float _stiffness=30.f, std::string _colormap="rainbow", std::string const &_category="robots")
Definition robot.cpp:814
Abstract base class for message success rate calculations.
Definition robot.h:44
virtual double operator()(double msg_size, double p_send, double cluster_size) const =0
Computes the message success rate.
virtual ~MsgSuccessRate()=default
Virtual destructor.
Geometry of an object.
Definition objects_geometry.h:40
float y
Y position.
Definition objects.h:99
float x
X position.
Definition objects.h:98
ObjectGeometry * geom
Geometry of the object.
Definition objects.h:113
float theta
Orientation (in rad).
Definition objects.h:100
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.
Definition objects.cpp:56
virtual void render(SDL_Renderer *, b2WorldId) const override
Renders the robot on the given SDL renderer.
Definition robot.cpp:720
virtual void set_motor(motor_id motor, int speed) override
Updates the motor speed of the robot and recalculates its velocities. Pogobjects do not move,...
Definition robot.cpp:699
virtual b2Vec2 get_IR_emitter_position(ir_direction dir) const override
Retrieves the IR emitters current positions.
Definition robot.cpp:716
PogobjectObject(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, std::string const &_category="robots")
Definition robot.cpp:673
Class representing a simulated Pogobot.
Definition robot.h:142
virtual b2Vec2 get_photosensor_position(uint8_t sensor_number) const
Returns the position of a photosensor.
Definition robot.cpp:547
std::unique_ptr< MsgSuccessRate > msg_success_rate
Probability of successfully sending a message.
Definition robot.h:341
void(* callback_export_data)(void)
Callback to export data.
Definition robot.h:212
float communication_radius
Communication radius of each IR emitter.
Definition robot.h:340
std::vector< color_t > leds
LED colors for the robot.
Definition robot.h:335
void initialize_time()
Initialize time-related operations.
Definition robot.cpp:653
virtual void render_communication_channels(SDL_Renderer *, b2WorldId) const
Renders the communication channels originating from this robot.
Definition robot.cpp:351
uint8_t motor_dir_mem[3]
Motors current direction and power ([R, L, B]).
Definition robot.h:390
uint8_t percent_msgs_sent_per_ticks
Percentage of messages sent per tick.
Definition robot.h:233
float left_motor_speed
Current speed of the left motor.
Definition robot.h:273
virtual void set_motor(motor_id motor, int speed)
Updates the motor speed of the robot and recalculates its velocities.
Definition robot.cpp:444
bool rotate_LEDs_45_deg
Definition robot.h:416
std::vector< std::vector< PogobotObject * > > neighbors
Pointers to neighboring robots.
Definition robot.h:338
uint32_t pogobot_ticks
Simulation ticks counter.
Definition robot.h:223
time_reference_t _global_timer
Global timer reference.
Definition robot.h:229
uint8_t motor_dir[3]
Definition robot.h:391
bool enable_user_steps() const
Check if user steps are enabled.
Definition robot.h:377
uint32_t _error_code_initial_time
Initial time for error code reporting.
Definition robot.h:232
void * data
Pointer to user data.
Definition robot.h:208
std::queue< message_t > messages
Queue of incoming messages.
Definition robot.h:339
uint8_t max_nb_processed_msg_per_tick
Maximum number of messages processed per tick.
Definition robot.h:225
int8_t error_codes_led_idx
LED index for error codes.
Definition robot.h:228
virtual float get_IR_emitter_angle(ir_direction dir) const
World-frame bearing of the chosen IR emitter.
Definition robot.cpp:514
void(* user_init)(void)
Pointer to a user-defined initialization function.
Definition robot.h:209
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.
Definition robot.cpp:155
float photosensors_noise_stddev
Stddev of the Gaussian noise to apply to photosensors light levels.
Definition robot.h:439
void enable_stop_watches()
Enables all registered stop watches.
Definition robot.cpp:203
float angular_noise_stddev
Definition robot.h:415
float temporal_noise
Definition robot.h:408
virtual void render(SDL_Renderer *, b2WorldId) const override
Renders the object on the given SDL renderer.
Definition robot.cpp:216
virtual void initialize_angular_bias(std::pair< int16_t, int16_t > &domain)
Initialize the level of angular bias, based on provided configuration/parameters.
Definition robot.cpp:166
uint8_t main_loop_hz
Main loop frequency in Hz.
Definition robot.h:224
float linear_noise_stddev
Definition robot.h:414
std::set< time_reference_t * > stop_watches
Set of registered stop watches.
Definition robot.h:238
float right_motor_speed
Current speed of the right motor.
Definition robot.h:274
bool _enable_user_steps
Whether we allow user programs to be executed.
Definition robot.h:211
virtual b2Vec2 get_IR_emitter_position(ir_direction dir) const
Retrieves the IR emitters current positions.
Definition robot.cpp:490
std::vector< int16_t > photosensors_biases
Level of systematic bias to apply to each photosensor.
Definition robot.h:438
float max_linear_speed
Definition robot.h:412
float temporal_noise_stddev
Definition robot.h:409
uint16_t motor_power_mem[3]
Definition robot.h:392
void sleep_µs(uint64_t microseconds)
Simulate a sleep on a single robot.
Definition robot.cpp:665
virtual void parse_configuration(Configuration const &config, Simulation *simulation) override
Parse a provided configuration and set associated members values.
Definition robot.cpp:135
virtual void update_time()
Updates the object's current time.
Definition robot.cpp:661
uint32_t _current_time_milliseconds
Current time in milliseconds.
Definition robot.h:231
uint32_t nb_msgs_recv
Counter for messages received.
Definition robot.h:235
float radius
Radius of this robot.
Definition robot.h:272
time_reference_t timer_main_loop
Main loop timer reference.
Definition robot.h:230
bool(* msg_tx_fn)(void)
Function pointer for message transmission.
Definition robot.h:227
void(* msg_rx_fn)(message_t *)
Function pointer for message reception.
Definition robot.h:226
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)
Definition robot.cpp:91
uint64_t current_time_microseconds
Current time in microseconds.
Definition robot.h:387
virtual void launch_user_step(float t) override
Launches the user-defined step function.
Definition robot.cpp:188
void create_robot_body(b2WorldId world_id)
Creates the object's physical body in the simulation.
Definition robot.cpp:177
int16_t angular_bias
Definition robot.h:441
void register_stop_watch(time_reference_t *sw)
Registers a stop watch with the robot.
Definition robot.cpp:199
void receive_message(message_t *const message, PogobotObject *source)
Receive a message from another robot.
Definition robot.cpp:619
bool show_lateral_leds
Whether to render lateral LEDs.
Definition robot.h:275
float max_angular_speed
Definition robot.h:413
void disable_stop_watches()
Disables all registered stop watches.
Definition robot.cpp:209
void(* user_step)(void)
Pointer to a user-defined step function.
Definition robot.h:210
void send_to_neighbors(ir_direction dir, short_message_t *const message)
Sends a short message to neighboring robots.
Definition robot.cpp:583
uint32_t nb_msgs_sent
Counter for messages sent.
Definition robot.h:234
virtual void set_motor(motor_id motor, int speed) override
Updates the motor speed of the robot and recalculates its velocities. Pogobjects do not move,...
Definition robot.h:586
virtual void render_communication_channels(SDL_Renderer *, b2WorldId) const override
Renders the communication channels originating from this robot.
Definition robot.h:621
virtual b2Vec2 get_IR_emitter_position(ir_direction dir) const override
Retrieves the IR emitters current positions.
Definition robot.cpp:803
virtual bool is_tangible() const override
Returns whether this object is tangible (e.g. collisions, etc) or not.
Definition robot.h:626
Pogowall(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, std::string const &_category="robots")
Definition robot.cpp:767
virtual void move(float x, float y, float theta=NAN) override
Move the object to a given coordinate.
Definition robot.h:635
virtual void render(SDL_Renderer *, b2WorldId) const override
Renders the robot on the given SDL renderer.
Definition robot.h:613
virtual float get_IR_emitter_angle(ir_direction dir) const override
World-frame bearing of the chosen IR emitter.
Definition robot.cpp:807
Class representing the simulation environment.
Definition simulator.h:43
std::vector< std::vector< b2Vec2 > > arena_polygons_t
Definition geometry.h:13
PogobotObject * current_robot
Definition robot.cpp:26
uint64_t sim_starting_time_microseconds
Definition robot.cpp:29
MsgSuccessRate * msg_success_rate_factory(Configuration const &config)
Factory of MsgSuccessRate, from a given configuration.
Definition robot.cpp:64
ShapeType
Enumeration to select the shape type of the robot's body.
Definition robot.h:32
@ Ellipse
Definition robot.h:34
@ Circle
Definition robot.h:33
@ Polygon
Definition robot.h:35
uint64_t get_current_time_microseconds()
Retrieves the current time in microseconds.
Definition spogobot.cpp:67
std::string log_current_robot()
Returns a log string for the current robot.
Definition spogobot.cpp:85
std::unique_ptr< Simulation > simulation
Global simulation instance.
Definition simulator.cpp:74
ir_direction
Definition spogobot.h:148
@ ir_all
Definition spogobot.h:153
motor_id
Definition spogobot.h:619
b2BodyId body_id
Definition robot.h:644
b2JointId joint_id
Definition robot.h:645
Definition spogobot.h:205
Definition spogobot.h:238
Definition spogobot.h:877