-
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.
Merge branch 'master' into feature/add_eps_for_TSR
- Loading branch information
Showing
9 changed files
with
351 additions
and
8 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,33 @@ | ||
# Find pr_control_msgs | ||
# | ||
# This sets the following variables: | ||
# pr_control_msgs_FOUND | ||
# pr_control_msgs_INCLUDE_DIRS | ||
# pr_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_pr_control_msgs pr_control_msgs QUIET) | ||
|
||
# Include directories | ||
find_path(pr_control_msgs_INCLUDE_DIRS | ||
NAMES pr_control_msgs/TriggerResult.h | ||
HINTS ${PC_pr_control_msgs_LIBRARY_DIRS} | ||
) | ||
|
||
# Version | ||
set(pr_control_msgs_VERSION ${PC_pr_control_msgs_VERSION}) | ||
|
||
# Set (NAME)_FOUND if all the variables and the version are satisfied. | ||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(pr_control_msgs | ||
FOUND_VAR pr_control_msgs_FOUND | ||
FAIL_MESSAGE DEFAULT_MSG | ||
REQUIRED_VARS pr_control_msgs_INCLUDE_DIRS | ||
VERSION_VAR pr_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#ifndef AIKIDO_CONTROL_ROS_ROSPOSITIONCOMMANDEXECUTOR_HPP_ | ||
#define AIKIDO_CONTROL_ROS_ROSPOSITIONCOMMANDEXECUTOR_HPP_ | ||
#include <chrono> | ||
#include <future> | ||
#include <mutex> | ||
#include <ros/ros.h> | ||
#include <ros/callback_queue.h> | ||
#include <sensor_msgs/JointState.h> | ||
#include <pr_control_msgs/SetPositionAction.h> | ||
#include <actionlib/client/action_client.h> | ||
#include <aikido/control/PositionCommandExecutor.hpp> | ||
#include <Eigen/Dense> | ||
|
||
namespace aikido{ | ||
namespace control { | ||
namespace ros { | ||
|
||
/// This class uses actionlib to command an action of the type | ||
/// pr_control_msgs/SetPosition. It specifies a set of target | ||
/// positions and sends it to the ROS server for execution | ||
class RosPositionCommandExecutor : public aikido::control::PositionCommandExecutor | ||
{ | ||
public: | ||
/// Constructor | ||
/// \param[in] node ROS node handle for action client. | ||
/// \param[in] serverName Name of the server to send trajectory to. | ||
/// \param[in] The names of the joints to set position targets for | ||
/// \param[in] connectionTimeout Timeout for server connection. | ||
/// \param[in] connectionPollingPeriod Polling period for server connection. | ||
RosPositionCommandExecutor( | ||
::ros::NodeHandle node, | ||
const std::string& serverName, | ||
std::vector<std::string> jointNames, | ||
std::chrono::milliseconds connectionTimeout = std::chrono::milliseconds{1000}, | ||
std::chrono::milliseconds connectionPollingPeriod = std::chrono::milliseconds{20} | ||
); | ||
|
||
virtual ~RosPositionCommandExecutor(); | ||
|
||
/// Sends positions to ROS server for execution. | ||
/// \param[in] goalPositions Vector of target positions for each joint | ||
std::future<void> execute(const Eigen::VectorXd& goalPositions) override; | ||
|
||
|
||
void step() override; | ||
|
||
private: | ||
using RosPositionActionClient | ||
= actionlib::ActionClient<pr_control_msgs::SetPositionAction>; | ||
using GoalHandle = RosPositionActionClient::GoalHandle; | ||
|
||
bool waitForServer(); | ||
|
||
void transitionCallback(GoalHandle handle); | ||
|
||
::ros::NodeHandle mNode; | ||
::ros::CallbackQueue mCallbackQueue; | ||
RosPositionActionClient mClient; | ||
RosPositionActionClient::GoalHandle mGoalHandle; | ||
|
||
std::chrono::milliseconds mConnectionTimeout; | ||
std::chrono::milliseconds mConnectionPollingPeriod; | ||
|
||
bool mInProgress; | ||
std::promise<void> mPromise; | ||
Eigen::VectorXd mGoalPositions; | ||
std::vector<std::string> mJointNames; | ||
|
||
std::mutex mMutex; | ||
}; | ||
|
||
} // namespace ros | ||
} // namespace control | ||
} // namespace aikido | ||
|
||
#endif // ifndef AIKIDO_CONTROL_ROS_ROSPOSITIONCOMMANDEXECUTOR_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,42 @@ | ||
#include <chrono> | ||
#include <mutex> | ||
#include <ros/ros.h> | ||
#include <ros/callback_queue.h> | ||
#include <actionlib/client/action_client.h> | ||
|
||
namespace aikido { | ||
namespace control { | ||
namespace ros { | ||
|
||
template <class ActionSpec, class TimeoutDuration, class PeriodDuration> | ||
bool waitForActionServer( | ||
actionlib::ActionClient<ActionSpec>& actionClient, | ||
::ros::CallbackQueue& callbackQueue, | ||
TimeoutDuration timeoutDuration = std::chrono::milliseconds{ 1000 }, | ||
PeriodDuration periodDuration = std::chrono::milliseconds{ 10 } | ||
) | ||
{ | ||
using Clock = std::chrono::steady_clock; | ||
|
||
const auto startTime = Clock::now(); | ||
const auto endTime = startTime + timeoutDuration; | ||
auto currentTime = startTime; | ||
|
||
while(currentTime < endTime) | ||
{ | ||
callbackQueue.callAvailable(); | ||
|
||
// TODO : Is this thread safe? | ||
if (actionClient.isServerConnected()) | ||
return true; | ||
|
||
currentTime += periodDuration; | ||
std::this_thread::sleep_until(currentTime); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} // namespace ros | ||
} // namespace control | ||
} // namespace aikido |
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,26 @@ | ||
#ifndef AIKIDO_CONTROL_ROS_UTIL_HPP_ | ||
#define AIKIDO_CONTROL_ROS_UTIL_HPP_ | ||
#include <chrono> | ||
#include <ros/ros.h> | ||
#include <ros/callback_queue.h> | ||
#include <actionlib/client/action_client.h> | ||
|
||
namespace aikido { | ||
namespace control { | ||
namespace ros { | ||
|
||
template <class ActionSpec, class TimeoutDuration, class PeriodDuration> | ||
bool waitForActionServer( | ||
actionlib::ActionClient<ActionSpec>& actionClient, | ||
::ros::CallbackQueue& callbackQueue, | ||
TimeoutDuration timeoutDuration = std::chrono::milliseconds{ 1000 }, | ||
PeriodDuration periodDuration = std::chrono::milliseconds{ 10 } ); | ||
|
||
|
||
} // namespace ros | ||
} // namespace control | ||
} // namespace aikido | ||
|
||
#include "detail/util-impl.hpp" | ||
|
||
#endif // AIKIDO_CONTROL_ROS_UTIL_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.