36 #include <rc_common_msgs/ReturnCodeConstants.h> 40 namespace rcd = dynamics;
41 using rc_common_msgs::ReturnCodeConstants;
59 void handleDynamicsStateChangeRequest(rcd::RemoteInterface::Ptr dynIF,
DynamicsCmd state,
60 rc_common_msgs::Trigger::Response& resp)
62 resp.return_code.value = ReturnCodeConstants::SUCCESS;
63 resp.return_code.message =
"";
65 std::string new_state;
73 case DynamicsCmd::STOP:
74 new_state = dynIF->stop();
76 case DynamicsCmd::STOP_SLAM:
77 new_state = dynIF->stopSlam();
79 case DynamicsCmd::START:
80 new_state = dynIF->start();
82 case DynamicsCmd::START_SLAM:
83 new_state = dynIF->startSlam();
85 case DynamicsCmd::RESTART_SLAM:
86 new_state = dynIF->restartSlam();
88 case DynamicsCmd::RESTART:
89 new_state = dynIF->restart();
91 case DynamicsCmd::RESET_SLAM:
92 new_state = dynIF->resetSlam();
95 throw std::runtime_error(
"handleDynamicsStateChangeRequest: unrecognized state change request");
97 if (new_state == rcd::RemoteInterface::State::FATAL)
99 resp.return_code.value = ReturnCodeConstants::NOT_APPLICABLE;
100 resp.return_code.message =
"rc_dynamics module is in " + new_state +
" state. Check the log files.";
103 catch (std::exception& e)
105 resp.return_code.value = ReturnCodeConstants::INTERNAL_ERROR;
106 resp.return_code.message = std::string(
"Failed to change state of rcdynamics module: ") + e.what();
111 resp.return_code.value = ReturnCodeConstants::NOT_APPLICABLE;
112 resp.return_code.message =
"rcdynamics remote interface not yet initialized!";
115 std::stringstream
msg;
116 msg <<
"rc_visard_driver: dynamics state change request returned with code: " 117 << resp.return_code.value <<
" msg: " << resp.return_code.message;
125 handleDynamicsStateChangeRequest(dynamicsInterface, DynamicsCmd::START, resp);
131 handleDynamicsStateChangeRequest(dynamicsInterface, DynamicsCmd::START_SLAM, resp);
137 handleDynamicsStateChangeRequest(dynamicsInterface, DynamicsCmd::RESTART, resp);
143 handleDynamicsStateChangeRequest(dynamicsInterface, DynamicsCmd::RESTART_SLAM, resp);
149 handleDynamicsStateChangeRequest(dynamicsInterface, DynamicsCmd::STOP, resp);
155 handleDynamicsStateChangeRequest(dynamicsInterface, DynamicsCmd::STOP_SLAM, resp);
161 handleDynamicsStateChangeRequest(dynamicsInterface, DynamicsCmd::RESET_SLAM, resp);
166 rc_visard_driver::GetTrajectory::Response& resp)
168 TrajectoryTime start(req.start_time.sec, req.start_time.nsec, req.start_time_relative);
169 TrajectoryTime end(req.end_time.sec, req.end_time.nsec, req.end_time_relative);
171 auto pbTraj = dynamicsInterface->getSlamTrajectory(start, end);
172 resp.trajectory.header.frame_id = pbTraj.parent();
173 resp.trajectory.header.stamp.sec = pbTraj.timestamp().sec();
174 resp.trajectory.header.stamp.nsec = pbTraj.timestamp().nsec();
176 for (
auto pbPose : pbTraj.poses())
178 geometry_msgs::PoseStamped rosPose;
179 rosPose.header.frame_id = pbTraj.parent();
180 rosPose.header.stamp.sec = pbPose.timestamp().sec();
181 rosPose.header.stamp.nsec = pbPose.timestamp().nsec();
182 rosPose.pose.position.x = pbPose.pose().position().x();
183 rosPose.pose.position.y = pbPose.pose().position().y();
184 rosPose.pose.position.z = pbPose.pose().position().z();
185 rosPose.pose.orientation.x = pbPose.pose().orientation().x();
186 rosPose.pose.orientation.y = pbPose.pose().orientation().y();
187 rosPose.pose.orientation.z = pbPose.pose().orientation().z();
188 rosPose.pose.orientation.w = pbPose.pose().orientation().w();
189 resp.trajectory.poses.push_back(rosPose);
193 if (autopublishTrajectory)
195 trajPublisher.publish(resp.trajectory);
203 if (dynamicsInterface)
207 rcd::RemoteInterface::ReturnCode
rc = dynamicsInterface->saveSlamMap();
208 resp.return_code.value = rc.value;
209 resp.return_code.message = rc.message;
211 catch (std::exception& e)
213 resp.return_code.value = ReturnCodeConstants::INTERNAL_ERROR;
214 resp.return_code.message = std::string(
"Failed to save SLAM map: ") + e.what();
219 resp.return_code.value = ReturnCodeConstants::NOT_APPLICABLE;
220 resp.return_code.message =
"rcdynamics remote interface not yet initialized!";
223 std::stringstream
msg;
224 msg <<
"rc_visard_driver: save slam map request returned with code: " 225 << resp.return_code.value <<
" msg: " << resp.return_code.message;
234 if (dynamicsInterface)
238 rcd::RemoteInterface::ReturnCode
rc = dynamicsInterface->loadSlamMap();
239 resp.return_code.value = rc.value;
240 resp.return_code.message = rc.message;
242 catch (std::exception& e)
244 resp.return_code.value = ReturnCodeConstants::INTERNAL_ERROR;
245 resp.return_code.message = std::string(
"Failed to load SLAM map: ") + e.what();
250 resp.return_code.value = ReturnCodeConstants::NOT_APPLICABLE;
251 resp.return_code.message =
"rcdynamics remote interface not yet initialized!";
254 std::stringstream
msg;
255 msg <<
"rc_visard_driver: load slam map request returned with code: " 256 << resp.return_code.value <<
" msg: " << resp.return_code.message;
265 if (dynamicsInterface)
269 rcd::RemoteInterface::ReturnCode
rc = dynamicsInterface->removeSlamMap();
270 resp.return_code.value = rc.value;
271 resp.return_code.message = rc.message;
273 catch (std::exception& e)
275 resp.return_code.value = ReturnCodeConstants::INTERNAL_ERROR;
276 resp.return_code.message = std::string(
"Failed to remove SLAM map: ") + e.what();
281 resp.return_code.value = ReturnCodeConstants::NOT_APPLICABLE;
282 resp.return_code.message =
"rcdynamics remote interface not yet initialized!";
285 std::stringstream
msg;
286 msg <<
"rc_visard_driver: remove slam map request returned with code: " 287 << resp.return_code.value <<
" msg: " << resp.return_code.message;
bool dynamicsStart(rc_common_msgs::Trigger::Request &req, rc_common_msgs::Trigger::Response &resp)
Start Stereo INS.
bool dynamicsStopSlam(rc_common_msgs::Trigger::Request &req, rc_common_msgs::Trigger::Response &resp)
Stop SLAM (keep Stereo INS running)
bool getSlamTrajectory(rc_visard_driver::GetTrajectory::Request &req, rc_visard_driver::GetTrajectory::Response &resp)
Get the Slam trajectory.
#define ROS_ERROR_STREAM_COND(cond, args)
bool dynamicsStartSlam(rc_common_msgs::Trigger::Request &req, rc_common_msgs::Trigger::Response &resp)
Start Stereo INS+SLAM.
DynamicsCmd
Commands taken by handleDynamicsStateChangeRequest()
bool dynamicsRestart(rc_common_msgs::Trigger::Request &req, rc_common_msgs::Trigger::Response &resp)
Restart Stereo INS.
bool removeSlamMap(rc_common_msgs::Trigger::Request &req, rc_common_msgs::Trigger::Response &resp)
Remove the onboard SLAM map.
#define ROS_INFO_STREAM_COND(cond, args)
bool dynamicsResetSlam(rc_common_msgs::Trigger::Request &req, rc_common_msgs::Trigger::Response &resp)
Reset SLAM (keep Stereo INS running)
bool dynamicsStop(rc_common_msgs::Trigger::Request &req, rc_common_msgs::Trigger::Response &resp)
Stop Stereo INS(+SLAM if running)
bool dynamicsRestartSlam(rc_common_msgs::Trigger::Request &req, rc_common_msgs::Trigger::Response &resp)
Restart Stereo INS+SLAM.
bool saveSlamMap(rc_common_msgs::Trigger::Request &req, rc_common_msgs::Trigger::Response &resp)
Save the onboard SLAM map.
bool loadSlamMap(rc_common_msgs::Trigger::Request &req, rc_common_msgs::Trigger::Response &resp)
Load the onboard SLAM map.