joint.h
Go to the documentation of this file.
1 
5 #ifndef JOINT_H
6 #define JOINT_H
7 
9 #include <urdf_parser/urdf_parser.h>
10 #include <urdf_model/joint.h>
11 #include <urdf_model/link.h>
12 #include <urdf_model/pose.h>
13 #include <stdexcept>
14 
15 namespace ackermann_controller {
16 
17 struct JointBase
18 {
20  const std::string& name,
21  const std::string& base_link_name,
23  ):
24  name_(name)
25  {
26  urdf::Vector3 position;
27  joint_ = model->getJoint(name_);
29 
30  if (!joint)
31  {
32  throw std::runtime_error(name_ + " couldn't be retrieved from model description");
33  }
34 
35  while (joint && joint->parent_link_name != base_link_name)
36  {
37  urdf::Pose transform = joint->parent_to_joint_origin_transform;
38  position = transform.position + transform.rotation * position;
39 
40  boost::shared_ptr<const urdf::Link> link = model->getLink(joint->parent_link_name);
41  joint = link->parent_joint;
42  }
43 
44  lateral_deviation_ = position.y;
45  }
46 
47  std::string name_;
51 };
52 
53 struct Joint: public JointBase
54 {
56  const std::string& name,
57  const std::string& base_link_name,
60  ):
61  JointBase(name, base_link_name, model),
62  handle_(handle)
63  {}
64 
65  virtual double getPosition() const
66  {
67  return handle_.getPosition();
68  }
69 
71 };
72 
73 struct ActuatedJoint: public JointBase
74 {
76  const std::string& name,
77  const std::string& base_link_name,
80  ):
81  JointBase(name, base_link_name, model),
82  handle_(handle)
83  {}
84 
85  virtual double getPosition() const
86  {
87  return handle_.getPosition();
88  }
89 
90  void setCommand(double command)
91  {
92  handle_.setCommand(command);
93  }
94 
96 };
97 
98 struct WheelBase
99 {
101  const std::string& child_link_name,
103  {
104  boost::shared_ptr<const urdf::Link> link = model->getLink(child_link_name);
105 
106  if (!link)
107  {
108  throw std::runtime_error("Link not found");
109  }
110 
111  if (!link->collision)
112  {
113  throw std::runtime_error("Link " + link->name + " does not have collision description. Add collision description for link to urdf.");
114  }
115 
116  if (!link->collision->geometry)
117  {
118  throw std::runtime_error("Link " + link->name + " does not have collision geometry description. Add collision geometry description for link to urdf.");
119  }
120 
121  if (link->collision->geometry->type != urdf::Geometry::CYLINDER)
122  {
123  throw std::runtime_error("Link " + link->name + " does not have cylinder geometry");
124  }
125 
126  radius_ = (static_cast<urdf::Cylinder*>(link->collision->geometry.get()))->radius;
127  }
128 
129  double radius_;
130 };
131 
132 struct Wheel: public Joint, public WheelBase
133 {
135  const std::string& name,
136  const std::string& base_link_name,
139  ):
140  Joint(name, base_link_name, model, handle),
141  WheelBase(joint_->child_link_name, model)
142  {}
143 };
144 
145 struct ActuatedWheel: public ActuatedJoint, public WheelBase
146 {
148  const std::string& name,
149  const std::string& base_link_name,
152  ):
153  ActuatedJoint(name, base_link_name, model, handle),
154  WheelBase(joint_->child_link_name, model)
155  {}
156 };
157 
158 }
159 
160 #endif
hardware_interface::JointStateHandle handle_
Definition: joint.h:50
void setCommand(double command)
Definition: joint.h:90
hardware_interface::JointStateHandle handle_
Definition: joint.h:70
virtual double getPosition() const
Definition: joint.h:85
boost::shared_ptr< const urdf::Joint > joint_
Definition: joint.h:49
virtual double getPosition() const
Definition: joint.h:65
hardware_interface::JointHandle handle_
Definition: joint.h:95
WheelBase(const std::string &child_link_name, boost::shared_ptr< urdf::ModelInterface > model)
Definition: joint.h:100
ActuatedJoint(const std::string &name, const std::string &base_link_name, boost::shared_ptr< urdf::ModelInterface > model, hardware_interface::JointHandle handle)
Definition: joint.h:75
Joint(const std::string &name, const std::string &base_link_name, boost::shared_ptr< urdf::ModelInterface > model, hardware_interface::JointStateHandle handle)
Definition: joint.h:55
Wheel(const std::string &name, const std::string &base_link_name, boost::shared_ptr< urdf::ModelInterface > model, hardware_interface::JointStateHandle handle)
Definition: joint.h:134
ActuatedWheel(const std::string &name, const std::string &base_link_name, boost::shared_ptr< urdf::ModelInterface > model, hardware_interface::JointHandle handle)
Definition: joint.h:147
JointBase(const std::string &name, const std::string &base_link_name, boost::shared_ptr< urdf::ModelInterface > model)
Definition: joint.h:19


ackermann_controller
Author(s): GĂ©rald Lelong
autogenerated on Mon Jun 10 2019 12:44:48