BotaDeviceDriver.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 #include <utility>
5 
6 namespace bota_device_driver
7 {
9 {
10 }
11 
13 {
14  const bool is_standalone = false;
15  const bool install_signal_handler = false;
16  double time_step;
17  std::string setup_file;
18  nh_->param<double>("time_step", time_step, 0.01);
19  nh_->param<std::string>("rokubimini_setup_file", setup_file, "");
20 
21  rokubiminiManager_ = std::make_unique<RokubiminiManager>(is_standalone, install_signal_handler, time_step, nh_);
22 
23  if (!rokubiminiManager_->loadSetup())
24  {
25  ROS_ERROR_STREAM("Could not load setup file");
26  }
27 
28  if (!rokubiminiManager_->startup())
29  {
30  ROS_WARN_STREAM("Manager could not startup");
31  return false;
32  }
33  rokubiminiManager_->setNodeHandle(nh_);
34  rokubiminiManager_->createRokubiminiRosPublishers();
35  rokubiminiManager_->createRokubiminiRosServices();
36  std::vector<std::shared_ptr<Rokubimini>> rokubiminis;
37  // Load all available rokubiminis
38  rokubiminis = rokubiminiManager_->getRokubiminis();
39  if (rokubiminis.empty())
40  {
41  ROS_ERROR_STREAM("No rokubimini available");
42  return false;
43  }
44 
46  options.callback_ = std::bind(&BotaDeviceDriver::update, this, std::placeholders::_1);
47  options.defaultPriority_ = 10; // this has high priority
48  options.name_ = "BotaDeviceDriver::updateWorker";
49 
50  int minimumft_sampling_rate = std::numeric_limits<int>::max();
51  /* the following function has to be after setting the filter in order Sampling rate Object to be updated.
52  * The filters are set inside the startup function above */
53  for (const auto& rokubimini : rokubiminis)
54  {
55  int ft_sampling_rate;
56  rokubimini->getForceTorqueSamplingRate(ft_sampling_rate);
57  minimumft_sampling_rate = std::min(minimumft_sampling_rate, ft_sampling_rate);
58  }
59 
60  /* never compare with equality floats */
61  if (time_step <= 0.000001)
62  {
63  options.timeStep_ = 1.0 / static_cast<float>(minimumft_sampling_rate);
64  ROS_WARN_STREAM("Starting Worker at " << 1 / options.timeStep_ << " Hz, based on force/torque sampling rate.");
65  }
66  else
67  {
68  options.timeStep_ = time_step;
69  ROS_WARN_STREAM("Starting Worker at " << 1 / options.timeStep_ << " Hz, based on selected time step.");
70  }
71 
72  if (!this->addWorker(options))
73  {
74  ROS_ERROR_STREAM("[BotaDeviceDriver] Worker " << options.name_ << "could not be added!");
75  return false;
76  }
77  ROS_DEBUG("Finished initializing device driver");
78  return true;
79 }
80 
82 {
83  ROS_DEBUG("[BotaDeviceDriver]: update called");
84  rokubiminiManager_->updateCommunicationManagerReadMessages();
85  rokubiminiManager_->updateProcessReadings();
86 
87  rokubiminiManager_->updateCommunicationManagerWriteMessages();
88 
89  rokubiminiManager_->publishRosMessages();
90  return true;
91 }
92 
94 {
95  rokubiminiManager_->shutdown();
96 }
97 
98 } // namespace bota_device_driver
std::unique_ptr< RokubiminiManager > rokubiminiManager_
std::atomic< double > timeStep_
bool update(const bota_worker::WorkerEvent &event)
#define ROS_WARN_STREAM(args)
bool addWorker(const std::string &name, const double timestep, bool(T::*fp)(const bota_worker::WorkerEvent &), T *obj, const int priority=0)
std::shared_ptr< ros::NodeHandle > NodeHandlePtr
#define ROS_ERROR_STREAM(args)
#define ROS_DEBUG(...)


bota_device_driver
Author(s):
autogenerated on Wed Mar 3 2021 03:09:22