Skip to content

Commit

Permalink
Introduce ROS<->M+ concept conversion functions
Browse files Browse the repository at this point in the history
Only support MP_COORD -> geometry_msgs/{Pose,Transform} for now, but others can be added later.
  • Loading branch information
gavanderhoorn committed Oct 6, 2023
1 parent 9492838 commit 5236faf
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/MotoROS.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
//============================================
#include <std_srvs/srv/trigger.h>
#include <sensor_msgs/msg/joint_state.h>
#include <geometry_msgs/msg/pose.h>
#include <geometry_msgs/msg/transform_stamped.h>
#include <geometry_msgs/msg/quaternion.h>
#include <tf2_msgs/msg/tf_message.h>
Expand Down Expand Up @@ -103,6 +104,7 @@
#include "MathConstants.h"
#include "MotoROS_PlatformLib.h"
#include "Ros_mpGetRobotCalibrationData.h"
#include "RosMotoPlusConversionUtils.h"

extern void Ros_Sleep(float milliseconds);

Expand Down
2 changes: 2 additions & 0 deletions src/MotoROS2_AllControllers.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@
<ClCompile Include="ServiceResetError.c" />
<ClCompile Include="FauxCommandLineArgs.c" />
<ClCompile Include="Ros_mpGetRobotCalibrationData.c" />
<ClCompile Include="RosMotoPlusConversionUtils.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ConfigFile.h" />
Expand Down Expand Up @@ -386,6 +387,7 @@
<ClInclude Include="MathConstants.h" />
<ClInclude Include="MotoROS_PlatformLib.h" />
<ClInclude Include="Ros_mpGetRobotCalibrationData.h" />
<ClInclude Include="RosMotoPlusConversionUtils.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
6 changes: 6 additions & 0 deletions src/MotoROS2_AllControllers.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@
<ClCompile Include="Ros_mpGetRobotCalibrationData.c">
<Filter>Source Files\Robot Controller</Filter>
</ClCompile>
<ClCompile Include="RosMotoPlusConversionUtils.c">
<Filter>Source Files\Utilities</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="MotoROS.h">
Expand Down Expand Up @@ -401,6 +404,9 @@
<ClInclude Include="TimeConversionUtils.h">
<Filter>Header Files\Utilities</Filter>
</ClInclude>
<ClInclude Include="RosMotoPlusConversionUtils.h">
<Filter>Header Files\Utilities</Filter>
</ClInclude>
<ClInclude Include="MotoPlusExterns.h">
<Filter>Header Files\Robot Controller</Filter>
</ClInclude>
Expand Down
27 changes: 27 additions & 0 deletions src/RosMotoPlusConversionUtils.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//RosMotoPlusConversionUtils.c

// SPDX-FileCopyrightText: 2023, Yaskawa America, Inc.
// SPDX-FileCopyrightText: 2023, Delft University of Technology
//
// SPDX-License-Identifier: Apache-2.0

#include "MotoROS.h"


void Ros_MpCoord_To_GeomMsgsPose(MP_COORD const* const mp_coord, geometry_msgs__msg__Pose* const ros_pose)
{
ros_pose->position.x = MICROMETERS_TO_METERS(mp_coord->x);
ros_pose->position.y = MICROMETERS_TO_METERS(mp_coord->y);
ros_pose->position.z = MICROMETERS_TO_METERS(mp_coord->z);
QuatConversion_MpCoordOrient_To_GeomMsgsQuaternion(
mp_coord->rx, mp_coord->ry, mp_coord->rz, &ros_pose->orientation);
}

void Ros_MpCoord_To_GeomMsgsTransform(MP_COORD const* const mp_coord, geometry_msgs__msg__Transform* const ros_transform)
{
ros_transform->translation.x = MICROMETERS_TO_METERS(mp_coord->x);
ros_transform->translation.y = MICROMETERS_TO_METERS(mp_coord->y);
ros_transform->translation.z = MICROMETERS_TO_METERS(mp_coord->z);
QuatConversion_MpCoordOrient_To_GeomMsgsQuaternion(
mp_coord->rx, mp_coord->ry, mp_coord->rz, &ros_transform->rotation);
}
42 changes: 42 additions & 0 deletions src/RosMotoPlusConversionUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//RosMotoPlusConversionUtils.h

// SPDX-FileCopyrightText: 2023, Yaskawa America, Inc.
// SPDX-FileCopyrightText: 2023, Delft University of Technology
//
// SPDX-License-Identifier: Apache-2.0

#ifndef MOTOROS2_ROS_MOTOPLUS_CONVERSION_UTILS_H
#define MOTOROS2_ROS_MOTOPLUS_CONVERSION_UTILS_H


/**
* Converts an M+ `MP_COORD` struct to a ROS `geometry_msgs/msg/Pose`.
*
* Unit conversion is also performed by this function:
*
* - `MP_COORD` positions are converted from micro-meters to meters
* - `MP_COORD` orientations are converted from milli-degrees to radians (and
* subsequently to a `Quaternion`)
*
* @param mp_coord Input M+ `MP_COORD` instance
* @param ros_pose Output `geometry_msgs/msg/Pose`
*/
extern void Ros_MpCoord_To_GeomMsgsPose(MP_COORD const* const mp_coord, geometry_msgs__msg__Pose* const ros_pose);


/**
* Converts an M+ `MP_COORD` struct to a ROS `geometry_msgs/msg/Transform`.
*
* Unit conversion is also performed by this function:
*
* - `MP_COORD` positions are converted from micro-meters to meters
* - `MP_COORD` orientations are converted from milli-degrees to radians (and
* subsequently to a `Quaternion`)
*
* @param mp_coord Input M+ `MP_COORD` instance
* @param ros_transform Output `geometry_msgs/msg/Pose`
*/
extern void Ros_MpCoord_To_GeomMsgsTransform(MP_COORD const* const mp_coord, geometry_msgs__msg__Transform* const ros_transform);


#endif // MOTOROS2_ROS_MOTOPLUS_CONVERSION_UTILS_H

0 comments on commit 5236faf

Please sign in to comment.