AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
ROS2ControlInterface.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16#pragma once
17#include <agxROS2/export.h>
18#include <agxROS2/Publisher.h>
19#include <agxROS2/Subscriber.h>
20#include <agxROS2/Qos.h>
21
22#include <agx/Constraint.h>
24#include <agxSDK/Assembly.h>
25#include <agxSDK/Simulation.h>
27
28#include <map>
29#include <string>
30#include <tuple>
31
32namespace agxROS2
33{
42 {
51 public:
53 POSITION = 0,
54 VELOCITY = 1,
55 EFFORT = 2
56 };
57
66 const std::string& jointCommandTopic,
67 const std::string& jointStateTopic,
68 bool syncWithSystemTime = false
69 );
70
78
84 bool removeJoint(const std::string& name);
85
92
96 virtual void pre(const agx::TimeStamp& time) override;
97
101 virtual void post(const agx::TimeStamp& time) override;
102
103 private:
109 void populateJointStateMessage(const agx::TimeStamp& time);
114 void setCommandOnJoints(agxROS2::sensorMsgs::JointState& jointStateMsg);
120 void setHeader(agxROS2::sensorMsgs::JointState& jointStateMsg, const agx::TimeStamp& time);
121
122 struct Joint {
123 agx::Constraint1DOFRef constraint;
124 agx::RangeReal effortLimit;
125 ROS2ControlCommandInterface commandInterface;
126 };
127
128 private:
131
134
135 std::map<std::string, Joint> m_joints;
136
137 // ros2_control syncs its control loop against the system clock.
138 // even if we publish the simulation time to /clock the ros2_control control
139 // loop will sleep with std::this_thread::sleep_until(next_iteration_time);
140 // where next_iteration_time is 0 and the system clock is larger so it will not sleep at all.
141 // Thus making the controller loop running as fast as possible ~4k hz always depending on hardware.
142 // Currently an issue in ros2_control repo https://github.com/ros-controls/ros2_control/issues/859
143 //
144 // A workaround is to set the simulation time to the system time. This assumes that the simulation
145 // runs in realtime. Not faster or slower. This will not make the control-loop and simulation synchronous,
146 // it only makes the controller update rate to be the specified rate. If the simulation runs faster than
147 // realtime then control signals will be missing when stepping. If it runs slower then the simulation
148 // will miss intermediate control signals.
149 bool m_syncWithSystemTime;
150 };
151}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXROS2_EXPORT
Possible to add joints (Constraint1DOF) and the listener will publish the position and velocity for t...
ROS2ControlInterface(const std::string &jointCommandTopic, const std::string &jointStateTopic, bool syncWithSystemTime=false)
Constructor creates the ROS2ControlInterface and initializes the ROS2 subscriber and publisher that w...
bool removeJoint(const std::string &name)
Remove a joint that is controlled by this listener.
bool removeJoint(agx::Constraint1DOF *joint)
Remove a joint that is controlled by this listener.
virtual void pre(const agx::TimeStamp &time) override
Checks if there is an available command message, receives it and sets the commands on the joints.
virtual void post(const agx::TimeStamp &time) override
Publishes the joint states.
bool addJoint(agx::Constraint1DOF *joint, ROS2ControlCommandInterface commandInterface)
Add a joint to be controlled by this listener and publish its state on the jointStateTopic.
ROS2ControlCommandInterface
The ROS2ControlCommandInterface sets how the joints should be controlled.
Derive from this class to implement a listener for simulation step events.
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic.
Definition Constraint.h:674
agx::Real TimeStamp
Definition TimeStamp.h:26