PlatformSubUnit.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package RobotAPI::ArmarXObjects::PlatformSubUnit
17 * @author Raphael ( raphael dot grimm at kit dot edu )
18 * @date 2017
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22#include "PlatformSubUnit.h"
23
24#include <Eigen/Core>
25#include <Eigen/Geometry>
26
27#include <SimoxUtility/math/convert/mat4f_to_rpy.h>
28#include <VirtualRobot/MathTools.h>
29
31#include <RobotAPI/interface/core/GeometryBase.h>
32#include <RobotAPI/interface/core/PoseBase.h>
34
35namespace armarx
36{
37
38 void
41 {
42 if (!getProxy())
43 {
44 //this unit is not initialized yet
45 ARMARX_IMPORTANT << deactivateSpam(1) << "not initialized yet - skipping this update";
46 return;
47 }
48 if (!listenerPrx)
49 {
50 ARMARX_INFO << deactivateSpam(1) << "listener is not set - skipping this update";
51 return;
52 }
53 const SensorValueBase* sensorValue = sc.sensors.at(platformSensorIndex).get();
54 ARMARX_CHECK_EXPRESSION(sensorValue);
55 std::lock_guard<std::mutex> guard{dataMutex};
56
57 const auto timestamp = sc.sensorValuesTimestamp.toMicroSeconds();
58 ;
59
60 // odom velocity is in local robot frame
61 FrameHeader odomVelocityHeader;
62 odomVelocityHeader.parentFrame = robotRootFrame;
63 odomVelocityHeader.frame = robotRootFrame;
64 odomVelocityHeader.agent = agentName;
65 odomVelocityHeader.timestampInMicroSeconds = timestamp;
66
67 // odom pose is in odom frame
68 FrameHeader odomPoseHeader;
69 odomPoseHeader.parentFrame = OdometryFrame;
70 odomPoseHeader.frame = robotRootFrame;
71 odomPoseHeader.agent = agentName;
72 odomPoseHeader.timestampInMicroSeconds = timestamp;
73
74 // odom velocity is in local robot frame
75 FrameHeader globalPoseHeader;
76 globalPoseHeader.parentFrame = GlobalFrame;
77 globalPoseHeader.frame = robotRootFrame;
78 globalPoseHeader.agent = agentName;
79 globalPoseHeader.timestampInMicroSeconds = timestamp;
80
81
82 //pos
83 {
88
89 const auto odom_T_robot = VirtualRobot::MathTools::posrpy2eigen4f(
90 s->relativePositionX, s->relativePositionY, 0, 0, 0, s->relativePositionRotation);
91
92 // @@@ CHECK BELOW:
93 // if (s->isA<SensorValueHolonomicPlatformAbsolutePosition>())
94 // {
95 // const SensorValueHolonomicPlatformAbsolutePosition* sabs = s->asA<SensorValueHolonomicPlatformAbsolutePosition>();
96 // abs = positionCorrection * VirtualRobot::MathTools::posrpy2eigen4f(sabs->absolutePositionX, sabs->absolutePositionY, 0, 0, 0, sabs->absolutePositionRotation);
97
98 // TransformStamped currentPose;
99 // currentPose.header = globalPoseHeader;
100 // currentPose.transform = abs;
101
102 // globalPosePrx->reportGlobalRobotPose(currentPose);
103
104 // // legacy interfaces
105 // PlatformPose platformPose = toPlatformPose(currentPose);
106 // listenerPrx->reportPlatformPose(platformPose);
107 // globalPosCtrl->setGlobalPos(platformPose);
108 // }
109 // else
110 // {
111 // global_T_robot = global_T_odom * odom_T_robot;
112 // }
113
114 // const auto global_T_robot = global_T_odom * odom_T_robot;
115
116
117 const TransformStamped odomPose{.header = odomPoseHeader, .transform = odom_T_robot};
118 odometryPrx->reportOdometryPose(odomPose);
119
120 // legacy interface
121 const auto odomLegacyPose = toPlatformPose(odomPose);
122 listenerPrx->reportPlatformOdometryPose(
123 odomLegacyPose.x, odomLegacyPose.y, odomLegacyPose.rotationAroundZ);
124 }
125
126 //vel
127 {
131
132 TwistStamped odomVelocity;
133 odomVelocity.header = odomVelocityHeader;
134 odomVelocity.twist.linear << s->velocityX, s->velocityY, 0;
135 odomVelocity.twist.angular << 0, 0, s->velocityRotation;
136
137 odometryPrx->reportOdometryVelocity(odomVelocity);
138
139 // legacy interface
140 const auto& vel = odomVelocity.twist;
141 listenerPrx->reportPlatformVelocity(vel.linear.x(), vel.linear.y(), vel.angular.z());
142 }
143 }
144
145 void
146 armarx::PlatformSubUnit::move(Ice::Float vx, Ice::Float vy, Ice::Float vr, const Ice::Current&)
147 {
148 //holding the mutex here could deadlock
149 if (!pt->isControllerActive())
150 {
151 pt->activateController();
152 }
153 std::lock_guard<std::mutex> guard{dataMutex};
154 pt->setVelocites(std::clamp(vx, -maxVLin, maxVLin),
155 std::clamp(vy, -maxVLin, maxVLin),
156 std::clamp(vr, -maxVAng, maxVAng));
157 }
158
159 void
161 Ice::Float ry,
162 Ice::Float rr,
163 Ice::Float lac,
164 Ice::Float rac,
165 const Ice::Current&)
166 {
167 globalPosCtrl->setTarget(rx, ry, rr, lac, rac);
168 if (!globalPosCtrl->isControllerActive())
169 {
170 globalPosCtrl->activateController();
171 };
172 }
173
174 void
176 Ice::Float ry,
177 Ice::Float rr,
178 Ice::Float lac,
179 Ice::Float rac,
180 const Ice::Current&)
181 {
182 relativePosCtrl->setTarget(rx, ry, rr, lac, rac);
183 if (!relativePosCtrl->isControllerActive())
184 {
185 relativePosCtrl->activateController();
186 }
187 //holding the mutex here could deadlock
188 // std::lock_guard<std::mutex> guard {dataMutex};
189 ARMARX_INFO << "target orientation: " << rr;
190 }
191
192 void
194 Ice::Float mxVAng,
195 const Ice::Current&)
196 {
197 std::lock_guard<std::mutex> guard{dataMutex};
198 maxVLin = std::abs(mxVLin);
199 maxVAng = std::abs(mxVAng);
200 }
201
202 // void armarx::PlatformSubUnit::setGlobalPose(armarx::PoseBasePtr globalPose, const Ice::Current&)
203 // {
204 // std::lock_guard<std::mutex> guard {dataMutex};
205 // PosePtr p = PosePtr::dynamicCast(globalPose);
206 // global_T_odom = p->toEigen() * global_T_robot.inverse();
207 // }
208
209 // armarx::PoseBasePtr armarx::PlatformSubUnit::getGlobalPose(const Ice::Current&)
210 // {
211 // std::lock_guard<std::mutex> guard {dataMutex};
212 // return new Pose {global_T_robot};
213 // }
214
215 void
217 {
218 move(0, 0, 0);
219 }
220
221
222} // namespace armarx
std::string timestamp()
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
constexpr T c
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
void update(const SensorAndControl &sc, const JointAndNJointControllers &c) override
NJointHolonomicPlatformGlobalPositionControllerPtr globalPosCtrl
NJointHolonomicPlatformRelativePositionControllerPtr relativePosCtrl
void moveRelative(Ice::Float rx, Ice::Float ry, Ice::Float rr, Ice::Float lac, Ice::Float rac, const Ice::Current &=Ice::emptyCurrent) override
NJointHolonomicPlatformVelocityControllerInterfacePtr pt
void setMaxVelocities(Ice::Float mxVLin, Ice::Float mxVAng, const Ice::Current &=Ice::emptyCurrent) override
void move(Ice::Float vx, Ice::Float vy, Ice::Float vr, const Ice::Current &=Ice::emptyCurrent) override
void stopPlatform(const Ice::Current &c=Ice::emptyCurrent) override
void moveTo(Ice::Float rx, Ice::Float ry, Ice::Float rr, Ice::Float lac, Ice::Float rac, const Ice::Current &=Ice::emptyCurrent) override
PlatformUnitListenerPrx listenerPrx
PlatformUnitListener proxy for publishing state updates.
OdometryListenerPrx odometryPrx
The SensorValueBase class.
const T * asA() const
The robot's position relative to its initial pose when starting the robot unit based on odometry info...
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
std::string const GlobalFrame
Variable of the global coordinate system.
Definition FramedPose.h:65
This file offers overloads of toIce() and fromIce() functions for STL container types.
PlatformPose toPlatformPose(const TransformStamped &transformStamped)
std::string const OdometryFrame
Definition FramedPose.h:66
detail::ControlThreadOutputBufferEntry SensorAndControl
Structure used by the RobotUnit to swap lists of Joint and NJoint controllers.
std::vector< PropagateConst< SensorValueBase * > > sensors