3 #include "measurement.h"
8 b2Fixture * GetSensor(b2Body * body);
14 b2Body * GetDisturbance(b2World * x);
23 bool overlaps(b2Body * robot,
const Disturbance *
const);
33 bool overlaps(
const b2PolygonShape& box,
const Disturbance *
const d,
const b2Transform& robot_pose=b2Transform_zero);
39 void world_cleanup(b2World & _world);
51 b2Transform start=b2Transform_zero;
53 Direction direction= DEFAULT;
55 AffordanceIndex affordance=NONE;
65 float linearSpeed=WHEEL_SPEED_DEFAULT*2;
68 float R=WHEEL_SPEED_DEFAULT;
69 float L=WHEEL_SPEED_DEFAULT;
76 void init(Direction& direction){
78 case Direction::DEFAULT:
79 L=WHEEL_SPEED_DEFAULT;
80 R=WHEEL_SPEED_DEFAULT;
86 case Direction::RIGHT:
99 void setVelocities(
const float & l,
const float &r){
100 omega = (MAX_SPEED*(r-l)/BETWEEN_WHEELS);
101 linearSpeed = MAX_SPEED*(l+r)/2;
105 b2Vec2 getLinearVelocity(
const float &dt=1)
const{
107 velocity.x = linearSpeed *cos(omega)*dt;
108 velocity.y = linearSpeed *sin(omega)*dt;
118 return b2Transform(getLinearVelocity(dt), b2Rot(getOmega(dt)));
121 float getRWheelSpeed()
const{
125 float getLWheelSpeed()
const{
129 void setRWheelSpeed(
float f){
133 void setLWheelSpeed(
float f){
141 float getLinearSpeed(){
145 float getOmega(
const float &dt=1)
const{
155 float getOmega(
const float l,
const float r,
float dt=1)
const{
156 float result = (MAX_SPEED*(r-l)/BETWEEN_WHEELS)*TURN_FRICTION*dt;
160 void setOmega(
const float &o){
164 void setLinearSpeed(
const float & s){
178 std::vector <b2Body*> collisions;
182 void BeginContact(b2Contact * contact) {
183 b2Fixture * fixtureA= contact->GetFixtureA();
184 b2Fixture * fixtureB= contact->GetFixtureB();
185 b2BodyUserData bodyData = fixtureA->GetBody()->GetUserData();
186 if (bodyData.pointer==ROBOT_FLAG) {
187 b2Body * other = contact->GetFixtureB()->GetBody();
188 if (fixtureA->IsSensor()){
189 if (other->GetUserData().pointer==DISTURBANCE_FLAG){
194 if (fixtureB->IsSensor()){
197 collisions.push_back(other);
199 bodyData = fixtureB->GetBody()->GetUserData();
200 if (bodyData.pointer==ROBOT_FLAG) {
201 b2Body * other = contact->GetFixtureA()->GetBody();
202 if (fixtureB->IsSensor()){
203 if (other->GetUserData().pointer==DISTURBANCE_FLAG){
208 if (fixtureA->IsSensor()){
211 collisions.push_back(other);
215 std::vector <b2Body*> get_collisions(){
225 AffordanceIndex getAffIndex(){
239 Direction
H(
Disturbance ob, Direction d,
bool topDown=0);
269 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));
280 EndedResult checkEnded(
const State& n, Direction dir=UNDEFINED,
bool relax=
false, std::pair<bool,b2Transform> use_start= std::pair <bool,b2Transform>(1, b2Transform_zero));
291 bool checkEnded(
const b2PolygonShape &box,
const b2Transform& robot_pose=b2Transform_zero,
Disturbance * dist_obs=NULL );
294 start = b2Transform(b2Vec2(0.0, 0.0), b2Rot(0));
296 action.init(direction);
301 action.init(direction);
304 Task(
Disturbance ob, Direction d, b2Transform _start=b2Transform(b2Vec2(0.0, 0.0), b2Rot(0.0)),
bool topDown=0){
307 affordance=disturbance.getAffIndex();
308 direction =
H(disturbance, d, topDown);
309 action.init(direction);
350 b2Transform
from_Di(
const b2Transform * custom_start=NULL,
Disturbance * d_obs=NULL);
352 void set_change(
bool b){
367 return change || motorStep==0;
383 void setMotorStep(
int i){
387 int getMotorStep()
const{
return motorStep;}
389 b2Transform getStart(){
393 b2Transform& getStartRef(){
397 Direction get_direction(){
401 void set_direction(Direction d){
409 bool isTurnFinished(
const b2Transform & robotTransform, Direction dir);
Definition: measurement.h:67
Definition: configurator.h:17
Definition: measurement.h:76
Used to find collisions in the Box2D simulation.
Definition: task.h:176
A closed hybrid control loop. It has an initial disturbance representing the continuous state and a d...
Definition: task.h:45
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:169
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:231
bool endCriteria_met(Angle &a, Distance &d)
Returns true if the endCriteria is met based on.
Definition: task.cpp:386
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:202
simResult bumping_that(b2World &_world, int iteration, b2Body *, float remaining=SIM_DURATION)
Executes this task in a Box2D simulation.
Definition: task.cpp:57
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:353
Disturbance * get_disturbance_ptr()
Get a pointer to the disturbance.
Definition: task.h:375
EndCriteria & getEndCriteria()
Returns a REFERENCE to the endCriteria.
Definition: task.h:331
bool is_over()
If task has finished executing.
Definition: task.h:366
Definition: disturbance.h:114
Defines the end criteria for a Task, i.e. when it is considered to be finished.
Definition: measurement.h:88
Provides information on whether a Task has ended and with what heuristic -estimated- cost (chi) and p...
Definition: measurement.h:122
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:63
float getOmega(const float l, const float r, float dt=1) const
Uses kinematic model to calculate angle.
Definition: task.h:155
b2Transform getTransform(const float &dt=1) const
Gets the ROBOT's displacement in the world frame after dt seconds.
Definition: task.h:117
Definition: disturbance.h:270