vpROSRobotPioneer.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * $Id: vpROSRobotPioneer.cpp 4574 2014-01-09 08:48:51Z fpasteau $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Interface for Pioneer robots based on ROS middleware.
36  *
37  * Authors:
38  * Francois Pasteau
39  *
40  *****************************************************************************/
41 
42 #include <std_srvs/Empty.h>
43 #include <visp/vpConfig.h>
44 #include <visp/vpMath.h>
45 #include <visp/vpRobotException.h>
47 
52  : vpPioneer()
53 {
54 }
55 
58 {
59  stopMotion();
60  disableMotors();
61 }
62 
64 void
66 {
68  enableMotors();
69 }
70 
71 void
72 vpROSRobotPioneer::init( int argc, char **argv )
73 {
74  vpROSRobot::init( argc, argv );
75  enableMotors();
76 }
77 
95 void
96 vpROSRobotPioneer::setVelocity( const vpRobot::vpControlFrameType frame, const vpColVector &vel )
97 {
98  if ( !isInitialized )
99  {
100  throw( vpRobotException( vpRobotException::notInitialized, "ROS robot pioneer is not initialized" ) );
101  }
102 
103  if ( vel.size() != 2 )
104  {
105  throw( vpRobotException( vpRobotException::dimensionError, "Velocity vector is not a 2 dimension vector" ) );
106  }
107 
108  vpColVector vel_max( 2 );
109  vpColVector vel_sat;
110  vpColVector vel_robot( 6 );
111 
112  if ( frame == vpRobot::REFERENCE_FRAME )
113  {
114  vel_max[0] = getMaxTranslationVelocity();
115  vel_max[1] = getMaxRotationVelocity();
116 
117  vel_sat = vpRobot::saturateVelocities( vel, vel_max, true );
118  vel_robot[0] = vel_sat[0];
119  vel_robot[1] = 0;
120  vel_robot[2] = 0;
121  vel_robot[3] = 0;
122  vel_robot[4] = 0;
123  vel_robot[5] = vel_sat[1];
124  vpROSRobot::setVelocity( frame, vel_robot );
125  }
126  else
127  {
128  throw vpRobotException( vpRobotException::wrongStateError,
129  "Cannot send the robot velocity in the specified control frame" );
130  }
131 }
132 
133 void
135 {
136  ros::ServiceClient client = n->serviceClient< std_srvs::Empty >( "/RosAria/enable_motors" );
137  std_srvs::Empty srv;
138  if ( !client.call( srv ) )
139  {
140  ROS_ERROR( "Unable to enable motors" );
141  }
142 }
143 
144 void
146 {
147  ros::ServiceClient client = n->serviceClient< std_srvs::Empty >( "/RosAria/disable_motors" );
148  std_srvs::Empty srv;
149  if ( !client.call( srv ) )
150  {
151  ROS_ERROR( "Unable to disable motors" );
152  }
153 }
vpROSRobotPioneer::~vpROSRobotPioneer
~vpROSRobotPioneer()
destructor
Definition: vpROSRobotPioneer.cpp:57
vpROSRobotPioneer.h
vpROSRobot::init
void init()
basic initialization
Definition: vpROSRobot.cpp:113
ros::NodeHandle::serviceClient
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
vpROSRobotPioneer::init
void init()
basic initialization
Definition: vpROSRobotPioneer.cpp:65
vpROSRobotPioneer::disableMotors
void disableMotors()
Definition: vpROSRobotPioneer.cpp:145
vpROSRobot::setVelocity
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
Definition: vpROSRobot.cpp:149
vpROSRobotPioneer::enableMotors
void enableMotors()
Definition: vpROSRobotPioneer.cpp:134
ROS_ERROR
#define ROS_ERROR(...)
ros::ServiceClient
vpROSRobot::n
ros::NodeHandle * n
Definition: vpROSRobot.h:65
vpROSRobotPioneer::vpROSRobotPioneer
vpROSRobotPioneer()
Definition: vpROSRobotPioneer.cpp:51
ros::ServiceClient::call
bool call(const MReq &req, MRes &resp, const std::string &service_md5sum)
vpROSRobot::stopMotion
void stopMotion()
Definition: vpROSRobot.cpp:285
vpROSRobot::isInitialized
bool isInitialized
Definition: vpROSRobot.h:70
vpROSRobotPioneer::setVelocity
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
Definition: vpROSRobotPioneer.cpp:96


visp_ros
Author(s): Francois Pasteau, Fabien Spindler, Gatien Gaumerais, Alexander Oliva
autogenerated on Wed Mar 2 2022 01:13:33