12 ROS_DEBUG(
"Mission Init!");
16 agents = std::vector<Agent*>();
19 stepsTreshhold = threashold;
20 endOnFinish = endOnFin;
24 resultsLog = std::unordered_map<int, std::pair<bool, int>>();
25 resultsLog.reserve(agNumber);
29 agentStateMsg.pos = std::vector<geometry_msgs::Point32>();
30 agentStateMsg.vel = std::vector<geometry_msgs::Point32>();
31 agentStateMsg.rad = std::vector<float> ();
33 ROSMissionPub = n.advertise<ORCAStar::AgentState>(
"AgentStates", 1000);
34 loopRate =
new ros::Rate(10);
51 ROS_DEBUG(
"Mission Start!");
55 ROS_DEBUG(
"Mission step!");
59 ROSMissionPub.publish(agentStateMsg);
67 ROS_DEBUG(
"Mission End!");
74 geometry_msgs::Point32 tmp;
79 tmp.x = a->GetPosition().X();
80 tmp.y = a->GetPosition().Y();
81 agentStateMsg.pos[i] = tmp;
83 tmp.x = a->GetVelocity().X();
84 tmp.y = a->GetVelocity().Y();
85 agentStateMsg.vel[i] = tmp;
87 agentStateMsg.rad[i] = a->GetRadius();
96 ROS_DEBUG(
"Agent %lu Update Velocity",
id);
97 agents[id]->SetVelocity(
Point(msg.vel.x, msg.vel.y));
102 for(
auto &a : agents)
104 Point vel = a->GetVelocity();
105 Point newPos = a->GetPosition() + vel * options->timestep;
106 a->SetPosition(newPos);
116 ROS_DEBUG(
"Task File is OK!");
118 agentStateMsg.pos.resize(agNumber);
119 agentStateMsg.vel.resize(agNumber);
120 agentStateMsg.rad.resize(agNumber);
124 while(!initFlag && ros::ok())
129 ROS_DEBUG(
"Agents is OK!");
139 return taskReader->ReadData() && taskReader->GetMap(&map) &&
140 taskReader->GetAgents(agents, agNumber) &&
141 taskReader->GetEnvironmentOptions(&options);
150 res.start.x = agents[agCount]->GetStart().X();
151 res.start.y = agents[agCount]->GetStart().Y();
152 res.goal.x = agents[agCount]->GetGoal().X();
153 res.goal.y = agents[agCount]->GetGoal().Y();
155 res.delta = options->delta;
156 res.speed = agents[agCount]->GetParam().maxSpeed;
157 res.radius = agents[agCount]->GetParam().radius;
158 res.agentMaxNum = agents[agCount]->GetParam().agentsMaxNum;
159 res.sightRadius = agents[agCount]->GetParam().sightRadius;
160 res.timeBoundary = agents[agCount]->GetParam().timeBoundary;
161 res.timeBoundaryObst = agents[agCount]->GetParam().timeBoundaryObst;
163 for(
auto &O : map->GetObstacles())
165 geometry_msgs::Polygon polygon;
168 geometry_msgs::Point32 vertex;
169 vertex.x = o.left.X();
170 vertex.y = o.left.Y();
171 polygon.points.push_back(vertex);
174 res.Obstacles.push_back(polygon);
177 ROS_DEBUG(
"Sim Actor %lu\n", agCount);
180 if(agCount == agNumber)
197 if(stepsCount == stepsTreshhold)
203 for(
auto &agent : agents)
205 result = result && agent->isFinished();
bool PrepareSimulation()
Prepare simulation of multiagen navigation. Read task from XML file. Create ROS service for agent ini...
File contains ROSMission class.
Class Summary contains brief information about execution results.
bool InitAgent(ORCAStar::Init::Request &req, ORCAStar::Init::Response &res)
The Point class defines a position (or euclidean vector from (0,0)) in 2D space.
ROSMission(std::string fileName, size_t agNum, int threashold=-1, bool endOnFin=false)
ROSMission constructor with parameters. Initialize multiagent simulation. Creates ROS topics and serv...
void UpdateVelocity(const ORCAStar::AgentVelocity &msg)
void GenerateAgentStateMsg()
The XMLReader class implements interface for input data reading from XML-file with a specific structu...
void StartSimulation()
Start multiagent simulation execution.
~ROSMission()
Default ROSMission destructor.