ROSSimActor.cpp
Go to the documentation of this file.
1 
6 #include "ROSSimActor.h"
7 
8 
10 {
11  agNumber = 0;
12  id = 0;
13  initFlag = false;
14  sightRad = 0.0;
15 
16 
17  ros::ServiceClient client = n.serviceClient<ORCAStar::Init>("initServer");
18  ros::service::waitForService("initServer");
19  ORCAStar::Init srv;
20 
21  if (client.call(srv))
22  {
23 
24  client.shutdown();
25  ROS_DEBUG("Parameters received!");
26  id = srv.response.id;
27  sightRad = srv.response.sightRadius;
28  initData = srv.response;
29  }
30  else
31  {
32  ROS_ERROR("Parameters not received!");
33  exit(-1);
34  }
35 
36  std::stringstream serverName;
37  serverName << "initAgentServer_" << id;
38  ros::ServiceServer initServer = n.advertiseService(serverName.str(), &ROSSimActor::InitAgent, this);
39 
40  while(!initFlag && ros::ok())
41  {
42  ros::spinOnce();
43  }
44 
45  initServer.shutdown();
46 
47  agentVelocityMsg.id = id;
48  agentVelocityMsg.vel = geometry_msgs::Point32();
49 
50  ROSSimActorPub = n.advertise<ORCAStar::AgentVelocity>("AgentVelocities", 1000);
51  ROSSimActorSub = n.subscribe("AgentStates", 1000, &ROSSimActor::ReceiveAgentStates, this);
52 
53  std::stringstream inpTopicName;
54  inpTopicName << "AgentInput_" << id;
55  std::stringstream outTopicName;
56  outTopicName << "AgentOutput_" << id;
57 
58  ROSSimActorToAgentPub = n.advertise<ORCAStar::ORCAInput>(inpTopicName.str(), 1000);
59  ROSSimActorToAgentSub = n.subscribe(outTopicName.str(), 1000, &ROSSimActor::TransmitAgentVelocity, this);
60 
61  ROS_DEBUG("ROS Actor Init: %lu!", id);
62 
63  ros::spin();
64 }
65 
66 
67 
69 
70 
71 
72 void ROSSimActor::ReceiveAgentStates(const ORCAStar::AgentState &msg)
73 {
74  ROS_DEBUG("Actor %lu start step", id);
75  inputORCAMsg.pos = msg.pos[id];
76  inputORCAMsg.vel = msg.vel[id];
77 
78  Point curr = {msg.pos[id].x, msg.pos[id].y};
79 
80  inputORCAMsg.neighbours.pos.clear();
81  inputORCAMsg.neighbours.vel.clear();
82  inputORCAMsg.neighbours.rad.clear();
83 
84  for(size_t i = 0; i < msg.pos.size(); i++)
85  {
86  Point another = {msg.pos[i].x, msg.pos[i].y};
87 
88  if(id != i && (curr-another).SquaredEuclideanNorm() < sightRad * sightRad)
89  {
90  inputORCAMsg.neighbours.pos.push_back(msg.pos[i]);
91  inputORCAMsg.neighbours.vel.push_back(msg.vel[i]);
92  inputORCAMsg.neighbours.rad.push_back(msg.rad[i]);
93  }
94  }
95 
96 
97  ROSSimActorToAgentPub.publish(inputORCAMsg);
98 }
99 
100 void ROSSimActor::TransmitAgentVelocity(const geometry_msgs::Point32 &msg)
101 {
102  ROS_DEBUG("Actor %lu end step", id);
103 
104  agentVelocityMsg.id = id;
105  agentVelocityMsg.vel = msg;
106  ROSSimActorPub.publish(agentVelocityMsg);
107 }
108 
109 
110 bool ROSSimActor::InitAgent(ORCAStar::Init::Request &req, ORCAStar::Init::Response &res)
111 {
112  res = initData;
113 
114  ROS_DEBUG("Sim Agent %lu\n Init", id);
115 
116  initFlag = true;
117 
118  return true;
119 }
120 
~ROSSimActor()
ROSSimActor destructor.
Definition: ROSSimActor.cpp:68
The Point class defines a position (or euclidean vector from (0,0)) in 2D space.
Definition: Geom.h:61
float x
X-coordinate of the point.
Definition: Geom.h:192
File contains ROSSimActor class.
void TransmitAgentVelocity(const geometry_msgs::Point32 &msg)
Receives computed velocity from agent module and transmits it to simulation module.
void ReceiveAgentStates(const ORCAStar::AgentState &msg)
Receives all agents states and transmits neighbours states to single agent module.
Definition: ROSSimActor.cpp:72
ROSSimActor()
ROSSimActor default constructor.
Definition: ROSSimActor.cpp:9


ORCAStar
Author(s): Stepan Drgachev
autogenerated on Wed Jul 15 2020 16:13:14