odom.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Aldebaran
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 /*
19 * LOCAL includes
20 */
21 #include "odom.hpp"
22 #include "../tools/from_any_value.hpp"
23 
24 /*
25 * BOOST includes
26 */
27 #include <boost/foreach.hpp>
28 #define for_each BOOST_FOREACH
29 
30 
32 
33 namespace naoqi
34 {
35 namespace converter
36 {
37 
38 OdomConverter::OdomConverter( const std::string& name, const float& frequency, const qi::SessionPtr& session ):
39  BaseConverter( name, frequency, session ),
40  p_motion_( session->service("ALMotion") )
41 
42 {
43 }
44 
46 {
47  callbacks_[action] = cb;
48 }
49 
50 void OdomConverter::callAll( const std::vector<message_actions::MessageAction>& actions )
51 {
52 
53  int FRAME_WORLD = 1;
54  bool use_sensor = true;
55  // documentation of getPosition available here: http://doc.aldebaran.com/2-1/naoqi/motion/control-cartesian.html
56  std::vector<float> al_odometry_data = p_motion_.call<std::vector<float> >( "getPosition", "Torso", FRAME_WORLD, use_sensor );
57 
58  const ros::Time& odom_stamp = ros::Time::now();
59  std::vector<float> al_speed_data = p_motion_.call<std::vector<float> >( "getRobotVelocity" );
60 
61  const float& odomX = al_odometry_data[0];
62  const float& odomY = al_odometry_data[1];
63  const float& odomZ = al_odometry_data[2];
64  const float& odomWX = al_odometry_data[3];
65  const float& odomWY = al_odometry_data[4];
66  const float& odomWZ = al_odometry_data[5];
67 
68  const float& dX = al_speed_data[0];
69  const float& dY = al_speed_data[1];
70  const float& dWZ = al_speed_data[2];
71 
72  //since all odometry is 6DOF we'll need a quaternion created from yaw
73  tf2::Quaternion tf_quat;
74  tf_quat.setRPY( odomWX, odomWY, odomWZ );
75  geometry_msgs::Quaternion odom_quat = tf2::toMsg( tf_quat );
76 
77  static nav_msgs::Odometry msg_odom;
78  msg_odom.header.frame_id = "odom";
79  msg_odom.child_frame_id = "base_link";
80  msg_odom.header.stamp = odom_stamp;
81 
82  msg_odom.pose.pose.orientation = odom_quat;
83  msg_odom.pose.pose.position.x = odomX;
84  msg_odom.pose.pose.position.y = odomY;
85  msg_odom.pose.pose.position.z = odomZ;
86 
87  msg_odom.twist.twist.linear.x = dX;
88  msg_odom.twist.twist.linear.y = dY;
89  msg_odom.twist.twist.linear.z = 0;
90 
91  msg_odom.twist.twist.angular.x = 0;
92  msg_odom.twist.twist.angular.y = 0;
93  msg_odom.twist.twist.angular.z = dWZ;
94 
96  {
97  callbacks_[action](msg_odom);
98 
99  }
100 }
101 
103 {
104 }
105 
106 } //converter
107 } // naoqi
void setRPY(const tf2Scalar &roll, const tf2Scalar &pitch, const tf2Scalar &yaw)
#define for_each
Definition: odom.cpp:28
OdomConverter(const std::string &name, const float &frequency, const qi::SessionPtr &session)
Definition: odom.cpp:38
boost::function< void(nav_msgs::Odometry &)> Callback_t
Definition: odom.hpp:40
void registerCallback(message_actions::MessageAction action, Callback_t cb)
Definition: odom.cpp:45
action
B toMsg(const A &a)
std::map< message_actions::MessageAction, Callback_t > callbacks_
Definition: odom.hpp:56
static Time now()
void callAll(const std::vector< message_actions::MessageAction > &actions)
Definition: odom.cpp:50


naoqi_driver
Author(s): Karsten Knese
autogenerated on Sat Feb 15 2020 03:24:26