Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ros_control/RosTrajectoryExecutor #149

Merged
merged 31 commits into from
Apr 14, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
43ea8bf
ros/Conversions
gilwoolee Apr 2, 2017
e3f783b
Cleaning up CMakeLists.
gilwoolee Apr 2, 2017
4391bf9
CMakeLists cleanup
gilwoolee Apr 2, 2017
338f1b7
Style change to match AIKIDO style guide.
gilwoolee Apr 2, 2017
aafa1cf
Checking joint-name matches
gilwoolee Apr 2, 2017
b013bfd
Initial commit for RosTrajectoryExecutor
gilwoolee Apr 3, 2017
793a23a
Temporarily removing tests in CMakeLists.
gilwoolee Apr 3, 2017
a2e0ed8
Merge branch 'master' into convertJointTrajectory
gilwoolee Apr 4, 2017
22ba7b4
Addressing some of Mike's comments
gilwoolee Apr 5, 2017
9e09781
Addressing Miks and JS's comments.
gilwoolee Apr 7, 2017
6714011
Merge branch 'master' into convertJointTrajectory
gilwoolee Apr 7, 2017
785871b
Minor bug fix, adding one test for joint mapping.
gilwoolee Apr 7, 2017
c98e8ea
Merge branch 'master' into convertJointTrajectory
gilwoolee Apr 7, 2017
5a655e5
Adding conversion from trajectory to ros trajectory.
gilwoolee Apr 9, 2017
d4bdaa3
Addressing Mike's comments.
gilwoolee Apr 9, 2017
300e050
Merge master and latest Conversions.cpp
gilwoolee Apr 9, 2017
d0d29dc
Line wrapping
gilwoolee Apr 9, 2017
f750b32
Removing a line.
gilwoolee Apr 9, 2017
3a10630
Merge branch 'master' into convertJointTrajectory
jslee02 Apr 11, 2017
9b9ba1e
Merge branch 'master' into RosTrajectoryExecutor
jslee02 Apr 11, 2017
064aa8a
Addressing Mike's comments
gilwoolee Apr 11, 2017
8f1a94b
Merge branch 'convertJointTrajectory' of https://github.com/personalr…
gilwoolee Apr 11, 2017
fc70347
Changing method names
gilwoolee Apr 12, 2017
4fd63b7
Merge branch 'convertJointTrajectory' of https://github.com/personalr…
gilwoolee Apr 12, 2017
65292c0
Addressing Mike and JS's comments.
gilwoolee Apr 12, 2017
6ad1d9c
Changing constructor to templated, removing reorderMap.
gilwoolee Apr 13, 2017
5db6d4e
Suppress warning
jslee02 Apr 13, 2017
6b71cb1
Merge remote-tracking branch 'origin/master' into RosTrajectoryExecutor
jslee02 Apr 13, 2017
98e8440
Fix Conversions
jslee02 Apr 13, 2017
5f0f1ae
Add missing dependencies to package.xml
jslee02 Apr 14, 2017
2537bfd
Suppress warnings
jslee02 Apr 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions include/aikido/control/ros/RosTrajectoryExecutor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#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 <dart/dart.hpp>
#include <aikido/control/TrajectoryExecutor.hpp>
#include <aikido/trajectory/Trajectory.hpp>

// actionlib and DART both #define this macro.
#undef DEPRECATED
#include <actionlib/client/action_client.h>
#undef DEPRECATED
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jslee02 Is this still necessary? I believe DART switched to the DART_DEPRECATED macro to avoid a conflict just like this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary. DART switched to the DART_DEPRECATED since version 6.0.1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gilwoolee Can you switch from DEPRECATED to DART_GENERATED and remove this #undef.


namespace aikido {
namespace control {
namespace ros {

class RosTrajectoryExecutor : public aikido::control::TrajectoryExecutor
{
public:
RosTrajectoryExecutor(
::dart::dynamics::MetaSkeletonPtr skeleton,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to tie each RosTrajectoryExecutor instance to a specific skeleton?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point! It seems like we could replace mSkeleton with a list of DOFs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably comes from my lack of knowledge in ROS. My question was, can't a RosTrajectoryExecutor be very flexible and take trajectories covering different set of dofs? Will serverName refer to something specific like arm-controller-server, etc.?

::ros::NodeHandle node,
const std::string& serverName,
double timestep,
double goalTimeTolerance,
std::chrono::milliseconds connectionTimeout
= std::chrono::milliseconds{1000},
std::chrono::milliseconds connectionPollingRate
= std::chrono::milliseconds{20}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Rename this to connectionPollingPeriod.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to suggest templatizing this constructor for the each time-related types so that we could pass any of time units. Here is a similar example. In this case, however, we would like to templatize for two possibly different duration types like:

template <typename DurationA, typename DurationB>
RosTrajectoryExecutor(...,
  const DurationA& connectionTimeout = std::chrono::milliseconds{1000},
  const DurationB& connectionPollingPeriod = std::chrono::milliseconds{20});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am generally supportive of this, but I am not sure how to implement it. We store these durations in member variables, so this would require templateing the entire class on DurationA and DurationB. It's possible we could do some type erasure shenaniganz to avoid this, but I don't think it's worth the effort at this point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually don't need to templatize the whole class but only this constructor. The member variable can be any specific duration type. Here is an example what I did: member variable, templated constructor.

);

virtual ~RosTrajectoryExecutor();

std::future<void> execute(trajectory::TrajectoryPtr _traj) override;

std::future<void> execute(
trajectory::TrajectoryPtr _traj, const ::ros::Time& _startTime);

/// Simulates mTraj. To be executed on a separate thread.
void spin();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should refactor this function into a spinOnce-style callback that we can call from the Executor implemented in #151. That is potentially important because it lets us consolidate all of our various callbacks, e.g. multiple RosTrajectoryExecutors and JointStateSubscribers, into a single thread.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind! It turns out that spin() is already implemented that way. 😅

Maybe we should rename this to something more obvious? Maybe step() or tick()?


private:
using TrajectoryActionClient
= actionlib::ActionClient<control_msgs::FollowJointTrajectoryAction>;
using GoalHandle = TrajectoryActionClient::GoalHandle;

bool waitForServer();

void transitionCallback(GoalHandle _handle);

::ros::NodeHandle mNode;
::ros::CallbackQueue mCallbackQueue;
TrajectoryActionClient mClient;
TrajectoryActionClient::GoalHandle mGoalHandle;

::dart::dynamics::MetaSkeletonPtr mSkeleton;
double mTimestep;
double mGoalTimeTolerance;

std::chrono::milliseconds mConnectionTimeout;
std::chrono::milliseconds mConnectionPollingRate;

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_
2 changes: 2 additions & 0 deletions src/control/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ add_component_targets(${PROJECT_NAME} control "${PROJECT_NAME}_control")
add_component_dependencies(${PROJECT_NAME} control statespace trajectory)

coveralls_add_sources(${sources})

add_subdirectory("ros") # Dependencies: control, statespace, trajectory
41 changes: 41 additions & 0 deletions src/control/ros/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#==============================================================================
# Dependencies
#
find_package(actionlib QUIET)
aikido_check_package(actionlib "aikido::control::ros" "actionlib")

find_package(control_msgs QUIET)
aikido_check_package(control_msgs "aikido::control::ros" "control_msgs")

find_package(roscpp QUIET)
aikido_check_package(roscpp "aikido::control::ros" "roscpp")

#==============================================================================
# Libraries
#
set(sources
RosTrajectoryExecutor.cpp
)

add_library("${PROJECT_NAME}_control_ros" SHARED ${sources})
target_include_directories("${PROJECT_NAME}_control_ros" SYSTEM
PUBLIC
${actionlib_INCLUDE_DIRS}
${control_msgs_INCLUDE_DIRS}
${roscpp_INCLUDE_DIRS}
)
target_link_libraries("${PROJECT_NAME}_control_ros"
"${PROJECT_NAME}_control"
"${PROJECT_NAME}_statespace"
"${PROJECT_NAME}_trajectory"
${DART_LIBRARIES}
${actionlib_LIBRARIES}
${control_msgs_LIBRARIES}
${roscpp_LIBRARIES}
)

add_component(${PROJECT_NAME} control_ros)
add_component_targets(${PROJECT_NAME} control_ros "${PROJECT_NAME}_control_ros")
add_component_dependencies(${PROJECT_NAME} control_ros control statespace trajectory)

# coveralls_add_sources(${sources})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there is a strong reason not to, we should uncomment this.

Loading