Skip to content

Commit 5236faf

Browse files
committed
Introduce ROS<->M+ concept conversion functions
Only support MP_COORD -> geometry_msgs/{Pose,Transform} for now, but others can be added later.
1 parent 9492838 commit 5236faf

5 files changed

+79
-0
lines changed

src/MotoROS.h

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
//============================================
5151
#include <std_srvs/srv/trigger.h>
5252
#include <sensor_msgs/msg/joint_state.h>
53+
#include <geometry_msgs/msg/pose.h>
5354
#include <geometry_msgs/msg/transform_stamped.h>
5455
#include <geometry_msgs/msg/quaternion.h>
5556
#include <tf2_msgs/msg/tf_message.h>
@@ -103,6 +104,7 @@
103104
#include "MathConstants.h"
104105
#include "MotoROS_PlatformLib.h"
105106
#include "Ros_mpGetRobotCalibrationData.h"
107+
#include "RosMotoPlusConversionUtils.h"
106108

107109
extern void Ros_Sleep(float milliseconds);
108110

src/MotoROS2_AllControllers.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@
352352
<ClCompile Include="ServiceResetError.c" />
353353
<ClCompile Include="FauxCommandLineArgs.c" />
354354
<ClCompile Include="Ros_mpGetRobotCalibrationData.c" />
355+
<ClCompile Include="RosMotoPlusConversionUtils.c" />
355356
</ItemGroup>
356357
<ItemGroup>
357358
<ClInclude Include="ConfigFile.h" />
@@ -386,6 +387,7 @@
386387
<ClInclude Include="MathConstants.h" />
387388
<ClInclude Include="MotoROS_PlatformLib.h" />
388389
<ClInclude Include="Ros_mpGetRobotCalibrationData.h" />
390+
<ClInclude Include="RosMotoPlusConversionUtils.h" />
389391
</ItemGroup>
390392
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
391393
<ImportGroup Label="ExtensionTargets">

src/MotoROS2_AllControllers.vcxproj.filters

+6
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@
321321
<ClCompile Include="Ros_mpGetRobotCalibrationData.c">
322322
<Filter>Source Files\Robot Controller</Filter>
323323
</ClCompile>
324+
<ClCompile Include="RosMotoPlusConversionUtils.c">
325+
<Filter>Source Files\Utilities</Filter>
326+
</ClCompile>
324327
</ItemGroup>
325328
<ItemGroup>
326329
<ClInclude Include="MotoROS.h">
@@ -401,6 +404,9 @@
401404
<ClInclude Include="TimeConversionUtils.h">
402405
<Filter>Header Files\Utilities</Filter>
403406
</ClInclude>
407+
<ClInclude Include="RosMotoPlusConversionUtils.h">
408+
<Filter>Header Files\Utilities</Filter>
409+
</ClInclude>
404410
<ClInclude Include="MotoPlusExterns.h">
405411
<Filter>Header Files\Robot Controller</Filter>
406412
</ClInclude>

src/RosMotoPlusConversionUtils.c

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//RosMotoPlusConversionUtils.c
2+
3+
// SPDX-FileCopyrightText: 2023, Yaskawa America, Inc.
4+
// SPDX-FileCopyrightText: 2023, Delft University of Technology
5+
//
6+
// SPDX-License-Identifier: Apache-2.0
7+
8+
#include "MotoROS.h"
9+
10+
11+
void Ros_MpCoord_To_GeomMsgsPose(MP_COORD const* const mp_coord, geometry_msgs__msg__Pose* const ros_pose)
12+
{
13+
ros_pose->position.x = MICROMETERS_TO_METERS(mp_coord->x);
14+
ros_pose->position.y = MICROMETERS_TO_METERS(mp_coord->y);
15+
ros_pose->position.z = MICROMETERS_TO_METERS(mp_coord->z);
16+
QuatConversion_MpCoordOrient_To_GeomMsgsQuaternion(
17+
mp_coord->rx, mp_coord->ry, mp_coord->rz, &ros_pose->orientation);
18+
}
19+
20+
void Ros_MpCoord_To_GeomMsgsTransform(MP_COORD const* const mp_coord, geometry_msgs__msg__Transform* const ros_transform)
21+
{
22+
ros_transform->translation.x = MICROMETERS_TO_METERS(mp_coord->x);
23+
ros_transform->translation.y = MICROMETERS_TO_METERS(mp_coord->y);
24+
ros_transform->translation.z = MICROMETERS_TO_METERS(mp_coord->z);
25+
QuatConversion_MpCoordOrient_To_GeomMsgsQuaternion(
26+
mp_coord->rx, mp_coord->ry, mp_coord->rz, &ros_transform->rotation);
27+
}

src/RosMotoPlusConversionUtils.h

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//RosMotoPlusConversionUtils.h
2+
3+
// SPDX-FileCopyrightText: 2023, Yaskawa America, Inc.
4+
// SPDX-FileCopyrightText: 2023, Delft University of Technology
5+
//
6+
// SPDX-License-Identifier: Apache-2.0
7+
8+
#ifndef MOTOROS2_ROS_MOTOPLUS_CONVERSION_UTILS_H
9+
#define MOTOROS2_ROS_MOTOPLUS_CONVERSION_UTILS_H
10+
11+
12+
/**
13+
* Converts an M+ `MP_COORD` struct to a ROS `geometry_msgs/msg/Pose`.
14+
*
15+
* Unit conversion is also performed by this function:
16+
*
17+
* - `MP_COORD` positions are converted from micro-meters to meters
18+
* - `MP_COORD` orientations are converted from milli-degrees to radians (and
19+
* subsequently to a `Quaternion`)
20+
*
21+
* @param mp_coord Input M+ `MP_COORD` instance
22+
* @param ros_pose Output `geometry_msgs/msg/Pose`
23+
*/
24+
extern void Ros_MpCoord_To_GeomMsgsPose(MP_COORD const* const mp_coord, geometry_msgs__msg__Pose* const ros_pose);
25+
26+
27+
/**
28+
* Converts an M+ `MP_COORD` struct to a ROS `geometry_msgs/msg/Transform`.
29+
*
30+
* Unit conversion is also performed by this function:
31+
*
32+
* - `MP_COORD` positions are converted from micro-meters to meters
33+
* - `MP_COORD` orientations are converted from milli-degrees to radians (and
34+
* subsequently to a `Quaternion`)
35+
*
36+
* @param mp_coord Input M+ `MP_COORD` instance
37+
* @param ros_transform Output `geometry_msgs/msg/Pose`
38+
*/
39+
extern void Ros_MpCoord_To_GeomMsgsTransform(MP_COORD const* const mp_coord, geometry_msgs__msg__Transform* const ros_transform);
40+
41+
42+
#endif // MOTOROS2_ROS_MOTOPLUS_CONVERSION_UTILS_H

0 commit comments

Comments
 (0)