-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ros_control/RosTrajectoryExecutor (#149)
* ros/Conversions * Cleaning up CMakeLists. * CMakeLists cleanup * Style change to match AIKIDO style guide. * Checking joint-name matches * Initial commit for RosTrajectoryExecutor * Temporarily removing tests in CMakeLists. * Addressing some of Mike's comments * Addressing Miks and JS's comments. * Minor bug fix, adding one test for joint mapping. * Adding conversion from trajectory to ros trajectory. * Addressing Mike's comments. * Line wrapping * Removing a line. * Addressing Mike's comments * Changing method names * Addressing Mike and JS's comments. * Changing constructor to templated, removing reorderMap. * Suppress warning * Fix Conversions * Add missing dependencies to package.xml and use find modules to find actionlib and control_msgs * Suppress warnings
- Loading branch information
Showing
15 changed files
with
846 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Find actionlib | ||
# | ||
# This sets the following variables: | ||
# actionlib_FOUND | ||
# actionlib_INCLUDE_DIRS | ||
# actionlib_LIBRARIES | ||
# actionlib_VERSION | ||
|
||
# Note: This find module is necessary because the config file imports "gtest", | ||
# "tests", and "run_tests" that conflict with the targets defined by Aikido. | ||
|
||
find_package(PkgConfig QUIET REQUIRED) | ||
|
||
# Check to see if pkgconfig is installed. | ||
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE) | ||
pkg_check_modules(PC_actionlib actionlib QUIET REQUIRED) | ||
|
||
# Include directories | ||
find_path(actionlib_INCLUDE_DIRS | ||
NAMES actionlib/action_definition.h | ||
HINTS ${PC_actionlib_LIBRARY_DIRS} | ||
) | ||
|
||
# Libraries | ||
find_library(actionlib_LIBRARIES | ||
actionlib | ||
HINTS ${PC_actionlib_LIBRARY_DIRS} | ||
) | ||
|
||
# Version | ||
set(actionlib_VERSION ${PC_actionlib_VERSION}) | ||
|
||
# Set (NAME)_FOUND if all the variables and the version are satisfied. | ||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(actionlib | ||
FOUND_VAR actionlib_FOUND | ||
FAIL_MESSAGE DEFAULT_MSG | ||
REQUIRED_VARS actionlib_INCLUDE_DIRS actionlib_LIBRARIES | ||
VERSION_VAR actionlib_VERSION | ||
) |
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,33 @@ | ||
# Find control_msgs | ||
# | ||
# This sets the following variables: | ||
# control_msgs_FOUND | ||
# control_msgs_INCLUDE_DIRS | ||
# control_msgs_VERSION | ||
|
||
# Note: This find module is necessary because the config file imports "gtest", | ||
# "tests", and "run_tests" that conflict with the targets defined by Aikido. | ||
|
||
find_package(PkgConfig QUIET REQUIRED) | ||
|
||
# Check to see if pkgconfig is installed. | ||
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE) | ||
pkg_check_modules(PC_control_msgs control_msgs QUIET REQUIRED) | ||
|
||
# Include directories | ||
find_path(control_msgs_INCLUDE_DIRS | ||
NAMES control_msgs/JointTolerance.h | ||
HINTS ${PC_control_msgs_LIBRARY_DIRS} | ||
) | ||
|
||
# Version | ||
set(control_msgs_VERSION ${PC_control_msgs_VERSION}) | ||
|
||
# Set (NAME)_FOUND if all the variables and the version are satisfied. | ||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(control_msgs | ||
FOUND_VAR control_msgs_FOUND | ||
FAIL_MESSAGE DEFAULT_MSG | ||
REQUIRED_VARS control_msgs_INCLUDE_DIRS | ||
VERSION_VAR control_msgs_VERSION | ||
) |
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
33 changes: 33 additions & 0 deletions
33
include/aikido/control/ros/RosTrajectoryExecutionException.hpp
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,33 @@ | ||
#ifndef AIKIDO_CONTROL_ROS_ROSTRAJECTORYEXECUTIONEXCEPTION_HPP_ | ||
#define AIKIDO_CONTROL_ROS_ROSTRAJECTORYEXECUTIONEXCEPTION_HPP_ | ||
#include <exception> | ||
#include <actionlib/client/action_client.h> | ||
#include <control_msgs/FollowJointTrajectoryAction.h> | ||
|
||
namespace aikido { | ||
namespace control { | ||
namespace ros { | ||
|
||
/// This class wraps various exceptions that may arise during trajectory | ||
/// execution over ROS. | ||
class RosTrajectoryExecutionException: public std::runtime_error | ||
{ | ||
public: | ||
|
||
RosTrajectoryExecutionException( | ||
const std::string& what, | ||
actionlib::TerminalState terminalState); | ||
|
||
RosTrajectoryExecutionException( | ||
const std::string& what, | ||
int result); | ||
|
||
virtual ~RosTrajectoryExecutionException() = default; | ||
|
||
}; | ||
|
||
} // ros | ||
} // control | ||
} // aikido | ||
|
||
#endif |
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,90 @@ | ||
#ifndef AIKIDO_CONTROL_ROS_ROSTRAJECTORYEXECUTOR_HPP_ | ||
#define AIKIDO_CONTROL_ROS_ROSTRAJECTORYEXECUTOR_HPP_ | ||
#include <chrono> | ||
#include <future> | ||
#include <mutex> | ||
#include <ros/ros.h> | ||
#include <ros/callback_queue.h> | ||
#include <control_msgs/FollowJointTrajectoryAction.h> | ||
#include <aikido/control/TrajectoryExecutor.hpp> | ||
#include <aikido/statespace/dart/MetaSkeletonStateSpace.hpp> | ||
#include <aikido/trajectory/Trajectory.hpp> | ||
#include <actionlib/client/action_client.h> | ||
|
||
namespace aikido { | ||
namespace control { | ||
namespace ros { | ||
|
||
/// This class sends trajectory commands to ROS server. | ||
class RosTrajectoryExecutor : public aikido::control::TrajectoryExecutor | ||
{ | ||
public: | ||
/// Constructor. | ||
/// \param[in] space Space in which trajectries operate. | ||
/// \param[in] node ROS node handle for action client. | ||
/// \param[in] serverName Name of the server to send traejctory to. | ||
/// \param[in] timestep Step size for interpolating trajectories. | ||
/// \param[in] goalTimeTolerance | ||
/// \param[in] connectionTimeout Timeout for server connection. | ||
/// \param[in] connectionPollingPeriod Polling period for server connection. | ||
template <typename DurationA, typename DurationB> | ||
RosTrajectoryExecutor( | ||
statespace::dart::MetaSkeletonStateSpacePtr space, | ||
::ros::NodeHandle node, | ||
const std::string& serverName, | ||
double timestep, | ||
double goalTimeTolerance, | ||
const DurationA& connectionTimeout = std::chrono::milliseconds{1000}, | ||
const DurationB& connectionPollingPeriod = std::chrono::milliseconds{20} | ||
); | ||
|
||
virtual ~RosTrajectoryExecutor(); | ||
|
||
/// Sends trajectory to ROS server for execution. | ||
/// \param[in] traj Trajecotry to be executed. | ||
std::future<void> execute(trajectory::TrajectoryPtr traj) override; | ||
|
||
/// Sends trajectory to ROS server for execution. | ||
/// \param[in] traj Trajectrory to be executed. | ||
/// \param[in] startTime Start time for the trajectory. | ||
std::future<void> execute( | ||
trajectory::TrajectoryPtr traj, const ::ros::Time& startTime); | ||
|
||
/// To be executed on a separate thread. | ||
/// Regularly checks for the completion of a sent trajectory. | ||
void spin(); | ||
|
||
private: | ||
using TrajectoryActionClient | ||
= actionlib::ActionClient<control_msgs::FollowJointTrajectoryAction>; | ||
using GoalHandle = TrajectoryActionClient::GoalHandle; | ||
|
||
bool waitForServer(); | ||
|
||
void transitionCallback(GoalHandle handle); | ||
|
||
statespace::dart::MetaSkeletonStateSpacePtr mSpace; | ||
::ros::NodeHandle mNode; | ||
::ros::CallbackQueue mCallbackQueue; | ||
TrajectoryActionClient mClient; | ||
TrajectoryActionClient::GoalHandle mGoalHandle; | ||
|
||
double mTimestep; | ||
double mGoalTimeTolerance; | ||
|
||
std::chrono::milliseconds mConnectionTimeout; | ||
std::chrono::milliseconds mConnectionPollingPeriod; | ||
|
||
bool mInProgress; | ||
std::promise<void> mPromise; | ||
trajectory::TrajectoryPtr mTrajectory; | ||
|
||
std::mutex mMutex; | ||
}; | ||
|
||
} // namespace ros | ||
} // namespace control | ||
} // namespace aikido | ||
|
||
#endif // ifndef AIKIDO_CONTROL_ROS_ROSTRAJECTORYEXECUTOR_HPP_ | ||
|
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
Oops, something went wrong.