|
Army ant simulation
|
#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 |
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.
| void Robot::allowMotorRotation | ( | side | s | ) |
| void Robot::blockMotorRotation | ( | side | s | ) |
| bool Robot::checkGripp | ( | side | s | ) |
| 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
| world | box2D world defined in the main program |
| robotParameters | structure 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 |
| void Robot::destroyBody | ( | ) |
| void Robot::drawBody | ( | sf::RenderWindow & | window, |
| double | m_to_pix | ||
| ) |
| void Robot::drawGripJoint | ( | sf::RenderWindow & | window, |
| double | m_to_px | ||
| ) |
| void Robot::drawJoint | ( | sf::RenderWindow & | window, |
| double | m_to_px | ||
| ) |
| double Robot::getAngle | ( | ) |
| b2Body * Robot::getBody | ( | ) |
| double Robot::getBodyLength | ( | ) |
| int Robot::getDelay | ( | ) |
| int Robot::getId | ( | ) |
| 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
| s | is the side of the robot (relative to the robot referential), can be either LEFT or RIGHT |
Definition at line 1056 of file Robot.cpp.

| b2RevoluteJoint * Robot::getMotor | ( | side | s | ) |
| 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)
Definition at line 1065 of file Robot.cpp.

| e_state Robot::getState | ( | ) |
| b2Body * Robot::getWheel | ( | side | s | ) |
Get the Box2D body part representing one of the two wheels of the robot
| s | is the side of the robot (relative to the robot referential), can be either LEFT or RIGHT that define which wheel will be returned |
Definition at line 1072 of file Robot.cpp.

| 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.
| contact | box2D contact object usually obtained via the contact listener |
| otherBody | box2D body in contact with the robot |
| m_to_px | scale conversion between box2d and sfml coordinates, used to draw the contact point |
update m_leftGripJointDef and m_rightGripJointDef depending on the contact side
| 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.
| contact | box2D contact object usually obtained via the contact listener |
| otherBody | box2D body in contact with the robot |
| m_to_px | scale conversion between box2d and sfml coordinates, used to draw the contact point |
update m_leftGripJointDef and m_rightGripJointDef depending on the contact side
| 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.
| contact | box2D contact object usually obtained via the contact listener |
| otherBody | box2D body in contact with the robot |
| m_to_px | scale 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.


| void Robot::incrementNbJoint | ( | side | s | ) |
| bool Robot::isContact | ( | ) |
| bool Robot::isGrabbed | ( | ) |
| bool Robot::isMoving | ( | ) |
| bool Robot::isReady | ( | ) |
| 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
| s | is the motor side can take LEFT or RIGHT value |
| limit_angle_rad | is the value that define the limit angle in rad |
| 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.

| 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.

| 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
| int Robot::nbJoint | ( | side | s | ) |
| void Robot::resetNbJoint | ( | side | s | ) |
| void Robot::setContact | ( | bool | contact | ) |
| void Robot::setDelay | ( | int | delay | ) |
| void Robot::setId | ( | int | id | ) |
| void Robot::setSpeed | ( | double | speed | ) |
| void Robot::setState | ( | e_state | state | ) |
| void Robot::turnOffMotor | ( | side | s | ) |
| b2PrismaticJoint* Robot::m_previousGripJoint = nullptr |
1.8.14