dynamic_graph_manager
simple_dgm.hpp
Go to the documentation of this file.
1 
9 #include "dynamic_graph_manager/TestUserCmdBool.h"
12 
14 {
20 {
21 public:
26  {
27  boolean_set_by_user_cmd_ = false;
28  }
33  {
34  }
40  {
41  // get the hardware communication ros node handle
42  ros::NodeHandle& ros_node_handle = dynamic_graph::ros_init(
45  ros_user_commands_.push_back(ros_node_handle.advertiseService(
46  "set_a_boolean", &SimpleDGM::user_command_callback, this));
47  }
54  {
55  map["encoders"].setRandom();
56  map["imu_accelerometer"].setRandom();
57  map["imu_gyroscope"].setRandom();
58  map["imu"].setRandom();
59  }
67  {
68  desired_torques_ = map.at("torques");
69  desired_positions_ = map.at("positions");
70  }
71 
76  {
77  // Here we nee to protect the access to this ressource as it may
78  // conflict with different thread. Please use cond_var_ to make sure
79  // everything is access on its due time.
80  bool ret = boolean_set_by_user_cmd_;
81  return ret;
82  }
83 
94  dynamic_graph_manager::TestUserCmdBool::Request& req,
95  dynamic_graph_manager::TestUserCmdBool::Response& res)
96  {
97  // parse and register the command for further call.
99  std::bind(&SimpleDGM::user_command, this, req.input_boolean));
100  // return whatever the user want
101  res.sanity_check = true;
102 
103  // the service has been executed properly
104  return true;
105  }
106 
114  {
115  // here define a check for robot specific stuff.
116  bool check = true;
117  return check || DynamicGraphManager::is_in_safety_mode();
118  }
119 
125  {
126  // fill all controls with zero... Check your robot to imagine what would
127  // be safer in this case.
128  for (dynamic_graph::VectorDGMap::iterator ctrl =
129  motor_controls_map_.begin();
130  ctrl != motor_controls_map_.end();
131  ++ctrl)
132  {
133  ctrl->second.fill(0.0);
134  }
135  }
136 
137 private:
143  void user_command(bool user_input)
144  {
145  // do something with the internal state or with the hardware
146  boolean_set_by_user_cmd_ = user_input;
147  }
148  // some internal hardware class or obect. Here just a simple boolean for
149  // unit testing
150  std::atomic_bool boolean_set_by_user_cmd_;
151 
152  // Control
153  dynamicgraph::Vector desired_torques_, desired_positions_;
154 };
155 
156 } // namespace dynamic_graph_manager
std::deque< ros::ServiceServer > ros_user_commands_
Attribute shared with the daughter class.
Definition: dynamic_graph_manager.hh:772
SimpleDGM()
Construct a new SimpleDGM object.
Definition: simple_dgm.hpp:25
bool user_command_callback(dynamic_graph_manager::TestUserCmdBool::Request &req, dynamic_graph_manager::TestUserCmdBool::Response &res)
This service callback parse the ros messages and register and internal method for further call using ...
Definition: simple_dgm.hpp:93
~SimpleDGM()
Destroy the SimpleDGM object.
Definition: simple_dgm.hpp:32
static const std::string hw_com_ros_node_name_
hw_com_ros_node_name_ this is the ros node name of the harware communication process ...
Definition: dynamic_graph_manager.hh:368
void initialize_hardware_communication_process()
Simple overload doing nothing.
Definition: simple_dgm.hpp:39
std::map< std::string, dynamicgraph::Vector > VectorDGMap
VectorDGMap is a shortcut for the very long type of the map.
Definition: tools.hh:22
this is this package namespace in order to avoid naming conflict
Definition: device.hh:22
This class has for purpose to manage the different processes during run time.
Definition: dynamic_graph_manager.hh:92
void get_sensors_to_map(dynamic_graph::VectorDGMap &map)
Get the sensors to the map object.
Definition: simple_dgm.hpp:53
VectorDGMap motor_controls_map_
motor_controls_map_ is a map of dynamicgraph::Vector.
Definition: dynamic_graph_manager.hh:577
void compute_safety_controls()
compute_safety_controls computes safety controls very fast in case the dynamic graph is taking to muc...
Definition: simple_dgm.hpp:124
void user_command(bool user_input)
The actuall user command called in the real time thread.
Definition: simple_dgm.hpp:143
void set_motor_controls_from_map(const dynamic_graph::VectorDGMap &map)
Set the motor controls from map object to no hardware.
Definition: simple_dgm.hpp:66
bool get_has_user_command_been_executed()
Get the has_user_command_been_executed_ object.
Definition: simple_dgm.hpp:75
bool is_in_safety_mode()
is_in_safety_mode check if the dynamic graph is still alive and sending commands at a descent frequen...
Definition: simple_dgm.hpp:113
This class is a simple dynamic graph manager with a fake hardware interface used for unittesting...
Definition: simple_dgm.hpp:19
DynamicGraphManager()
DynamicGraphManager, constructor of the class.
Definition: dynamic_graph_manager.cpp:34
void add_user_command(std::function< void(void)> func)
Method inherited.
Definition: dynamic_graph_manager.cpp:722
Example of hardware communication client based on ROS.
Definition: simple_dgm.hpp:13
ros::NodeHandle & ros_init(std::string node_name)
rosInit is a global method that uses the structure GlobalRos.
Definition: ros_init.cpp:31