motor_chain.cpp
Go to the documentation of this file.
1 
4 
5 using namespace canopen;
6 
7 
8 class XmlRpcSettings : public Settings{
9 public:
11  XmlRpcSettings(const XmlRpc::XmlRpcValue &v) : value_(v) {}
12  XmlRpcSettings& operator=(const XmlRpc::XmlRpcValue &v) { value_ = v; return *this; }
13 private:
14  virtual bool getRepr(const std::string &n, std::string & repr) const {
15  if(value_.hasMember(n)){
16  std::stringstream sstr;
17  sstr << const_cast< XmlRpc::XmlRpcValue &>(value_)[n]; // does not write since already existing
18  repr = sstr.str();
19  return true;
20  }
21  return false;
22  }
24 
25 };
26 
27 
29  RosChain(nh, nh_priv), motor_allocator_("canopen_402", "canopen::MotorBase::Allocator") {}
30 
32 {
33  std::string name = params["name"];
34  std::string &joint = name;
35  if(params.hasMember("joint")) joint.assign(params["joint"]);
36 
37  if(!robot_layer_->getJoint(joint)){
38  ROS_ERROR_STREAM("joint " + joint + " was not found in URDF");
39  return false;
40  }
41 
42  std::string alloc_name = "canopen::Motor402::Allocator";
43  if(params.hasMember("motor_allocator")) alloc_name.assign(params["motor_allocator"]);
44 
45  XmlRpcSettings settings;
46  if(params.hasMember("motor_layer")) settings = params["motor_layer"];
47 
48  MotorBaseSharedPtr motor;
49 
50  try{
51  motor = motor_allocator_.allocateInstance(alloc_name, name + "_motor", node->getStorage(), settings);
52  }
53  catch( const std::exception &e){
54  std::string info = boost::diagnostic_information(e);
55  ROS_ERROR_STREAM(info);
56  return false;
57  }
58 
59  if(!motor){
60  ROS_ERROR_STREAM("Could not allocate motor.");
61  return false;
62  }
63 
64  motor->registerDefaultModes(node->getStorage());
65  motors_->add(motor);
66  logger->add(motor);
67 
68  boost::shared_ptr<HandleLayer> handle( new HandleLayer(joint, motor, node->getStorage(), params));
69 
71  if(!handle->prepareFilters(s)){
73  return false;
74  }
75 
76  robot_layer_->add(joint, handle);
77  logger->add(handle);
78 
79  return true;
80 }
81 
83  motors_.reset(new LayerGroupNoDiag<MotorBase>("402 Layer"));
84  robot_layer_.reset(new RobotLayer(nh_));
85 
86  ros::Duration dur(0.0) ;
87 
89  add(motors_);
91 
92  if(!nh_.param("use_realtime_period", false)){
93  dur.fromSec(boost::chrono::duration<double>(update_duration_).count());
94  ROS_INFO_STREAM("Using fixed control period: " << dur);
95  }else{
96  ROS_INFO("Using real-time control period");
97  }
98  cm_.reset(new ControllerManagerLayer(robot_layer_, nh_, dur));
99  add(cm_);
100 
101  return true;
102  }
103 
104  return false;
105 }
106 
virtual void add(const VectorMemberSharedPtr &l)
boost::shared_ptr< ControllerManagerLayer > cm_
Definition: motor_chain.h:20
XmlRpcServer s
const std::string reason() const
XmlRpcSettings(const XmlRpc::XmlRpcValue &v)
Definition: motor_chain.cpp:11
virtual bool setup_chain()
Definition: motor_chain.cpp:82
boost::shared_ptr< canopen::LayerGroupNoDiag< canopen::MotorBase > > motors_
Definition: motor_chain.h:17
virtual bool getRepr(const std::string &n, std::string &repr) const
Definition: motor_chain.cpp:14
Duration & fromSec(double t)
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
const std::string name
MotorChain(const ros::NodeHandle &nh, const ros::NodeHandle &nh_priv)
Definition: motor_chain.cpp:28
ClassAllocator< canopen::MotorBase > motor_allocator_
Definition: motor_chain.h:16
XmlRpc::XmlRpcValue value_
Definition: motor_chain.cpp:23
bool hasMember(const std::string &name) const
#define ROS_INFO_STREAM(args)
virtual bool setup_chain()
virtual bool nodeAdded(XmlRpc::XmlRpcValue &params, const canopen::NodeSharedPtr &node, const LoggerSharedPtr &logger)
Definition: motor_chain.cpp:31
time_duration update_duration_
#define ROS_ERROR_STREAM(args)
XmlRpcSettings & operator=(const XmlRpc::XmlRpcValue &v)
Definition: motor_chain.cpp:12
ros::NodeHandle nh_
RobotLayerSharedPtr robot_layer_
Definition: motor_chain.h:18


canopen_motor_node
Author(s): Mathias Lüdtke
autogenerated on Sat May 4 2019 02:40:47