quori_controller_node.cpp
Go to the documentation of this file.
2 
3 
4 #include "SerialDevice.hpp"
5 #include "Quori.hpp"
6 
7 #include <array>
8 #include <chrono>
9 
10 namespace
11 {
12 
13 
14 
15 }
16 
17 using namespace quori_controller;
18 
19 int main(int argc, char *argv[])
20 {
21  ros::init(argc, argv, "quori_controller");
22 
24  spinner.start();
25 
26  ros::NodeHandle nh;
27  ros::NodeHandle pnh("~");
28 
29  std::vector<std::string> devices;
30  if (!pnh.getParam("devices", devices))
31  {
32  std::cerr << "Expected ~devices parameter" << std::endl;
33  return EXIT_FAILURE;
34  }
35 
36  bool generate_csvs = false;
37  pnh.getParam("generate_csvs", generate_csvs);
38 
39  boost::asio::io_service service;
40  std::vector<SerialDevice::Ptr> serial_devices;
41  std::unique_ptr<std::ofstream> csv_file;
42  Csv::Ptr csv;
43 
44 
45  if (generate_csvs)
46  {
47  csv_file = std::make_unique<std::ofstream>("out.csv");
48  if (!*csv_file) throw std::runtime_error("Could not open csv file");
49  csv = Csv::open(*csv_file);
50  std::cerr << "Opened CSV" << std::endl;
51  }
52 
53  for (const auto &device : devices)
54  {
55  const auto serial_device = SerialDevice::open(service, device);
56  if (csv) serial_device->attachSetPositionsCsv(csv);
57  serial_devices.push_back(serial_device);
58  }
59 
60 
61  Quori robot(nh, serial_devices);
62 
64 
65  double rate_hz = pnh.param("rate", 100.0);
66 
67  ros::Time last_read;
68  ros::Time last_update;
69  ros::Time last_write;
70 
71  ros::Rate rate(rate_hz);
72  while (ros::ok())
73  {
74  service.run_one();
75 
76  const ros::Time read_time = ros::Time::now();
77  robot.read(read_time, read_time - last_read);
78  last_read = read_time;
79 
80  const ros::Time update_time = ros::Time::now();
81  cm.update(update_time, update_time - last_update);
82  last_update = update_time;
83 
84 
85  const ros::Time write_time = ros::Time::now();
86  robot.write(write_time, write_time - last_write);
87  last_write = write_time;
88 
89  rate.sleep();
90  }
91 }
controller_manager::ControllerManager
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
ros::AsyncSpinner
quori_controller::SerialDevice::open
static Ptr open(boost::asio::io_service &context, const std::string &path)
Definition: SerialDevice.cpp:38
controller_manager.h
ros::ok
ROSCPP_DECL bool ok()
quori_controller::Quori::read
virtual void read(const ros::Time &time, const ros::Duration &period)
Definition: Quori.cpp:165
quori_controller
Definition: Csv.hpp:10
spinner
void spinner()
main
int main(int argc, char *argv[])
Definition: quori_controller_node.cpp:19
quori_controller::Csv::Ptr
std::shared_ptr< Csv > Ptr
Definition: Csv.hpp:15
ros::Rate::sleep
bool sleep()
quori_controller::Csv::open
static Ptr open(std::ostream &out)
Definition: Csv.cpp:38
ros::Time
ros::NodeHandle::param
T param(const std::string &param_name, const T &default_val) const
ros::Rate
SerialDevice.hpp
quori_controller::Quori::write
void write()
controller_manager::ControllerManager::update
void update(const ros::Time &time, const ros::Duration &period, bool reset_controllers=false)
Quori.hpp
ros::NodeHandle
quori_controller::Quori
Definition: Quori.hpp:25
ros::Time::now
static Time now()


quori_controller
Author(s):
autogenerated on Wed Mar 2 2022 00:53:16