Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "teleop.hpp"
00022
00023
00024 namespace naoqi
00025 {
00026 namespace subscriber
00027 {
00028
00029 TeleopSubscriber::TeleopSubscriber( const std::string& name, const std::string& cmd_vel_topic, const std::string& joint_angles_topic, const qi::SessionPtr& session ):
00030 cmd_vel_topic_(cmd_vel_topic),
00031 joint_angles_topic_(joint_angles_topic),
00032 BaseSubscriber( name, cmd_vel_topic, session ),
00033 p_motion_( session->service("ALMotion") )
00034 {}
00035
00036 void TeleopSubscriber::reset( ros::NodeHandle& nh )
00037 {
00038 sub_cmd_vel_ = nh.subscribe( cmd_vel_topic_, 10, &TeleopSubscriber::cmd_vel_callback, this );
00039 sub_joint_angles_ = nh.subscribe( joint_angles_topic_, 10, &TeleopSubscriber::joint_angles_callback, this );
00040
00041 is_initialized_ = true;
00042 }
00043
00044 void TeleopSubscriber::cmd_vel_callback( const geometry_msgs::TwistConstPtr& twist_msg )
00045 {
00046
00047 const float& vel_x = twist_msg->linear.x;
00048 const float& vel_y = twist_msg->linear.y;
00049 const float& vel_th = twist_msg->angular.z;
00050
00051 std::cout << "going to move x: " << vel_x << " y: " << vel_y << " th: " << vel_th << std::endl;
00052 p_motion_.async<void>("move", vel_x, vel_y, vel_th );
00053 }
00054
00055 void TeleopSubscriber::joint_angles_callback( const naoqi_bridge_msgs::JointAnglesWithSpeedConstPtr& js_msg )
00056 {
00057 if ( js_msg->relative==0 )
00058 {
00059 p_motion_.async<void>("setAngles", js_msg->joint_names, js_msg->joint_angles, js_msg->speed);
00060 }
00061 else
00062 {
00063 p_motion_.async<void>("changeAngles", js_msg->joint_names, js_msg->joint_angles, js_msg->speed);
00064 }
00065 }
00066
00067 }
00068 }