Army ant simulation
Public Member Functions | Public Attributes | List of all members
Robot Class Reference

#include <Robot.h>

Public Member Functions

 Robot (b2World *world, config::sRobot robotParameters, double posX, double posY, double angle=0)
 
void createBody (b2World *world, config::sRobot m_robotParameters, double posX, double posY, double angle=0)
 
void drawBody (sf::RenderWindow &window, double m_to_pix)
 
void drawJoint (sf::RenderWindow &window, double m_to_px)
 
void drawGripJoint (sf::RenderWindow &window, double m_to_px)
 
void moveBodyWithMotor ()
 
void moveBodyWithForce ()
 
void moveBodyWithImpulse ()
 
void turnOffMotor (side s)
 
void blockMotorRotation (side s)
 
void allowMotorRotation (side s)
 
void limitMotorRotation (side s, double limit_angle_rad)
 
void setState (e_state state)
 
e_state getState ()
 
b2Body * getBody ()
 
b2Body * getWheel (side s)
 
b2PrismaticJointDef getJointDef (side s)
 
void grip (b2Contact *contact, b2Body *otherBody, double m_to_px)
 
void gripGroundFromPos ()
 
bool gripSide (b2Contact *contact, b2Body *otherBody, double m_to_px)
 
bool contactOnGripSide (b2Contact *contact)
 
void setContact (bool contact)
 
bool isContact ()
 
void setDelay (int delay)
 
int getDelay ()
 
bool checkGripp (side s)
 
bool isGrabbed ()
 
int nbJoint (side s)
 
void incrementNbJoint (side s)
 
void resetNbJoint (side s)
 
b2RevoluteJoint * getMotor (side s)
 
void destroyBody ()
 
double getBodyLength ()
 
void setSpeed (double speed)
 
bool isReady ()
 
bool isMoving ()
 
void setId (int id)
 
int getId ()
 
b2Vec2 getPosition ()
 
double getAngle ()
 

Public Attributes

side m_movingSide = RIGHT
 
bool m_ready = false
 
bool m_moving = false
 
bool m_start = true
 
bool m_pushing = false
 
bool m_isGrabbed = false
 
double m_referenceAngle = -PI
 
double m_referenceAngleJoint = 0
 
int m_bridgeAge = 0
 
int m_age = 0
 
int m_pushing_delay = 0
 
b2PrismaticJoint * m_previousGripJoint = nullptr
 
b2PrismaticJoint * m_currentGripJoint = nullptr
 

Detailed Description

A Robot object is a set of physical properties (body, fixture, joints) and graphical features that describes the robot. This features are synchronized and the robot is controlled by proper member functions. Those member functions allow to control the grip creation and the robot movement at the joint level.

Definition at line 40 of file Robot.h.

Member Function Documentation

◆ allowMotorRotation()

void Robot::allowMotorRotation ( side  s)

allowMotorRotation, remove the rotation limit and keep the motor active

Parameters
sis the motor side can take LEFT or RIGHT value

Definition at line 564 of file Robot.cpp.

Here is the caller graph for this function:

◆ blockMotorRotation()

void Robot::blockMotorRotation ( side  s)

blockMotorRotation keep the motor enable but set an infinitesimal rotation limit and the speed to 0 in order to block totally the rotation

Parameters
sis the motor side can take LEFT or RIGHT value

Definition at line 522 of file Robot.cpp.

◆ checkGripp()

bool Robot::checkGripp ( side  s)

Check if the robot is currently grabbing something (gripper on)

Parameters
sideof the gripper can be either LEFT or RIGHT
Returns
true if the gripper on the side is active

Definition at line 902 of file Robot.cpp.

◆ createBody()

void Robot::createBody ( b2World *  world,
config::sRobot  m_robotParameters,
double  posX,
double  posY,
double  angle = 0 
)

Create the box2D body of the robot and attach it to the world

Parameters
worldbox2D world defined in the main program
robotParametersstructure containing the robot parameters: only the body length and speed have to be defined
posX,posY: initial position of the robot in this world in meters
angle: initial angle of the robot in this world in rad

Definition at line 55 of file Robot.cpp.

◆ destroyBody()

void Robot::destroyBody ( )

Destroy the Box2D bodies composing the robot.

Definition at line 1093 of file Robot.cpp.

◆ drawBody()

void Robot::drawBody ( sf::RenderWindow &  window,
double  m_to_pix 
)

Use SFML to to draw the body of the robot on the window

Parameters
windowactive SFML window
m_to_pixis the conversion factor used to transform the meters to pixels

Definition at line 142 of file Robot.cpp.

◆ drawGripJoint()

void Robot::drawGripJoint ( sf::RenderWindow &  window,
double  m_to_px 
)

Use SFML to to draw the robot's grippers on the window

Parameters
windowactive SFML window
m_to_pixis the conversion factor used to transform the meters to pixels

Definition at line 233 of file Robot.cpp.

◆ drawJoint()

void Robot::drawJoint ( sf::RenderWindow &  window,
double  m_to_px 
)

Use SFML to to draw all the joints of the robot on the window

Parameters
windowactive SFML window
m_to_pixis the conversion factor used to transform the meters to pixels

Definition at line 303 of file Robot.cpp.

◆ getAngle()

double Robot::getAngle ( )

Get the robot angle (angle of the robot body) in rad respectively to the original angle. This angle might require to be processed to be comprised between 0 and 2Pi

Returns
the angle of the robot (rad)

Definition at line 1037 of file Robot.cpp.

Here is the caller graph for this function:

◆ getBody()

b2Body * Robot::getBody ( )

Get the Box2D body part representing the attach between the robot's wheels

Returns
a pointer on the body of the attach between the two wheels

Definition at line 1041 of file Robot.cpp.

Here is the caller graph for this function:

◆ getBodyLength()

double Robot::getBodyLength ( )
Returns
the body length of the robot in meter (and not pixels)

Definition at line 1044 of file Robot.cpp.

◆ getDelay()

int Robot::getDelay ( )

Get the current robot's delay as a number of iteration left for the robot before being able to be ready.

Returns
the current robot's delay before being ready

Definition at line 1048 of file Robot.cpp.

Here is the caller graph for this function:

◆ getId()

int Robot::getId ( )
Returns
the value of the robot unique id stored in m_id

Definition at line 1053 of file Robot.cpp.

Here is the caller graph for this function:

◆ getJointDef()

b2PrismaticJointDef Robot::getJointDef ( side  s)

get the box2D definition of the prismatic joint used to create the gripper, this definition can then be used to create the actual grip joint

Parameters
sis the side of the robot (relative to the robot referential), can be either LEFT or RIGHT

Definition at line 1056 of file Robot.cpp.

Here is the caller graph for this function:

◆ getMotor()

b2RevoluteJoint * Robot::getMotor ( side  s)

Get a pointer on the Box2D joint between a foot and the robot body that act as the motor.

Parameters
sside of the robot
Returns
a pointer on the Box2D joint that act as the motor of the given side s

Definition at line 982 of file Robot.cpp.

◆ getPosition()

b2Vec2 Robot::getPosition ( )

Get the robot center position (located at the center of the robot body) in m respectively to the origin of the Box2D world (top left corner)

Returns
a b2Vec2 vector with the x and y coordinates of the robot position (m)

Definition at line 1065 of file Robot.cpp.

Here is the caller graph for this function:

◆ getState()

e_state Robot::getState ( )

Access the current robot state

Returns
the e_state value defining the robot state, can take two values WALK or BRIDGE

Definition at line 1069 of file Robot.cpp.

Here is the caller graph for this function:

◆ getWheel()

b2Body * Robot::getWheel ( side  s)

Get the Box2D body part representing one of the two wheels of the robot

Parameters
sis the side of the robot (relative to the robot referential), can be either LEFT or RIGHT that define which wheel will be returned
Returns
a pointer on the box2D wheel on the s side

Definition at line 1072 of file Robot.cpp.

Here is the caller graph for this function:

◆ grip()

void Robot::grip ( b2Contact *  contact,
b2Body *  otherBody,
double  m_to_px 
)

Create the grip joint definition as a Box2D prismatic joint definition object. gripGroundFromPos is used when one needs to create a static robot: It directly create the joint object without the intermediate definition.

Parameters
contactbox2D contact object usually obtained via the contact listener
otherBodybox2D body in contact with the robot
m_to_pxscale conversion between box2d and sfml coordinates, used to draw the contact point

update m_leftGripJointDef and m_rightGripJointDef depending on the contact side

Definition at line 575 of file Robot.cpp.

◆ gripGroundFromPos()

void Robot::gripGroundFromPos ( )

Create the grip joint definition as a Box2D prismatic joint definition object. gripGroundFromPos is used when one needs to create a static robot: It directly create the joint object without the intermediate definition.

Parameters
contactbox2D contact object usually obtained via the contact listener
otherBodybox2D body in contact with the robot
m_to_pxscale conversion between box2d and sfml coordinates, used to draw the contact point

update m_leftGripJointDef and m_rightGripJointDef depending on the contact side

Definition at line 729 of file Robot.cpp.

◆ gripSide()

bool Robot::gripSide ( b2Contact *  contact,
b2Body *  otherBody,
double  m_to_px 
)

Create the grip joint definition as a Box2D prismatic joint definition object. gripGroundFromPos is used when one needs to create a static robot: It directly create the joint object without the intermediate definition.

Parameters
contactbox2D contact object usually obtained via the contact listener
otherBodybox2D body in contact with the robot
m_to_pxscale conversion between box2d and sfml coordinates, used to draw the contact point

update m_leftGripJointDef and m_rightGripJointDef depending on the contact side

Definition at line 641 of file Robot.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ incrementNbJoint()

void Robot::incrementNbJoint ( side  s)

Methods to increment the number of grip joints of the robot of a given side, this number should not exceed 1

Parameters
sis the side of the robot: can be either LEFT or RIGHT

Definition at line 999 of file Robot.cpp.

Here is the caller graph for this function:

◆ isContact()

bool Robot::isContact ( )
Returns
true if the robot has just initiated a contact and didn't create a joint yet.

Definition at line 1082 of file Robot.cpp.

Here is the caller graph for this function:

◆ isGrabbed()

bool Robot::isGrabbed ( )

Check if the robot is currently grabbed by another robot

Returns
true if it is

Definition at line 938 of file Robot.cpp.

Here is the caller graph for this function:

◆ isMoving()

bool Robot::isMoving ( )
Returns
true if the robot is moving, false otherwise

Definition at line 1085 of file Robot.cpp.

Here is the caller graph for this function:

◆ isReady()

bool Robot::isReady ( )
Returns
true if the robot is ready to move, false otherwise

Definition at line 1088 of file Robot.cpp.

◆ limitMotorRotation()

void Robot::limitMotorRotation ( side  s,
double  limit_angle_rad 
)

Limit the motor rotation between +/- a given limit angle around the reference angle. The reference angle is defined by the member attribute m_referenceAngleJoint

Parameters
sis the motor side can take LEFT or RIGHT value
limit_angle_radis the value that define the limit angle in rad

Definition at line 543 of file Robot.cpp.

◆ moveBodyWithForce()

void Robot::moveBodyWithForce ( )

Second of the three different methods to move the robot body in the clockwise direction, The parameters might need to be adapted to fit the simulation parameters (object size, scale, weight...) The speed is applied via the m_angularSpeed class member (except for the force The impulse method uses a proportional action to reach the angular target speed

Definition at line 470 of file Robot.cpp.

Here is the call graph for this function:

◆ moveBodyWithImpulse()

void Robot::moveBodyWithImpulse ( )

Third of the three different methods to move the robot body in the clockwise direction, The parameters might need to be adapted to fit the simulation parameters (object size, scale, weight...) The speed is applied via the m_angularSpeed class member (except for the force The impulse method uses a proportional action to reach the angular target speed

Definition at line 495 of file Robot.cpp.

Here is the call graph for this function:

◆ moveBodyWithMotor()

void Robot::moveBodyWithMotor ( )

First of the three different methods to move the robot body in the clockwise direction, This is the one used in the current implementation, the other two functions are alternative way to move the body but are currently not used The speed is applied via the m_angularSpeed class member (except for the force The impulse method uses a proportional action to reach the angular target speed

Definition at line 442 of file Robot.cpp.

◆ nbJoint()

int Robot::nbJoint ( side  s)

Methods to check the number of grip joints of the robot of a given side, this number should not exceed 1

Parameters
sis the side of the robot: can be either LEFT or RIGHT

Definition at line 991 of file Robot.cpp.

Here is the caller graph for this function:

◆ resetNbJoint()

void Robot::resetNbJoint ( side  s)

Methods to reset the number of grip joints of the robot of a given side, this number should not exceed 1

Parameters
sis the side of the robot: can be either LEFT or RIGHT

Definition at line 1007 of file Robot.cpp.

Here is the caller graph for this function:

◆ setContact()

void Robot::setContact ( bool  contact)

Used in the contact listener to update the m_contact flag if the robot initiate the contact

update m_contact

Definition at line 1020 of file Robot.cpp.

Here is the caller graph for this function:

◆ setDelay()

void Robot::setDelay ( int  delay)

setter and getter of the delay m_delay parameter

Parameters
delayis the number of iteration needed to be able to turn the motors on again

Definition at line 1023 of file Robot.cpp.

Here is the caller graph for this function:

◆ setId()

void Robot::setId ( int  id)

Set the unique id of the robot. Usually it corresponds to the number of robot created (as opposed to number of active robots)

Parameters
idthe unique id of the robot

update m_id

Definition at line 1027 of file Robot.cpp.

◆ setSpeed()

void Robot::setSpeed ( double  speed)

the rotational robot speed, if the moveBodyWithMotor is used, the speed is in rad/s

Definition at line 1030 of file Robot.cpp.

◆ setState()

void Robot::setState ( e_state  state)

Set the current robot state

Parameters
stateis the new robot state, can take three values WALK or BRIDGE

Definition at line 1033 of file Robot.cpp.

Here is the caller graph for this function:

◆ turnOffMotor()

void Robot::turnOffMotor ( side  s)

Turn off wheels' motor turnOffMotor disable the motor, it means that the rotation is freed

Parameters
sis the motor side can take LEFT or RIGHT value

Definition at line 513 of file Robot.cpp.

Member Data Documentation

◆ m_previousGripJoint

b2PrismaticJoint* Robot::m_previousGripJoint = nullptr

Pointers on the two possible gripping joints

Definition at line 287 of file Robot.h.


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