trajectory_library.cpp
Go to the documentation of this file.
1 //
2 // Created by yijiangh on 7/5/17.
3 //
4 
6 
7 #include <rosbag/bag.h>
8 #include <rosbag/view.h>
9 
10 void choreo_core_service::TrajectoryLibrary::save(const std::string& filename)
11 {
12  rosbag::Bag bag;
13  bag.open(filename, rosbag::bagmode::Write);
15 
16  for (TrajectoryMap::const_iterator it = map_.begin(); it != map_.end(); ++it)
17  {
18  bag.write(it->first, now, it->second);
19  }
20 }
21 
22 void choreo_core_service::TrajectoryLibrary::load(const std::string& filename)
23 {
24  rosbag::Bag bag;
25  bag.open(filename, rosbag::bagmode::Read);
26  rosbag::View view(bag);
27 
28  for (rosbag::View::iterator it = view.begin(); it != view.end(); ++it)
29  {
30  choreo_msgs::UnitProcessPlanPtr ptr = it->instantiate<choreo_msgs::UnitProcessPlan>();
31  if (!ptr)
32  {
33  // message failed to load
34  throw std::runtime_error("Could not load joint trajectory from ROS bag");
35  }
36 
37  // Check to see if key is already in data structure
38  std::string const& key = it->getTopic();
39  if (map_.find(key) != map_.end())
40  {
41  throw std::runtime_error("Bagfile had name matching key already in data structure");
42  }
43 
44  map_[key] = *ptr;
45  }
46 }
double now()
void open(std::string const &filename, uint32_t mode=bagmode::Read)
void load(const std::string &filename)
iterator end()
iterator begin()
static Time now()
void write(std::string const &topic, ros::MessageEvent< T > const &event)
void save(const std::string &filename)


choreo_core
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:38