5 #include <ram_msgs/AdditiveManufacturingTrajectory.h> 6 #include <ram_trajectory_utils/BufferParams.h> 7 #include <ram_trajectory_utils/ExportTrajectory.h> 8 #include <ram_trajectory_utils/ImportTrajectory.h> 9 #include <ram_trajectory_utils/UnmodifiedTrajectory.h> 25 std::vector<ram_msgs::AdditiveManufacturingTrajectory>
traj_msgs;
89 ram_trajectory_utils::BufferParams::Response &res)
93 ram_msgs::AdditiveManufacturingTrajectory trajectory;
94 switch (req.button_id)
102 res.error =
"Start of the buffer";
112 res.error =
"End of the buffer";
130 ram_trajectory_utils::UnmodifiedTrajectory::Response &res)
135 if (msg.generated == req.generated)
137 res.trajectory = msg;
147 size_t last_index = full_path.find_last_of(
"/");
148 std::string file_name = full_path.substr(last_index + 1, full_path.size());
150 last_index = file_name.find_last_of(
"\\");
151 file_name = file_name.substr(last_index + 1, file_name.size());
153 last_index = file_name.find_last_of(
".");
154 if (last_index == std::string::npos)
157 return file_name.substr(last_index + 1, file_name.size());
161 ram_trajectory_utils::ExportTrajectory::Response &res)
167 if (file_extension.compare(
"bag") != 0)
169 res.error = req.file_name +
" is not a bag file";
176 res.error =
"Current trajectory is empty";
181 ram_msgs::AdditiveManufacturingTrajectory unmodified_current_traj = current_traj;
183 if (current_traj.poses.size() == 0)
185 res.error =
"Current trajectory is empty";
190 bool trajectory_in_buffer =
false;
193 if (current_traj.generated != msg.generated)
196 trajectory_in_buffer =
true;
197 if (current_traj.modified != msg.modified)
199 unmodified_current_traj = msg;
204 if (!trajectory_in_buffer)
206 res.error =
"Corresponding unmodified trajectory does not exist in the buffer";
217 export_trajectoy_bag.
close();
221 export_trajectoy_bag.
close();
223 res.error = e.what();
231 ram_trajectory_utils::ImportTrajectory::Response &res)
237 if (file_extension.compare(
"bag") != 0)
239 res.error = req.file_name +
" is not a bag file";
245 std::vector<ram_msgs::AdditiveManufacturingTrajectory> msgs_from_file;
249 std::vector<std::string> topics;
250 topics.push_back(std::string(
"ram/trajectory"));
255 ram_msgs::AdditiveManufacturingTrajectory::ConstPtr
s =
256 m.instantiate<ram_msgs::AdditiveManufacturingTrajectory>();
258 msgs_from_file.push_back(*s);
261 import_trajectoy_bag.
close();
265 import_trajectoy_bag.
close();
267 res.error = e.what();
271 if (msgs_from_file.size() != 2)
273 res.error =
"Unable to import trajectory";
278 ram_msgs::AdditiveManufacturingTrajectory trajectory = msgs_from_file[0];
279 ram_msgs::AdditiveManufacturingTrajectory unmodified_trajectory = msgs_from_file[1];
281 if (trajectory.poses.size() == 0)
283 res.error =
"Trajectory is empty";
313 bool error_in_first_bag =
false;
314 bool error_in_second_bag =
false;
320 std::vector<std::string> topics;
321 topics.push_back(std::string(
"ram/trajectory"));
327 ram_msgs::AdditiveManufacturingTrajectory::ConstPtr
s =
328 m.instantiate<ram_msgs::AdditiveManufacturingTrajectory>();
341 std::string file(getenv(
"HOME"));
342 file +=
"/.ros/ram_buffer_trajectory.bag";
344 if (std::remove(file.c_str()) == 0)
347 error_in_first_bag =
true;
354 std::vector<std::string> topics;
355 topics.push_back(std::string(
"ram/trajectory"));
361 ram_msgs::AdditiveManufacturingTrajectory::ConstPtr
s =
362 m.instantiate<ram_msgs::AdditiveManufacturingTrajectory>();
373 std::string file(getenv(
"HOME"));
374 file +=
"/.ros/ram_buffer_unmodified_trajectory.bag";
376 if (std::remove(file.c_str()) == 0)
379 error_in_second_bag =
true;
382 if (error_in_first_bag || error_in_second_bag)
389 pub = nh.
advertise<ram_msgs::AdditiveManufacturingTrajectory>(
"ram/trajectory",
msg_to_keep,
true);
const unsigned msg_to_keep(10)
bool exportTrajectoryCallback(ram_trajectory_utils::ExportTrajectory::Request &req, ram_trajectory_utils::ExportTrajectory::Response &res)
void publish(const boost::shared_ptr< M > &message) const
void open(std::string const &filename, uint32_t mode=bagmode::Read)
bool importTrajectoryCallback(ram_trajectory_utils::ImportTrajectory::Request &req, ram_trajectory_utils::ImportTrajectory::Response &res)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
unsigned last_msg_published
std::mutex unmodified_msgs_mutex
std::unique_ptr< ros::NodeHandle > nh
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL const std::string & getName()
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
std::vector< ram_msgs::AdditiveManufacturingTrajectory > traj_msgs
const std::string & getPublisherName() const
std::vector< ram_msgs::AdditiveManufacturingTrajectory > unmodified_traj_msgs
bool getUnmodifiedTrajectoryCallback(ram_trajectory_utils::UnmodifiedTrajectory::Request &req, ram_trajectory_utils::UnmodifiedTrajectory::Response &res)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_WARN_STREAM(args)
int main(int argc, char **argv)
bool trajectoryBufferCallback(ram_trajectory_utils::BufferParams::Request &req, ram_trajectory_utils::BufferParams::Response &res)
void saveTrajectoryCallback(const ros::MessageEvent< ram_msgs::AdditiveManufacturingTrajectory > &msg_event)
ROSCPP_DECL void shutdown()
#define ROS_ERROR_STREAM(args)
void mySigintHandler(int)
std::string fileExtension(const std::string full_path)
void write(std::string const &topic, ros::MessageEvent< T > const &event)
boost::shared_ptr< M > getMessage() const
ROSCPP_DECL void waitForShutdown()