actuator_array_driver.h
Go to the documentation of this file.
00001 /*
00002  *  Copyright (c) 2011, A.M.Howard, S.Williams
00003  *  All rights reserved.
00004  *
00005  *  Redistribution and use in source and binary forms, with or without
00006  *  modification, are permitted provided that the following conditions are met:
00007  *      * Redistributions of source code must retain the above copyright
00008  *        notice, this list of conditions and the following disclaimer.
00009  *      * Redistributions in binary form must reproduce the above copyright
00010  *        notice, this list of conditions and the following disclaimer in the
00011  *        documentation and/or other materials provided with the distribution.
00012  *      * Neither the name of the <organization> nor the
00013  *        names of its contributors may be used to endorse or promote products
00014  *        derived from this software without specific prior written permission.
00015  *
00016  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017  *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018  *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *  DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00020  *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021  *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 /*
00028  * actuator_array_driver.h
00029  *
00030  *  Created on: Feb 24, 2011
00031  *      Author: swilliams8
00032  */
00033 
00034 #ifndef ACTUATOR_ARRAY_DRIVER_H_
00035 #define ACTUATOR_ARRAY_DRIVER_H_
00036 
00037 #include <ros/ros.h>
00038 #include <sensor_msgs/JointState.h>
00039 #include <std_srvs/Empty.h>
00040 #include <urdf/model.h>
00041 
00042 namespace actuator_array_driver
00043 {
00044 
00045 /*
00046  * A structure that holds standard information about each joint. If additional information is needed, a derived structure
00047  * can be provided to the ActuatorArrayDriver base class.
00048  */
00049 struct JointProperties
00050 {
00051   bool has_position_limits;
00052   double min_position;
00053   double max_position;
00054   bool has_velocity_limits;
00055   double max_velocity;
00056   bool has_acceleration_limits;
00057   double max_acceleration;
00058   bool has_effort_limits;
00059   double max_effort;
00060   double friction;
00061   double damping;
00062 };
00063 
00064 /*
00065  * This package contains a base class for an Actuator Array Driver. This is intended for use with chains of R/C Servos or other
00066  * similar devices where position (and velocity) commands are sent at irregular intervals, as opposed to the tight, real-time
00067  * control loop of the PR2 Controller Manager system.
00068  *
00069  * This base class performs some standard functionality, such as parsing joint limits out of the robot_description, subscribing to
00070  * a 'command' topic, publishing on the 'joint_states' topic, and setting up a 'stop' and 'home' service call. This is designed to
00071  * work as a stand-alone driver for controlling/tele-operating a chain of servos, or in conjunction with the Actuatory Array
00072  * Joint Trajectory Action. This class is provided as a convenience only, and is not required for successful operation with the
00073  * Actuator Array Joint Trajectory Action.
00074  *
00075  * The base class is templated on a JOINT structure. If no additional data is needed, the provided JointProperties can be used
00076  * as the template argument. If additional information needs to be stored on a per-joint basis, then the JointProperties class
00077  * can be used as a base for a custom JOINT structure.
00078  */
00079 template<class JOINT>
00080 class ActuatorArrayDriver
00081 {
00082 public:
00083   ActuatorArrayDriver();
00084   virtual ~ActuatorArrayDriver();
00085 
00088   void read_and_publish();
00089 
00093   void spin();
00094 
00095 
00096 protected:
00098   ros::Subscriber command_sub_;
00099 
00101   sensor_msgs::JointState command_msg_;
00102 
00106   void command_callback(const sensor_msgs::JointState::ConstPtr& command_msg);
00107 
00109   ros::ServiceServer stop_srv_;
00110 
00112   bool stop_callback(std_srvs::Empty::Request& req, std_srvs::Empty::Response& res);
00113 
00115   ros::ServiceServer home_srv_;
00116 
00118   bool home_callback(std_srvs::Empty::Request& req, std_srvs::Empty::Response& res);
00119 
00121   ros::Publisher joint_state_pub_;
00122 
00124   sensor_msgs::JointState joint_state_msg_;
00125 
00128   std::string robot_description_parameter_;
00129 
00131   urdf::Model urdf_model_;
00132 
00134   std::map<std::string, JOINT> joints_;
00135 
00139   void parse_urdf(const ros::NodeHandle& node);
00140 
00145   void update_joint_from_urdf(const std::string& joint_name, JOINT& joint_properties);
00146 
00158   void parse_actuator_list(const ros::NodeHandle& node);
00159 
00164   void advertise_and_subscribe(ros::NodeHandle& node);
00165 
00172   void init();
00173 
00177   // a convenience function that allows a single YAML configuration file to both
00181   virtual bool init_actuator_(const std::string& joint_name, JOINT& joint_properties, XmlRpc::XmlRpcValue& joint_data) {return true;};
00182 
00185   virtual bool read_(ros::Time ts = ros::Time::now()) {return true;};
00186 
00190   virtual bool command_() {return true;};
00191 
00194   virtual bool stop_() {return true;};
00195 
00198   virtual bool home_() {return true;};
00199 
00200 };
00201 
00202 }
00203 
00204 #include <actuator_array_driver/actuator_array_driver_impl.h>
00205 
00206 #endif /* ACTUATOR_ARRAY_DRIVER_H_ */


actuator_array_driver
Author(s): Stephen Williams
autogenerated on Wed Nov 27 2013 12:00:24