dynamic_graph_manager
simple_dgm.hpp

The correponding hardware python client is seen here:

#include "dynamic_graph_manager/TestUserCmdBool.h"
{
class SimpleDGM : public dynamic_graph::DynamicGraphManager
{
public:
{
boolean_set_by_user_cmd_ = false;
}
{
}
{
// get the hardware communication ros node handle
ros::NodeHandle& ros_node_handle = dynamic_graph::ros_init(
ros_user_commands_.push_back(ros_node_handle.advertiseService(
"set_a_boolean", &SimpleDGM::user_command_callback, this));
}
{
map["encoders"].setRandom();
map["imu_accelerometer"].setRandom();
map["imu_gyroscope"].setRandom();
map["imu"].setRandom();
}
{
desired_torques_ = map.at("torques");
desired_positions_ = map.at("positions");
}
{
// Here we nee to protect the access to this ressource as it may
// conflict with different thread. Please use cond_var_ to make sure
// everything is access on its due time.
bool ret = boolean_set_by_user_cmd_;
return ret;
}
dynamic_graph_manager::TestUserCmdBool::Request& req,
dynamic_graph_manager::TestUserCmdBool::Response& res)
{
// parse and register the command for further call.
std::bind(&SimpleDGM::user_command, this, req.input_boolean));
// return whatever the user want
res.sanity_check = true;
// the service has been executed properly
return true;
}
{
// here define a check for robot specific stuff.
bool check = true;
return check || DynamicGraphManager::is_in_safety_mode();
}
{
// fill all controls with zero... Check your robot to imagine what would
// be safer in this case.
for (dynamic_graph::VectorDGMap::iterator ctrl =
ctrl != motor_controls_map_.end();
++ctrl)
{
ctrl->second.fill(0.0);
}
}
private:
void user_command(bool user_input)
{
// do something with the internal state or with the hardware
boolean_set_by_user_cmd_ = user_input;
}
// some internal hardware class or obect. Here just a simple boolean for
// unit testing
std::atomic_bool boolean_set_by_user_cmd_;
// Control
dynamicgraph::Vector desired_torques_, desired_positions_;
};
} // namespace dynamic_graph_manager