29 #include <RobotAPI/interface/core/GeometryBase.h>
32 #include <Eigen/Geometry>
36 #include <RobotAPI/interface/units/PlatformUnitInterface.h>
39 #include <VirtualRobot/MathTools.h>
47 def->defineOptionalProperty<
int>(
"IntervalMs", 10,
"The time in milliseconds between two calls to the simulation method.");
48 def->defineOptionalProperty<
float>(
"InitialRotation", 0,
"Initial rotation of the platform.");
49 def->defineOptionalProperty<
float>(
"InitialPosition.x", 0,
"Initial x position of the platform.");
50 def->defineOptionalProperty<
float>(
"InitialPosition.y", 0,
"Initial y position of the platform.");
51 def->defineOptionalProperty<std::string>(
"ReferenceFrame",
"Platform",
"Reference frame in which the platform position is reported.");
52 def->defineOptionalProperty<
float>(
"LinearVelocity", 1000.0,
"Linear velocity of the platform (default: 1000 mm/sec).");
53 def->defineOptionalProperty<
float>(
"MaxLinearAcceleration", 1000.0,
"Linear acceleration of the platform (default: 1000 mm/sec).");
54 def->defineOptionalProperty<
float>(
"Kp_Position", 5.0,
"P value of the PID position controller");
55 def->defineOptionalProperty<
float>(
"Kp_Velocity", 5.0,
"P value of the PID velocity controller");
56 def->defineOptionalProperty<
float>(
"AngularVelocity", 1.5,
"Angular velocity of the platform (default: 1.5 rad/sec).");
58 def->component(robotStateComponent);
66 referenceFrame = getProperty<std::string>(
"ReferenceFrame").getValue();
75 velPID.reset(
new MultiDimPIDController(getProperty<float>(
"Kp_Velocity").getValue(), 0, 0, getProperty<float>(
"MaxLinearAcceleration").getValue()));
81 intervalMs = getProperty<int>(
"IntervalMs").getValue();
94 agentName = robotStateComponent->getRobotName();
95 robotRootFrame = robotStateComponent->getSynchronizedRobot()->getRootNode()->getName();
97 TransformStamped currentPose;
99 currentPose.header.frame = robotRootFrame;
100 currentPose.header.agent = agentName;
101 currentPose.header.timestampInMicroSeconds =
TimeUtil::GetTime().toMicroSeconds();
102 currentPose.transform = currentPlatformPose();
132 std::vector<float> vel(3, 0.0f);
139 posPID->update(timeDeltaInSeconds,
142 float newXTickMotion =
posPID->getControlValue()[0] * timeDeltaInSeconds;
145 vel[0] =
posPID->getControlValue()[0];
146 vel[1] =
posPID->getControlValue()[1];
175 targetVel = rot * targetVel;
205 FrameHeader odomVelocityHeader;
206 odomVelocityHeader.parentFrame = robotRootFrame;
207 odomVelocityHeader.frame = robotRootFrame;
208 odomVelocityHeader.agent = agentName;
209 odomVelocityHeader.timestampInMicroSeconds =
TimeUtil::GetTime().toMicroSeconds();;
212 FrameHeader odomPoseHeader;
214 odomPoseHeader.frame = robotRootFrame;
215 odomPoseHeader.agent = agentName;
231 TransformStamped currentPose;
233 currentPose.header.frame = robotRootFrame;
234 currentPose.header.agent = agentName;
235 currentPose.header.timestampInMicroSeconds =
TimeUtil::GetTime().toMicroSeconds();
236 currentPose.transform = currentPlatformPose();
244 listenerPrx->reportPlatformVelocity(velo.linear.x(), velo.linear.y(), velo.angular.z());
249 ARMARX_INFO <<
"new target pose : " << targetPlatformPositionX <<
", " << targetPlatformPositionY <<
" with angle " << targetPlatformRotation;
263 header.frame = robotRootFrame;
264 header.agent = agentName;
266 TransformStamped targetPose;
267 targetPose.header = header;
273 ARMARX_INFO <<
deactivateSpam(1) <<
"New velocity: " << targetPlatformVelocityX <<
", " << targetPlatformVelocityY <<
" with angular velocity: " << targetPlatformVelocityRotation;
274 std::unique_lock lock(currentPoseMutex);
275 platformMode = eVelocityControl;
276 linearVelocityX =
std::min(maxLinearVelocity, targetPlatformVelocityX);
277 linearVelocityY =
std::min(maxLinearVelocity, targetPlatformVelocityY);
278 angularVelocity =
std::min(maxAngularVelocity, targetPlatformVelocityRotation);
282 void PlatformUnitSimulation::moveRelative(
float targetPlatformOffsetX,
float targetPlatformOffsetY,
float targetPlatformOffsetRotation,
float positionalAccuracy,
float orientationalAccuracy,
const Ice::Current&
c)