43 if (!handle || !handle->
connected())
return false;
44 std::string resource = handle->
getName();
50 if (!handle || !handle->
connected())
return false;
51 if (
enabled(handle))
return true;
52 std::string resource = handle->
getName();
54 ROS_DEBUG_NAMED(
"quadrotor_interface",
"Enabled %s control", resource.c_str());
62 std::string resource = handle->
getName();
63 std::map<std::string, const CommandHandle *>::iterator it =
enabled_.lower_bound(resource);
65 ROS_DEBUG_NAMED(
"quadrotor_interface",
"Disabled %s control", resource.c_str());
71 std::string resource = handle->
getName();
74 if (input.get() != handle) input->reset();
78 if (output.get() != handle) output->reset();
89 const Quaternion::_w_type& w = pose().orientation.w;
90 const Quaternion::_x_type& x = pose().orientation.x;
91 const Quaternion::_y_type& y = pose().orientation.y;
92 const Quaternion::_z_type& z = pose().orientation.z;
93 roll = atan2(2.*y*z + 2.*w*x, z*z - y*y - x*x + w*w);
94 pitch = -asin(2.*x*z - 2.*w*y);
95 yaw = atan2(2.*x*y + 2.*w*z, x*x + w*w - z*z - y*y);
100 const Quaternion::_w_type& w = pose().orientation.w;
101 const Quaternion::_x_type& x = pose().orientation.x;
102 const Quaternion::_y_type& y = pose().orientation.y;
103 const Quaternion::_z_type& z = pose().orientation.z;
104 return atan2(2.*x*y + 2.*w*z, x*x + w*w - z*z - y*y);
109 const Quaternion::_w_type& w = pose().orientation.w;
110 const Quaternion::_x_type& x = pose().orientation.x;
111 const Quaternion::_y_type& y = pose().orientation.y;
112 const Quaternion::_z_type& z = pose().orientation.z;
114 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;
115 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;
116 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;
122 const Quaternion::_w_type& w = pose().orientation.w;
123 const Quaternion::_x_type& x = pose().orientation.x;
124 const Quaternion::_y_type& y = pose().orientation.y;
125 const Quaternion::_z_type& z = pose().orientation.z;
127 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;
128 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;
129 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;
136 x -= pose.
get()->position.x;
137 y -= pose.
get()->position.y;
150 get()->z = sin(command / 2.);
151 get()->w = cos(command / 2.);
160 if (scalar_)
return *scalar_;
161 const Quaternion::_w_type& w =
get()->w;
162 const Quaternion::_x_type& x =
get()->x;
163 const Quaternion::_y_type& y =
get()->y;
164 const Quaternion::_z_type& z =
get()->z;
165 return atan2(2.*x*y + 2.*w*z, x*x + w*w - z*z - y*y);
170 command.orientation = *
get();
174 command.orientation.x = 0.0;
175 command.orientation.y = 0.0;
176 command.orientation.z = sin(*scalar_ / 2.);
177 command.orientation.x = cos(*scalar_ / 2.);
184 static const double M_2PI = 2.0 * M_PI;
186 error -= floor(error / M_2PI) * M_2PI;
virtual ~QuadrotorInterface()
const ValueType * get() const
bool enabled(const CommandHandle *handle) const
HandleType::ValueType const * getCommand(const std::string &name) const
std::map< std::string, CommandHandlePtr > outputs_
bool start(const CommandHandle *handle)
void setCommand(double command)
virtual bool connected() const =0
virtual const Wrench * getWrenchCommand() const
std::map< std::string, const CommandHandle * > enabled_
#define ROS_DEBUG_NAMED(name,...)
void stop(const CommandHandle *handle)
virtual const Twist * getTwistCommand() const
virtual const std::string & getName() const
virtual const MotorCommand * getMotorCommand() const
Vector3 toBody(const Vector3 &nav) const
double getError(const PoseHandle &pose) const
double getCommand() const
std::map< std::string, CommandHandlePtr > inputs_
double getError(const PoseHandle &pose) const
void disconnect(const CommandHandle *handle)
Vector3 fromBody(const Vector3 &nav) const
void getError(const PoseHandle &pose, double &x, double &y) const
void getEulerRPY(double &roll, double &pitch, double &yaw) const
bool update(Pose &command) const
virtual const Pose * getPoseCommand() const