13 #include "control_interface.h"
14 #include "task_controller.h"
28 std::thread * LIDAR_thread=NULL;
29 float simulationStep=2*std::max(ROBOT_HALFLENGTH, ROBOT_HALFWIDTH);
30 std::chrono::high_resolution_clock::time_point previousTimeScan;
32 std::vector<vertexDescriptor>m_plan, current_vertices;
35 CoordinateContainer data2fp;
36 TransitionSystem transitionSystem=TransitionSystem(1);
38 vertexDescriptor currentVertex=MOVING_VERTEX;
39 edgeDescriptor movingEdge=edgeDescriptor(), currentEdge=edgeDescriptor();
71 void addIteration(
int i=1){
76 void dummy_vertex(vertexDescriptor src);
87 void printPlan(std::vector <vertexDescriptor>* p=NULL);
99 std::pair<edgeDescriptor, bool>
addVertex(
const vertexDescriptor & src, vertexDescriptor &v1,
Edge edge=
Edge(),
bool topDown=0);
141 void update_graph(TransitionSystem& g,
const b2Transform & _deltaPose);
144 float approximate_angle(
const float &,
const Direction &,
const simResult::resultType &);
147 void adjust_goal_expectation();
150 void register_controller(
Controller * controller){
151 task_controller=controller;
155 return task_controller;
158 void register_tracker(
Tracker * _tracker){
159 if (!_tracker){
return;}
161 tracker->init(&controlGoal);
177 void register_planner(
Planner * _p){
181 void setSimulationStep(
float f){
185 void register_logger(
Logger * l){
193 static void MulT(
const b2Transform& B,
Task & task);
199 static void Mul(
const b2Transform& B,
Task &task);
223 return ExecutionInfo(currentVertex, gv, currentTask, controlGoal, been, m_plan);
239 Disturbance getDisturbance(TransitionSystem&g, vertexDescriptor v, b2World & world,
const Direction & dir,
const b2Transform& start);
252 void backtrack(std::vector <vertexDescriptor>& evaluation_q, std::vector <vertexDescriptor>&priority_q, std::set<vertexDescriptor>& closed, std::vector <vertexDescriptor>& plan_prov, vertexDescriptor module_src=MOVING_VERTEX, vertexDescriptor startRecycle=MOVING_VERTEX);
262 std::vector <vertexDescriptor>
splitTask(vertexDescriptor v, Direction d, vertexDescriptor src=TransitionSystem::null_vertex());
272 void propagateD(vertexDescriptor v1, vertexDescriptor v0, std::set<vertexDescriptor>*closed=NULL, StateMatcher::MATCH_TYPE match=StateMatcher::_FALSE);
275 void planPriority(TransitionSystem&, vertexDescriptor);
277 void adjust_simulated_task(
const vertexDescriptor&, TransitionSystem &,
Task*);
280 void adjust_rw_task(
const vertexDescriptor&, TransitionSystem &,
Task*,
const b2Transform &);
288 std::pair <edgeDescriptor, bool>
maxProbability(std::vector<edgeDescriptor> ev, TransitionSystem&);
301 VertexMatch
findMatch(
State s, Direction dir=Direction::UNDEFINED, StateMatcher::MATCH_TYPE match_type=StateMatcher::_TRUE,
StateDifference * _sd=NULL, std::vector <VertexMatch>*other_matches=NULL);
312 std::vector<vertexDescriptor>
explorer(vertexDescriptor v, TransitionSystem&g, b2World &w);
343 std::pair <edgeDescriptor, bool>
add_vertex_retro(vertexDescriptor &src, vertexDescriptor &v1,
Edge edge=
Edge(),
bool topDown=0);
346 std::vector <Direction>
getExploredDirections(vertexDescriptor v,
const std::vector<Direction>& directions);
357 void transitionMatrix(vertexDescriptor v, Direction d, vertexDescriptor src);
368 void applyTransitionMatrix(vertexDescriptor v0, Direction d,
bool ended, vertexDescriptor src, std::vector<vertexDescriptor>& plan_prov);
378 void addToPriorityQueue(vertexDescriptor v, std::vector<vertexDescriptor>& queue,
const std::set <vertexDescriptor>& closed);
382 void ts_cleanup(TransitionSystem &, std::vector <vertexDescriptor>&);
385 void shift_states(TransitionSystem &,
const std::vector<vertexDescriptor>&,
const b2Transform &);
388 vertexDescriptor get_explore_start(TransitionSystem &);
412 std::vector<Direction>::iterator
get_next_option(vertexDescriptor v, vertexDescriptor src, std::vector<vertexDescriptor> full_plan);
429 bool recycle_plan(vertexDescriptor v, vertexDescriptor &v0, vertexDescriptor & task_start, StateMatcher::MATCH_TYPE &matchType,
430 b2Transform & shift_start, b2Transform& sk_first_start, std::pair<edgeDescriptor, bool>&edge,
431 std::vector<vertexDescriptor> &plan_prov, Direction t_get_direction);
445 std::pair<State, Edge>
simulation_setup(b2World& w,
Task & t, vertexDescriptor v0, b2Transform shift, b2Transform &start, std::vector<Direction>v0_options);
462 bool matchToSafe(VertexMatch &match,
const std::vector<VertexMatch> &other_matches=std::vector<VertexMatch>());
476 std::pair<edgeDescriptor, bool>
setup_match_edge(VertexMatch &match, vertexDescriptor &v0, vertexDescriptor & v1,
const Edge& k, Direction direction,
bool changedMatch);
484 std::vector <vertexDescriptor>
task_vertices(vertexDescriptor v, std::pair<bool, edgeDescriptor>* ep=NULL);
494 std::vector <vertexDescriptor>
visitedOrVisitingEdge(
const std::vector <edgeDescriptor>& es, TransitionSystem& g, vertexDescriptor cv=TransitionSystem::null_vertex());
504 vertexDescriptor
getRecyclingStart(vertexDescriptor v, vertexDescriptor v1, vertexDescriptor taskStart);
511 std::vector <edgeDescriptor>
inEdges(vertexDescriptor v, Direction d = UNDEFINED);
513 bool closeVertex(std::set<vertexDescriptor> & closed, vertexDescriptor v);
525 std::pair<edgeDescriptor, bool>
addEdgeRetrospectively(vertexDescriptor v, vertexDescriptor &v1,
const State & s_tmp,std::pair<edgeDescriptor, bool> first_edge, Direction d,
float linearSpeed);
537 void correctQueue(std::vector<vertexDescriptor>& queue, vertexDescriptor v, vertexDescriptor startRecycle,
int planProvSize);
Configurator with long-range planning. It explores transitions out of a state until a DEFAULT Task is...
Definition: configurator.h:212
VertexMatch findMatch(State s, Direction dir=Direction::UNDEFINED, StateMatcher::MATCH_TYPE match_type=StateMatcher::_TRUE, StateDifference *_sd=NULL, std::vector< VertexMatch > *other_matches=NULL)
Searches transition System for a match to a state provided. Continuous states are matched,...
Definition: configurator.cpp:681
std::vector< vertexDescriptor > visitedOrVisitingEdge(const std::vector< edgeDescriptor > &es, TransitionSystem &g, vertexDescriptor cv=TransitionSystem::null_vertex())
Returns a visited edge if present, or if the current.
void reassign_direction(vertexDescriptor bestNext, Direction &direction)
Reassigns direction as the direction of the bext task to expand next in explorer.
Definition: configurator.cpp:983
std::pair< edgeDescriptor, bool > setup_match_edge(VertexMatch &match, vertexDescriptor &v0, vertexDescriptor &v1, const Edge &k, Direction direction, bool changedMatch)
Given a valid match, sets up the edge with the previous vertex Creates new edge if it doesn't exist,...
Definition: configurator.cpp:1012
void propagateD(vertexDescriptor v1, vertexDescriptor v0, std::set< vertexDescriptor > *closed=NULL, StateMatcher::MATCH_TYPE match=StateMatcher::_FALSE)
Propagate a disturbance backwards to all states representing the same task.
Definition: configurator.cpp:336
void pre_explore()
Prepares transitionsystem for exploration: clears all edges of q0 with states that aren't the current...
Definition: configurator.cpp:798
void explore_plan(b2World &) override
Explores and plan.
Definition: configurator.cpp:891
std::pair< edgeDescriptor, bool > add_vertex_now(const vertexDescriptor &src, vertexDescriptor &v1, Disturbance obs, Edge edge=Edge(), bool topDown=0)
Adds state after discovering it in exploration.
Definition: configurator.cpp:45
bool recycle_plan(vertexDescriptor v, vertexDescriptor &v0, vertexDescriptor &task_start, StateMatcher::MATCH_TYPE &matchType, b2Transform &shift_start, b2Transform &sk_first_start, std::pair< edgeDescriptor, bool > &edge, std::vector< vertexDescriptor > &plan_prov, Direction t_get_direction)
Assesses whether a previous plan can be recycled.
Definition: configurator.cpp:941
std::pair< edgeDescriptor, bool > addEdgeRetrospectively(vertexDescriptor v, vertexDescriptor &v1, const State &s_tmp, std::pair< edgeDescriptor, bool > first_edge, Direction d, float linearSpeed)
Adds edge retrospectively (used in split task)
Definition: configurator.cpp:1116
std::pair< bool, Direction > getOppositeDirection(Direction)
Definition: configurator.cpp:103
void backtrack(std::vector< vertexDescriptor > &evaluation_q, std::vector< vertexDescriptor > &priority_q, std::set< vertexDescriptor > &closed, std::vector< vertexDescriptor > &plan_prov, vertexDescriptor module_src=MOVING_VERTEX, vertexDescriptor startRecycle=MOVING_VERTEX)
Iterates through vertices, if they result in crash, it splits the tasks and recalculates evaluation f...
Definition: configurator.cpp:302
std::pair< State, Edge > simulation_setup(b2World &w, Task &t, vertexDescriptor v0, b2Transform shift, b2Transform &start, std::vector< Direction >v0_options)
Sets up for simulation.
Definition: configurator.cpp:973
Disturbance getDisturbance(TransitionSystem &g, vertexDescriptor v, b2World &world, const Direction &dir, const b2Transform &start)
Use attention window to find if any previously avoided obstacle is in the way of the goal,...
Definition: configurator.cpp:113
std::vector< edgeDescriptor > inEdges(vertexDescriptor v, Direction d=UNDEFINED)
Returns a vector of all the in-edges of vertex.
Definition: configurator.cpp:1069
ExecutionInfo package_info(vertexDescriptor gv=TransitionSystem::null_vertex(), bool been=false)
Package task/goal execution details into an Execution Info instance.
Definition: configurator.h:222
void correctQueue(std::vector< vertexDescriptor > &queue, vertexDescriptor v, vertexDescriptor startRecycle, int planProvSize)
Edits.
Definition: configurator.cpp:1130
std::vector< vertexDescriptor > splitTask(vertexDescriptor v, Direction d, vertexDescriptor src=TransitionSystem::null_vertex())
Split tasks into sub-states of fixed length.
Definition: configurator.cpp:250
void transitionMatrix(vertexDescriptor v, Direction d, vertexDescriptor src)
Definition: configurator.cpp:491
std::pair< edgeDescriptor, bool > maxProbability(std::vector< edgeDescriptor > ev, TransitionSystem &)
Return edge with maximum probablitit in a vector.
Definition: configurator.cpp:618
std::pair< edgeDescriptor, bool > add_vertex_retro(vertexDescriptor &src, vertexDescriptor &v1, Edge edge=Edge(), bool topDown=0)
Adds vertices retroactively (e.g. after a state is split)
Definition: configurator.cpp:53
void removeExploredTransitions(vertexDescriptor v)
Definition: configurator.cpp:484
std::vector< Direction > getExploredDirections(vertexDescriptor v, const std::vector< Direction > &directions)
Definition: configurator.cpp:470
std::vector< Direction >::iterator get_next_option(vertexDescriptor v, vertexDescriptor src, std::vector< vertexDescriptor > full_plan)
Returns an iterator to the next option representing a discrete Task transition. If v is in the plan,...
bool matchToSafe(VertexMatch &match, const std::vector< VertexMatch > &other_matches=std::vector< VertexMatch >())
if the match is a crashed task
Definition: configurator.cpp:995
void addToPriorityQueue(vertexDescriptor v, std::vector< vertexDescriptor > &queue, const std::set< vertexDescriptor > &closed)
Adds vertexDescriptor to priority queue according to a custom heuristic.
Definition: configurator.cpp:600
std::vector< vertexDescriptor > task_vertices(vertexDescriptor v, std::pair< bool, edgeDescriptor > *ep=NULL)
Rerturns all the vertices making up a task.
Definition: configurator.cpp:1021
void adjustProbability(const edgeDescriptor &e)
Adjusts the probability that a continuous state (edge target) will occur after taking a discrete stat...
Definition: configurator.cpp:1139
vertexDescriptor getRecyclingStart(vertexDescriptor v, vertexDescriptor v1, vertexDescriptor taskStart)
Returns the vertex from which to start recycling plan.
Definition: configurator.cpp:1088
void resetPhi()
Resets all vertices evaluation function phi to a default unitialised value of 10.
Definition: configurator.cpp:93
void applyTransitionMatrix(vertexDescriptor v0, Direction d, bool ended, vertexDescriptor src, std::vector< vertexDescriptor > &plan_prov)
Sets permitted transitions out of a state.
Definition: configurator.cpp:551
std::vector< vertexDescriptor > explorer(vertexDescriptor v, TransitionSystem &g, b2World &w)
Constructs transition system using a Box2D simulation combined with an A* graph expansion algorithm.
Definition: configurator.cpp:170
Definition: configurator.h:17
void update_graph(TransitionSystem &g, const b2Transform &_deltaPose)
Definition: configurator.cpp:865
static void run(Configurator *)
Spawns tasks, creates plans, tracks task and controls real-world task switching option to run in thre...
Definition: configurator.cpp:419
std::pair< edgeDescriptor, bool > addVertex(const vertexDescriptor &src, vertexDescriptor &v1, Edge edge=Edge(), bool topDown=0)
Add state to the cognitive map and set next state Task direction and options.
Definition: configurator.cpp:351
bool Spawner()
Calls functions to explore the state space and extract a plan.
Definition: configurator.cpp:63
void estimate_current_vertex()
Definition: configurator.cpp:814
static void MulT(const b2Transform &B, Task &task)
Matrix multiply by transpose.
Definition: configurator.cpp:4
virtual void explore_plan(b2World &)=0
Explores and plan.
static void Mul(const b2Transform &B, Task &task)
Matrix multiplication.
Definition: configurator.cpp:9
void init(Task _task=Task())
Initialises configurator.
Definition: configurator.cpp:16
void change_task()
changes tasks to execute on
Definition: configurator.cpp:849
Callback interface class for implementing custom strategies to switch between tasks to be executed.
Definition: task_controller.h:11
Information about what the configurator is doing (current Task, current vertex), what it wants to do ...
Definition: planner.h:41
Definition: control_interface.h:31
Class used to load data from the configurator.
Definition: debug.h:18
Definition: control_interface.h:42
Searches the transition system and extracts a plan.
Definition: planner.h:88
Implements a Braitenberg vehicle: only simulates one Task at a time.
Definition: configurator.h:562
void explore_plan(b2World &) override
Explores and plan.
Definition: configurator.cpp:917
Definition: graphTools.h:453
Tracking interface: Bridge between the real world and the simulation. Is used for tracking execution ...
Definition: tracker.h:8
Definition: worldbuilder.h:5
Definition: disturbance.h:112
Edges connecting states in the transition system.
Definition: graphTools.h:40
Definition: control_interface.h:119
Contains the differences between the contiuous components of two hybrid states.
Definition: graphTools.h:142
Hybrid states in the transition system.
Definition: graphTools.h:69
Definition: disturbance.h:268