teleop.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 "teleop.hpp"
22 
23 
24 namespace naoqi
25 {
26 namespace subscriber
27 {
28 
29 TeleopSubscriber::TeleopSubscriber( const std::string& name, const std::string& cmd_vel_topic, const std::string& joint_angles_topic, const qi::SessionPtr& session ):
30  cmd_vel_topic_(cmd_vel_topic),
31  joint_angles_topic_(joint_angles_topic),
32  BaseSubscriber( name, cmd_vel_topic, session ),
33  p_motion_( session->service("ALMotion") )
34 {}
35 
37 {
40 
41  is_initialized_ = true;
42 }
43 
44 void TeleopSubscriber::cmd_vel_callback( const geometry_msgs::TwistConstPtr& twist_msg )
45 {
46  // no need to check for max velocity since motion clamps the velocities internally
47  const float& vel_x = twist_msg->linear.x;
48  const float& vel_y = twist_msg->linear.y;
49  const float& vel_th = twist_msg->angular.z;
50 
51  std::cout << "going to move x: " << vel_x << " y: " << vel_y << " th: " << vel_th << std::endl;
52  p_motion_.async<void>("move", vel_x, vel_y, vel_th );
53 }
54 
55 void TeleopSubscriber::joint_angles_callback( const naoqi_bridge_msgs::JointAnglesWithSpeedConstPtr& js_msg )
56 {
57  if ( js_msg->relative==0 )
58  {
59  p_motion_.async<void>("setAngles", js_msg->joint_names, js_msg->joint_angles, js_msg->speed);
60  }
61  else
62  {
63  p_motion_.async<void>("changeAngles", js_msg->joint_names, js_msg->joint_angles, js_msg->speed);
64  }
65 }
66 
67 } //publisher
68 } // naoqi
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void joint_angles_callback(const naoqi_bridge_msgs::JointAnglesWithSpeedConstPtr &js_msg)
Definition: teleop.cpp:55
ros::Subscriber sub_joint_angles_
Definition: teleop.hpp:56
void cmd_vel_callback(const geometry_msgs::TwistConstPtr &twist_msg)
Definition: teleop.cpp:44
TeleopSubscriber(const std::string &name, const std::string &cmd_vel_topic, const std::string &joint_angles_topic, const qi::SessionPtr &session)
Definition: teleop.cpp:29
void reset(ros::NodeHandle &nh)
Definition: teleop.cpp:36


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