43 if (!handle || !handle->
connected())
return false;
44 std::string resource = handle->
getName();
50 if (!handle || !handle->
connected())
return false;
51 std::string resource = handle->
getName();
52 std::map<std::string, const CommandHandle *>::iterator it =
enabled_.find(resource);
55 ROS_INFO_NAMED(
"quadrotor_interface",
"Enabled %s output", resource.c_str());
57 }
else if (it->second == handle) {
65 if (!handle)
return false;
66 std::string resource = handle->
getName();
67 std::map<std::string, const CommandHandle *>::iterator it =
enabled_.find(resource);
68 if (it !=
enabled_.end() && it->second == handle) {
70 ROS_INFO_NAMED(
"quadrotor_interface",
"Disabled %s control", resource.c_str());
79 std::string resource = handle->
getName();
82 if (input.get() != handle) input->reset();
86 if (output.get() != handle) output->reset();
91 std::string resource = handle->
getName();
96 output->setPreempted();
110 const Quaternion::_w_type& w = pose().orientation.w;
111 const Quaternion::_x_type& x = pose().orientation.x;
112 const Quaternion::_y_type& y = pose().orientation.y;
113 const Quaternion::_z_type& z = pose().orientation.z;
114 roll =
atan2(2.*y*z + 2.*w*x, z*z - y*y - x*x + w*w);
115 pitch = -
asin(2.*x*z - 2.*w*y);
116 yaw =
atan2(2.*x*y + 2.*w*z, x*x + w*w - z*z - y*y);
121 const Quaternion::_w_type& w = pose().orientation.w;
122 const Quaternion::_x_type& x = pose().orientation.x;
123 const Quaternion::_y_type& y = pose().orientation.y;
124 const Quaternion::_z_type& z = pose().orientation.z;
125 return atan2(2.*x*y + 2.*w*z, x*x + w*w - z*z - y*y);
130 const Quaternion::_w_type& w = pose().orientation.w;
131 const Quaternion::_x_type& x = pose().orientation.x;
132 const Quaternion::_y_type& y = pose().orientation.y;
133 const Quaternion::_z_type& z = pose().orientation.z;
135 body.x = (w*w+x*x-y*y-z*z) * nav.x + (2.*x*y + 2.*w*z) * nav.y + (2.*x*z - 2.*w*y) * nav.z;
136 body.y = (2.*x*y - 2.*w*z) * nav.x + (w*w-x*x+y*y-z*z) * nav.y + (2.*y*z + 2.*w*x) * nav.z;
137 body.z = (2.*x*z + 2.*w*y) * nav.x + (2.*y*z - 2.*w*x) * nav.y + (w*w-x*x-y*y+z*z) * nav.z;
143 const Quaternion::_w_type& w = pose().orientation.w;
144 const Quaternion::_x_type& x = pose().orientation.x;
145 const Quaternion::_y_type& y = pose().orientation.y;
146 const Quaternion::_z_type& z = pose().orientation.z;
148 nav.x = (w*w+x*x-y*y-z*z) * body.x + (2.*x*y - 2.*w*z) * body.y + (2.*x*z + 2.*w*y) * body.z;
149 nav.y = (2.*x*y + 2.*w*z) * body.x + (w*w-x*x+y*y-z*z) * body.y + (2.*y*z - 2.*w*x) * body.z;
150 nav.z = (2.*x*z - 2.*w*y) * body.x + (2.*y*z + 2.*w*x) * body.y + (w*w-x*x-y*y+z*z) * body.z;
157 x -= pose.
get()->position.x;
158 y -= pose.
get()->position.y;
171 get()->z =
sin(command / 2.);
172 get()->w =
cos(command / 2.);
181 if (scalar_)
return *scalar_;
182 const Quaternion::_w_type& w =
get()->w;
183 const Quaternion::_x_type& x =
get()->x;
184 const Quaternion::_y_type& y =
get()->y;
185 const Quaternion::_z_type& z =
get()->z;
186 return atan2(2.*x*y + 2.*w*z, x*x + w*w - z*z - y*y);
191 command.orientation = *
get();
195 command.orientation.x = 0.0;
196 command.orientation.y = 0.0;
197 command.orientation.z =
sin(*scalar_ / 2.);
198 command.orientation.x =
cos(*scalar_ / 2.);
205 static const double M_2PI = 2.0 * M_PI;
207 error -= floor(error / M_2PI) * M_2PI;
#define ROS_INFO_NAMED(name,...)
Vector3 toBody(const Vector3 &nav) const
void getError(const PoseHandle &pose, double &x, double &y) const
virtual ~QuadrotorInterface()
void setCommand(double command)
bool start(const CommandHandle *handle)
void disconnect(const CommandHandle *handle)
bool stop(const CommandHandle *handle)
Vector3 fromBody(const Vector3 &nav) const
virtual bool connected() const =0
virtual const std::string & getName() const
const Pose * getPoseCommand() const
std::map< std::string, CommandHandlePtr > outputs_
INLINE Rall1d< T, V, S > asin(const Rall1d< T, V, S > &x)
const Wrench * getWrenchCommand() const
HandleType::ValueType const * getCommand(const std::string &name) const
bool enabled(const CommandHandle *handle) const
double getError(const PoseHandle &pose) const
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
bool preempt(const CommandHandle *handle)
std::map< std::string, const CommandHandle * > enabled_
double getError(const PoseHandle &pose) const
const ValueType * get() const
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
const Twist * getTwistCommand() const
const MotorCommand * getMotorCommand() const
bool update(Pose &command) const
void getEulerRPY(double &roll, double &pitch, double &yaw) const
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
double getCommand() const
std::map< std::string, CommandHandlePtr > inputs_