Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
730 additions
and
20 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
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
Oops, something went wrong.