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

Class representing a simulated Membrane, with a pogowall on each side. More...

#include <robot.h>

Inheritance diagram for MembraneObject:
Pogowall PogobotObject PhysicalObject Object

Classes

struct  Dot
struct  Joint

Public Member Functions

 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")
 MembraneObject (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 set_motor (motor_id motor, int speed) override
 Updates the motor speed of the robot and recalculates its velocities. Pogobjects do not move, so this method will always set the motors to 0.
virtual b2Vec2 get_position () const override
 Retrieves the object's current position.
virtual void render (SDL_Renderer *, b2WorldId) const override
 Renders the robot on the given SDL renderer.
virtual bool is_tangible () const override
 Returns whether this object is tangible (e.g. collisions, etc) or not.
virtual void move (float x, float y, float theta=NAN) override
 Move the object to a given coordinate.
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.
Public Member Functions inherited from Pogowall
 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")
 Pogowall (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 b2Vec2 get_IR_emitter_position (ir_direction dir) const override
 Retrieves the IR emitters current positions.
virtual float get_IR_emitter_angle (ir_direction dir) const override
 World-frame bearing of the chosen IR emitter.
virtual void render_communication_channels (SDL_Renderer *, b2WorldId) const override
 Renders the communication channels originating from this robot.
Public Member Functions inherited from 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)
 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 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.
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.
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.

Protected Member Functions

void create_robot_body (b2WorldId world_id)
 Creates the object's physical body in the simulation.
virtual void parse_configuration (Configuration const &config, Simulation *simulation) override
 Parse a provided configuration and set associated members values.
void make_distance_joint (b2WorldId world_id, b2BodyId a, b2BodyId b, float stiffness_scale=1.0f)
Protected Member Functions inherited from PogobotObject
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 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

int num_dots
std::vector< size_t > size_contours
float dot_radius
int cross_span
float stiffness
std::string colormap
std::vector< Dotdots
std::vector< Jointjoints
Protected Attributes inherited from PogobotObject
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.

Additional Inherited Members

Public Attributes inherited from PogobotObject
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.

Detailed Description

Class representing a simulated Membrane, with a pogowall on each side.

Constructor & Destructor Documentation

◆ MembraneObject() [1/2]

MembraneObject::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" )

Initializes a new Pogobject 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).
_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
_num_dotsHow many dots (≈ vertices) the membrane should have.
_dot_radiusPhysical radius for each dot (Box2D units, not pixels).
_cross_spanConnect every i‑th neighbour to stiffen the sheet (≥ 1).
_stiffnessThe stiffness of the joints.
_colormapName of the colormap to use to set the color of the object
_categoryName of the category of the object.

◆ MembraneObject() [2/2]

MembraneObject::MembraneObject ( 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 MembraneObject::create_robot_body ( b2WorldId world_id)
protected

Creates the object's physical body in the simulation.

Parameters
world_idThe Box2D world identifier.

◆ generate_contours()

arena_polygons_t MembraneObject::generate_contours ( std::size_t points_per_contour = 0) const
overridevirtual

Return one or more polygonal contours that represent the current geometry of the object.

Parameters
points_per_contourDesired number of vertices for each contour (a rectangle has one contour, a disk has one, an arena may have many – one per wall). If this value is 0, the function will determine automatically the best number of points to represent the shape.
Returns
arena_polygons_t A vector of closed polygons (counter‑clockwise, last vertex different from the first – the caller may close the loop if needed).

Reimplemented from PhysicalObject.

◆ get_position()

b2Vec2 MembraneObject::get_position ( ) const
overridevirtual

Retrieves the object's current position.

Returns the position of the object's physical body as a Box2D vector.

Returns
b2Vec2 The current position.

Reimplemented from PhysicalObject.

◆ is_tangible()

virtual bool MembraneObject::is_tangible ( ) const
inlineoverridevirtual

Returns whether this object is tangible (e.g. collisions, etc) or not.

Reimplemented from Pogowall.

◆ make_distance_joint()

void MembraneObject::make_distance_joint ( b2WorldId world_id,
b2BodyId a,
b2BodyId b,
float stiffness_scale = 1.0f )
protected

◆ move()

void MembraneObject::move ( float x,
float y,
float theta = NAN )
overridevirtual

Move the object to a given coordinate.

Parameters
xX coordinate.
yY coordinate.
thetaOrientation, in rad.

Reimplemented from Pogowall.

◆ parse_configuration()

void MembraneObject::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 PogobotObject.

◆ render()

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

Renders the robot on the given SDL renderer.

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

Reimplemented from Pogowall.

◆ set_motor()

virtual void MembraneObject::set_motor ( motor_id motor,
int speed )
inlineoverridevirtual

Updates the motor speed of the robot and recalculates its velocities. Pogobjects do not move, so this method will always set the motors to 0.

Parameters
motorThe identifier of the motor to update.
speed(Ignored) speed value for the selected motor.

Reimplemented from Pogowall.

Member Data Documentation

◆ colormap

std::string MembraneObject::colormap
protected

◆ cross_span

int MembraneObject::cross_span
protected

◆ dot_radius

float MembraneObject::dot_radius
protected

◆ dots

std::vector<Dot> MembraneObject::dots
protected

◆ joints

std::vector<Joint> MembraneObject::joints
protected

◆ num_dots

int MembraneObject::num_dots
protected

◆ size_contours

std::vector<size_t> MembraneObject::size_contours
protected

◆ stiffness

float MembraneObject::stiffness
protected

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