12 std::stringstream initServerName;
13 initServerName <<
"initAgentServer_" << id;
14 ros::ServiceClient client = n.serviceClient<ORCAStar::Init>(initServerName.str());
15 ros::service::waitForService(initServerName.str());
21 ROS_DEBUG(
"Agent %lu Parameters received!",
id);
25 ROS_ERROR(
"Agent %lu Parameters not received!",
id);
33 param =
new AgentParam(srv.response.sightRadius,srv.response.timeBoundary,srv.response.timeBoundaryObst,
34 srv.response.radius,
CN_DEFAULT_REPS, srv.response.speed, srv.response.agentMaxNum);
36 Point start = {srv.response.start.
x, srv.response.start.y};
37 Point goal = {srv.response.goal.
x, srv.response.goal.y};
40 std::vector<std::vector<Point>> obstacles;
42 for(
auto &obst : srv.response.Obstacles)
44 std::vector<Point> tmp;
45 for(
auto &vert : obst.points)
47 tmp.push_back({vert.x, vert.y});
49 obstacles.push_back(tmp);
55 std::vector<std::vector<int>> grid;
57 ros::ServiceClient mapClint = n.serviceClient<nav_msgs::GetMap>(
"static_map");
58 nav_msgs::GetMap mapSrv;
60 if(mapClint.call(mapSrv))
63 ROS_DEBUG(
"Agent %lu Map received!",
id);
67 ROS_ERROR(
"Agent %lu Map not received!",
id);
71 w = mapSrv.response.map.info.width;
72 h = mapSrv.response.map.info.height;
73 cs = mapSrv.response.map.info.resolution;
75 for(
size_t i = 0; i < h; i++)
77 grid.push_back(std::vector<int>(w, 0));
78 for(
size_t j = 0; j < w; j++)
80 if(mapSrv.response.map.data[j + w * (h - i - 1)] == 100)
90 map =
new Map(cs, grid, obstacles);
93 ROS_DEBUG(
"Map %lu Created!",
id);
95 agent =
new ORCAAgent(0, start, goal, *map, *options, *param);
96 agent->SetPlanner(
ThetaStar(*map, *options, agent->GetStart(), agent->GetGoal(), param->radius + param->rEps));
99 ROS_DEBUG(
"Agent %lu Created!",
id);
101 std::stringstream inpTopicName;
102 inpTopicName <<
"AgentInput_" << id;
103 std::stringstream outTopicName;
104 outTopicName <<
"AgentOutput_" << id;
106 ROSAgentSub = n.subscribe(inpTopicName.str(), 1000, &
ROSAgent::DoStep,
this);;
107 ROSAgentPub = n.advertise<geometry_msgs::Point32>(outTopicName.str(), 1000);;
110 ROS_DEBUG(
"Agent %lu Topics Created!",
id);
123 agent->SetPosition({msg.pos.x, msg.pos.y});
124 agent->SetVelocity({msg.vel.x, msg.vel.y});
127 for(
size_t i = 0; i < msg.neighbours.pos.size(); i++)
130 nParam.
radius = msg.neighbours.rad[i];
132 Point nPos = {msg.neighbours.pos[i].
x, msg.neighbours.pos[i].y};
133 Point nVel = {msg.neighbours.vel[i].
x, msg.neighbours.vel[i].y};
138 float distSq = (agent->GetPosition()-nPos).SquaredEuclideanNorm();
139 agent->AddNeighbour(*tmpAgent, distSq);
142 agent->UpdatePrefVelocity();
143 agent->UpdateNeighbourObst();
146 agent->ComputeNewVelocity();
147 agent->ApplyNewVelocity();
150 geometry_msgs::Point32 vel;
151 vel.x = agent->GetVelocity().X();
152 vel.y = agent->GetVelocity().Y();
154 for(
auto &n : neighbous)
161 ROS_DEBUG(
"Agent %lu Do Step!", agentId);
162 ROSAgentPub.publish(vel);
#define CN_DEFAULT_HWEIGHT
Default H-weight for Theta* value.
float radius
Size of the agent (radius of the agent).
The Point class defines a position (or euclidean vector from (0,0)) in 2D space.
#define CN_DEFAULT_CUTCORNERS
Default Theta* CUTCORNERS value.
#define CN_DEFAULT_REPS
Default agent buffer size value.
Class AgentParam contains agent and algoritms parameters.
float x
X-coordinate of the point.
#define CN_DEFAULT_METRIC_TYPE
Default Theta* heuristic-function value.
Agent class implements base agent interface and behavior.
Class EnvironmentOptions contains environment and algoritms parameters.
virtual void SetVelocity(const Point &vel)
Sets current velocity. Should be used if the new velocity may not coincide with the computed...
Map class describes static environment.
File contains ROSAgent class.
ThetaStar class implements Theta* algorithm, which creates path from start to goal position...
ORCAAgent class implements agent with ORCA algoritm behavior.
void DoStep(const ORCAStar::ORCAInput &msg)
virtual void SetPosition(const Point &pos)
SetsS current position of agent. Can be ovveriden.
#define CN_DEFAULT_BREAKINGTIES
Default Theta* BREAKINGTIES value.
#define CN_DEFAULT_TIME_STEP
Default simulation timestep value.
#define CN_DEFAULT_ALLOWSQUEEZE
Default Theta* ALLOWSQUEEZE value.