-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add copies of upstream effort_controllers to take SharedHWInterface
The normal ros_controllers/effort_controllers used by the SawyerControllers to control each joint do not allow a subclass of the EffortJointInterface to be passed in as a replacement. Thus, we need to (temporarily) copy in the upstream effort_controllers so that we can change them to take the SharedJointInterface. We should remove these copies once we can upstream a change to make the init() and constructor virtual (or some similar modification) so that interfaces that inherit from EffortJointInterface can be used instead.
- Loading branch information
1 parent
32b9555
commit 430644e
Showing
16 changed files
with
1,020 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
sawyer_sim_controllers/include/sawyer_sim_controllers/sawyer_joint_effort_controller.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/********************************************************************* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Copyright (c) 2008, Willow Garage, Inc. | ||
* Copyright (c) 2012, hiDOF, Inc. | ||
* Copyright (c) 2013, PAL Robotics, S.L. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of the Willow Garage nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*********************************************************************/ | ||
|
||
#ifndef SAWYER_EFFORT_CONTROLLERS__JOINT_EFFORT_CONTROLLER_H | ||
#define SAWYER_EFFORT_CONTROLLERS__JOINT_EFFORT_CONTROLLER_H | ||
|
||
#include <forward_command_controller/forward_command_controller.h> | ||
|
||
#include <sawyer_hardware_interface/shared_joint_interface.h> | ||
|
||
namespace sawyer_effort_controllers | ||
{ | ||
|
||
/** | ||
* \brief Joint Effort Controller (torque or force) | ||
* | ||
* This class passes the commanded effort down to the joint. | ||
* | ||
* \section ROS interface | ||
* | ||
* \param type Must be "JointEffortController". | ||
* \param joint Name of the joint to control. | ||
* | ||
* Subscribes to: | ||
* - \b command (std_msgs::Float64) : The joint effort to apply. | ||
*/ | ||
class JointEffortController : public forward_command_controller::ForwardCommandController<sawyer_hardware_interface::SharedJointInterface> | ||
{ | ||
public: | ||
bool init(sawyer_hardware_interface::SharedJointInterface* hw, ros::NodeHandle &n); | ||
bool init(sawyer_hardware_interface::SharedJointInterface* hw, ros::NodeHandle &n, const std::string& ctrl_type); | ||
}; | ||
|
||
} // namespace | ||
|
||
#endif |
208 changes: 208 additions & 0 deletions
208
sawyer_sim_controllers/include/sawyer_sim_controllers/sawyer_joint_position_controller.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
/********************************************************************* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Copyright (c) 2008, Willow Garage, Inc. | ||
* Copyright (c) 2012, hiDOF, Inc. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of the Willow Garage nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*********************************************************************/ | ||
|
||
#ifndef SAWYER_EFFORT_CONTROLLERS__JOINT_POSITION_CONTROLLER_H | ||
#define SAWYER_EFFORT_CONTROLLERS__JOINT_POSITION_CONTROLLER_H | ||
|
||
/** | ||
@class effort_controllers::JointPositionController | ||
@brief Joint Position Controller | ||
This class controls positon using a pid loop. | ||
@section ROS ROS interface | ||
@param type Must be "effort_controllers::JointPositionController" | ||
@param joint Name of the joint to control. | ||
@param pid Contains the gains for the PID loop around position. See: control_toolbox::Pid | ||
Subscribes to: | ||
- @b command (std_msgs::Float64) : The joint position to achieve. | ||
Publishes: | ||
- @b state (control_msgs::JointControllerState) : | ||
Current state of the controller, including pid error and gains. | ||
*/ | ||
|
||
#include <ros/node_handle.h> | ||
#include <urdf/model.h> | ||
#include <control_toolbox/pid.h> | ||
#include <boost/scoped_ptr.hpp> | ||
#include <boost/thread/condition.hpp> | ||
#include <realtime_tools/realtime_publisher.h> | ||
#include <hardware_interface/joint_command_interface.h> | ||
#include <controller_interface/controller.h> | ||
#include <control_msgs/JointControllerState.h> | ||
#include <std_msgs/Float64.h> | ||
#include <control_msgs/JointControllerState.h> | ||
#include <realtime_tools/realtime_buffer.h> | ||
|
||
#include <sawyer_hardware_interface/shared_joint_interface.h> | ||
|
||
|
||
namespace sawyer_effort_controllers | ||
{ | ||
|
||
class JointPositionController: public controller_interface::Controller<sawyer_hardware_interface::SharedJointInterface> | ||
{ | ||
public: | ||
|
||
/** | ||
* \brief Store position and velocity command in struct to allow easier realtime buffer usage | ||
*/ | ||
struct Commands | ||
{ | ||
double position_; // Last commanded position | ||
double velocity_; // Last commanded velocity | ||
bool has_velocity_; // false if no velocity command has been specified | ||
}; | ||
|
||
JointPositionController(); | ||
~JointPositionController(); | ||
|
||
/** \brief The init function is called to initialize the controller from a | ||
* non-realtime thread with a pointer to the hardware interface, itself, | ||
* instead of a pointer to a RobotHW. | ||
* | ||
* \param robot The specific hardware interface used by this controller. | ||
* | ||
* \param n A NodeHandle in the namespace from which the controller | ||
* should read its configuration, and where it should set up its ROS | ||
* interface. | ||
* | ||
* \returns True if initialization was successful and the controller | ||
* is ready to be started. | ||
*/ | ||
bool init(sawyer_hardware_interface::SharedJointInterface *robot, ros::NodeHandle &n); | ||
bool init(sawyer_hardware_interface::SharedJointInterface *robot, ros::NodeHandle &n, const std::string& ctrl_type) | ||
{ | ||
// ctrl_type is no-op for non-effort control | ||
return init(robot, n); | ||
} | ||
|
||
/*! | ||
* \brief Give set position of the joint for next update: revolute (angle) and prismatic (position) | ||
* | ||
* \param command | ||
*/ | ||
void setCommand(double pos_target); | ||
|
||
/*! | ||
* \brief Give set position of the joint for next update: revolute (angle) and prismatic (position) | ||
* Also supports a target velocity | ||
* | ||
* \param pos_target - position setpoint | ||
* \param vel_target - velocity setpoint | ||
*/ | ||
void setCommand(double pos_target, double vel_target); | ||
|
||
/** \brief This is called from within the realtime thread just before the | ||
* first call to \ref update | ||
* | ||
* \param time The current time | ||
*/ | ||
void starting(const ros::Time& time); | ||
|
||
/*! | ||
* \brief Issues commands to the joint. Should be called at regular intervals | ||
*/ | ||
void update(const ros::Time& time, const ros::Duration& period); | ||
|
||
/** | ||
* \brief Get the PID parameters | ||
*/ | ||
void getGains(double &p, double &i, double &d, double &i_max, double &i_min); | ||
|
||
/** | ||
* \brief Get the PID parameters | ||
*/ | ||
void getGains(double &p, double &i, double &d, double &i_max, double &i_min, bool &antiwindup); | ||
|
||
/** | ||
* \brief Print debug info to console | ||
*/ | ||
void printDebug(); | ||
|
||
/** | ||
* \brief Get the PID parameters | ||
*/ | ||
void setGains(const double &p, const double &i, const double &d, const double &i_max, const double &i_min, const bool &antiwindup = false); | ||
|
||
/** | ||
* \brief Get the name of the joint this controller uses | ||
*/ | ||
std::string getJointName(); | ||
|
||
/** | ||
* \brief Get the current position of the joint | ||
* \return current position | ||
*/ | ||
double getPosition(); | ||
|
||
hardware_interface::JointHandle joint_; | ||
urdf::JointConstSharedPtr joint_urdf_; | ||
realtime_tools::RealtimeBuffer<Commands> command_; | ||
Commands command_struct_; // pre-allocated memory that is re-used to set the realtime buffer | ||
|
||
private: | ||
int loop_count_; | ||
control_toolbox::Pid pid_controller_; /**< Internal PID controller. */ | ||
|
||
boost::scoped_ptr< | ||
realtime_tools::RealtimePublisher< | ||
control_msgs::JointControllerState> > controller_state_publisher_ ; | ||
|
||
ros::Subscriber sub_command_; | ||
|
||
/** | ||
* \brief Callback from /command subscriber for setpoint | ||
*/ | ||
void setCommandCB(const std_msgs::Float64ConstPtr& msg); | ||
|
||
/** | ||
* \brief Check that the command is within the hard limits of the joint. Checks for joint | ||
* type first. Sets command to limit if out of bounds. | ||
* \param command - the input to test | ||
*/ | ||
void enforceJointLimits(double &command); | ||
|
||
}; | ||
|
||
} // namespace | ||
|
||
#endif |
Oops, something went wrong.