19 #ifndef CHOREOGRAPHER_PLANNER_H_
20 #define CHOREOGRAPHER_PLANNER_H_
24 #include <pcl/point_types.h>
39 #include <ff_msgs/PlanAction.h>
40 #include <ff_msgs/ControlState.h>
41 #include <ff_msgs/Zone.h>
42 #include <ff_msgs/RegisterPlanner.h>
43 #include <ff_msgs/GetZones.h>
44 #include <ff_msgs/GetOccupancyMap.h>
45 #include <ff_msgs/GetMap.h>
48 #include <jps3d/planner/jps_3d_util.h>
75 state_(INITIALIZING) {
77 registration_.request.name =
name;
78 registration_.request.description = description;
79 registration_.request.unregister =
false;
91 virtual void PlanCallback(ff_msgs::PlanGoal
const& goal) = 0;
97 NODELET_DEBUG_STREAM(
"Plan result received");
98 NODELET_DEBUG_STREAM(result);
99 Complete(result.response, result);
102 NODELET_WARN_STREAM(
"Plan result received in non-planning state");
114 NODELET_WARN_STREAM(
"Plan feedback received in non-planning state");
120 bool GetZones(std::vector < ff_msgs::Zone > & zones) {
121 ff_msgs::GetZones srv;
122 if (client_z_.
Call(srv)) {
123 zones = srv.response.zones;
129 bool GetZonesMap(std::vector<signed char> &map, Vec3f &origin, Vec3i &dim,
double &map_res) {
130 ff_msgs::GetOccupancyMap srv;
131 if (client_z_m_.
Call(srv)) {
132 map.resize(srv.response.map.size());
133 map = srv.response.map;
134 origin[0] = srv.response.origin.x;
135 origin[1] = srv.response.origin.y;
136 origin[2] = srv.response.origin.z;
137 dim[0] = srv.response.dim.x;
138 dim[1] = srv.response.dim.y;
139 dim[2] = srv.response.dim.z;
140 map_res = srv.response.resolution;
145 bool GetFreeMap(pcl::PointCloud<pcl::PointXYZ> *points,
float *resolution) {
147 if (client_f_.
Call(srv)) {
149 *resolution = srv.response.resolution;
156 if (client_o_.
Call(srv)) {
158 *resolution = srv.response.resolution;
165 void Initialize(ros::NodeHandle *nh) {
166 cfg_fm_.
AddFile(
"flight.config");
169 server_p_.
SetGoalCallback(std::bind(&PlannerImplementation::GoalCallback,
this, std::placeholders::_1));
170 server_p_.
SetPreemptCallback(std::bind(&PlannerImplementation::PreemptCallback,
this));
171 server_p_.
SetCancelCallback(std::bind(&PlannerImplementation::CancelCallback,
this));
173 + registration_.request.name
175 server_p_.
Create(nh, topic);
178 client_z_.
SetTimeoutCallback(std::bind(&PlannerImplementation::GetZonesTimeoutCallback,
this));
182 client_z_m_.
SetTimeoutCallback(std::bind(&PlannerImplementation::GetZonesMapTimeoutCallback,
this));
186 client_r_.
SetTimeoutCallback(std::bind(&PlannerImplementation::RegisterTimeoutCallback,
this));
190 client_f_.
SetTimeoutCallback(std::bind(&PlannerImplementation::GetFreeMapTimeoutCallback,
this));
194 client_o_.
SetTimeoutCallback(std::bind(&PlannerImplementation::GetObstacleMapTimeoutCallback,
this));
198 InitFault(
"Planner could not be initialized");
203 void InitFault(std::string
const& msg ) {
204 NODELET_ERROR_STREAM(msg);
210 void Complete(int32_t response_code, ff_msgs::PlanResult result = ff_msgs::PlanResult()) {
213 result.response = response_code;
214 if (result.response > 0)
216 else if (result.response < 0)
222 NODELET_WARN_STREAM(
"Plan result received in non-planning state");
230 void ConnectedCallback(
void) {
231 NODELET_DEBUG_STREAM(
"ConnectedCallback()");
237 if (state_ != INITIALIZING)
return;
239 NODELET_DEBUG_STREAM(
"Registering planner");
240 client_r_.
Call(registration_);
246 void RegisterTimeoutCallback(
void) {
247 return InitFault(
"Timeout connecting to register service");
251 void GetZonesTimeoutCallback(
void) {
252 return InitFault(
"Timeout connecting to the get zones service");
256 void GetZonesMapTimeoutCallback(
void) {
257 return InitFault(
"Timeout connecting to the get zones map service");
261 void GetFreeMapTimeoutCallback(
void) {
262 return InitFault(
"Timeout connecting to the get free map service");
266 void GetObstacleMapTimeoutCallback(
void) {
267 return InitFault(
"Timeout connecting to the get obstacle map service");
271 bool CheckBound(
double candidate,
double upper_bound) {
272 return (candidate <= upper_bound);
276 double GetValue(
double candidate,
double upper_bound) {
277 if (candidate > 0.0 && candidate <= upper_bound)
283 void GoalCallback(ff_msgs::PlanGoalConstPtr
const& old_goal) {
284 NODELET_DEBUG_STREAM(
"A new plan request was just received");
285 NODELET_DEBUG_STREAM(*old_goal);
289 return Complete(RESPONSE::PROBLEM_CONNECTING_TO_SERVICES);
291 Complete(RESPONSE::PREEMPTED);
302 void PreemptCallback(
void) {
303 return Complete(RESPONSE::PREEMPTED);
307 void CancelCallback(
void) {
308 return Complete(RESPONSE::CANCELLED);
318 ff_msgs::RegisterPlanner registration_;
324 #endif // CHOREOGRAPHER_PLANNER_H_