3 #include "measurement.h"
5 extern const bool DEBUG;
10 b2Fixture * GetSensor(b2Body * body);
16 b2Body * GetDisturbance(b2World * x);
25 bool overlaps(b2Body * robot,
const Disturbance *
const);
35 bool overlaps(
const b2PolygonShape& box,
const Disturbance *
const d,
const b2Transform& robot_pose=b2Transform_zero);
41 void world_cleanup(b2World & _world);
51 char collisionFile[50];
54 b2Transform start=b2Transform_zero;
56 Direction direction= DEFAULT;
58 AffordanceIndex affordance=NONE;
68 float linearSpeed=WHEEL_SPEED_DEFAULT*2;
71 float R=WHEEL_SPEED_DEFAULT;
72 float L=WHEEL_SPEED_DEFAULT;
79 void init(Direction& direction){
81 case Direction::DEFAULT:
82 L=WHEEL_SPEED_DEFAULT;
83 R=WHEEL_SPEED_DEFAULT;
89 case Direction::RIGHT:
102 void setVelocities(
const float & l,
const float &r){
103 omega = (MAX_SPEED*(r-l)/BETWEEN_WHEELS);
104 linearSpeed = MAX_SPEED*(l+r)/2;
108 b2Vec2 getLinearVelocity(
const float &dt=1)
const{
110 velocity.x = linearSpeed *cos(omega)*dt;
111 velocity.y = linearSpeed *sin(omega)*dt;
121 return b2Transform(getLinearVelocity(dt), b2Rot(getOmega(dt)));
124 float getRWheelSpeed()
const{
128 float getLWheelSpeed()
const{
132 void setRWheelSpeed(
float f){
136 void setLWheelSpeed(
float f){
144 float getLinearSpeed(){
148 float getOmega(
const float &dt=1)
const{
158 float getOmega(
const float l,
const float r,
float dt=1)
const{
159 float result = (MAX_SPEED*(r-l)/BETWEEN_WHEELS)*TURN_FRICTION*dt;
163 void setOmega(
const float &o){
167 void setLinearSpeed(
const float & s){
181 std::vector <b2Body*> collisions;
185 void BeginContact(b2Contact * contact) {
186 b2Fixture * fixtureA= contact->GetFixtureA();
187 b2Fixture * fixtureB= contact->GetFixtureB();
188 b2BodyUserData bodyData = fixtureA->GetBody()->GetUserData();
189 if (bodyData.pointer==ROBOT_FLAG) {
190 b2Body * other = contact->GetFixtureB()->GetBody();
191 if (fixtureA->IsSensor()){
192 if (other->GetUserData().pointer==DISTURBANCE_FLAG){
197 if (fixtureB->IsSensor()){
200 collisions.push_back(other);
202 bodyData = fixtureB->GetBody()->GetUserData();
203 if (bodyData.pointer==ROBOT_FLAG) {
204 b2Body * other = contact->GetFixtureA()->GetBody();
205 if (fixtureB->IsSensor()){
206 if (other->GetUserData().pointer==DISTURBANCE_FLAG){
211 if (fixtureA->IsSensor()){
214 collisions.push_back(other);
218 std::vector <b2Body*> get_collisions(){
228 AffordanceIndex getAffIndex(){
242 Direction
H(
Disturbance ob, Direction d,
bool topDown=0);
272 EndedResult checkEnded(b2Transform robotTransform= b2Transform_zero, Direction dir=UNDEFINED,
bool relax=0, b2Body* robot=NULL, std::pair<bool,b2Transform> use_start= std::pair <bool,b2Transform>(1, b2Transform_zero));
283 EndedResult checkEnded(
const State& n, Direction dir=UNDEFINED,
bool relax=
false, std::pair<bool,b2Transform> use_start= std::pair <bool,b2Transform>(1, b2Transform_zero));
294 bool checkEnded(
const b2PolygonShape &box,
const b2Transform& robot_pose=b2Transform_zero,
Disturbance * dist_obs=NULL );
297 start = b2Transform(b2Vec2(0.0, 0.0), b2Rot(0));
299 action.init(direction);
304 action.init(direction);
307 Task(
Disturbance ob, Direction d, b2Transform _start=b2Transform(b2Vec2(0.0, 0.0), b2Rot(0.0)),
bool topDown=0){
310 affordance=disturbance.getAffIndex();
311 direction =
H(disturbance, d, topDown);
312 action.init(direction);
353 b2Transform
from_Di(
const b2Transform * custom_start=NULL,
Disturbance * d_obs=NULL);
355 void set_change(
bool b){
370 return change || motorStep==0;
386 void setMotorStep(
int i){
390 int getMotorStep()
const{
return motorStep;}
392 b2Transform getStart(){
396 b2Transform& getStartRef(){
400 Direction get_direction(){
404 void set_direction(Direction d){
412 bool isTurnFinished(
const b2Transform & robotTransform, Direction dir);
Definition: measurement.h:71
Definition: configurator.h:17
Definition: measurement.h:80
Used to find collisions in the Box2D simulation.
Definition: task.h:179
A closed hybrid control loop. It has an initial disturbance representing the continuous state and a d...
Definition: task.h:47
Direction H(Disturbance ob, Direction d, bool topDown=0)
Agent transfer function H which generates a motor output (Action) in response to a disturbance.
Definition: task.cpp:178
EndedResult checkEnded(b2Transform robotTransform=b2Transform_zero, Direction dir=UNDEFINED, bool relax=0, b2Body *robot=NULL, std::pair< bool, b2Transform > use_start=std::pair< bool, b2Transform >(1, b2Transform_zero))
Check if this task has ended based on state information (default are info for the task which calls th...
Definition: task.cpp:240
bool endCriteria_met(Angle &a, Distance &d)
Returns true if the endCriteria is met based on.
Definition: task.cpp:394
void setEndCriteria(const Angle &angle=SAFE_ANGLE, const Distance &distance=BOX2DRANGE)
Sets the end criteria for this task (bounds of the Flow condition). Angle is a valid measurement for ...
Definition: task.cpp:211
simResult bumping_that(b2World &_world, int iteration, b2Body *, float remaining=SIM_DURATION)
Executes this task in a Box2D simulation.
Definition: task.cpp:58
b2Transform from_Di(const b2Transform *custom_start=NULL, Disturbance *d_obs=NULL)
Returns a b2Transform expressing the pose of the disturbance relative to the robot in the robot's loc...
Definition: task.cpp:361
Disturbance * get_disturbance_ptr()
Get a pointer to the disturbance.
Definition: task.h:378
EndCriteria & getEndCriteria()
Returns a REFERENCE to the endCriteria.
Definition: task.h:334
bool is_over()
If task has finished executing.
Definition: task.h:369
Definition: disturbance.h:113
Defines the end criteria for a Task, i.e. when it is considered to be finished.
Definition: measurement.h:92
Provides information on whether a Task has ended and with what heuristic -estimated- cost (chi) and p...
Definition: measurement.h:126
Hybrid states in the transition system.
Definition: graphTools.h:69
The motor instructions generated by the control strategy used in this tasks.
Definition: task.h:66
float getOmega(const float l, const float r, float dt=1) const
Uses kinematic model to calculate angle.
Definition: task.h:158
b2Transform getTransform(const float &dt=1) const
Gets the ROBOT's displacement in the world frame after dt seconds.
Definition: task.h:120
Definition: disturbance.h:269