Skip to content

Instantly share code, notes, and snippets.

@proger
Last active November 23, 2023 13:31
Show Gist options
  • Select an option

  • Save proger/42c4dc1f84e0f929a322399edaa2f6b6 to your computer and use it in GitHub Desktop.

Select an option

Save proger/42c4dc1f84e0f929a322399edaa2f6b6 to your computer and use it in GitHub Desktop.
robomaster_sim to work with Coppelia 4.6
This patch makes robomaster_sim work with Coppelia 4.6
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 03c1ab6..be6e2cf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,7 +11,7 @@ IF (WIN32)
ELSE()
set(CMAKE_CXX_STANDARD 17)
- add_compile_options(-fPIC -Wall -Wextra -Werror -Wno-unused-parameter -Wno-deprecated-declarations -Wno-missing-field-initializers ) # -Wno-c99-extensions
+ add_compile_options(-fPIC -Wall -Wextra -Wno-unused-parameter -Wno-deprecated-declarations -Wno-missing-field-initializers ) # -Wno-c99-extensions
ENDIF()
option(USE_OPENCV "use OpenCV for vision" OFF)
@@ -147,23 +147,24 @@ endif()
add_subdirectory(coppeliaSim_plugin)
-target_include_directories(simExtRobomaster PRIVATE ${OpenCV_INCLUDE_DIRS})
-target_link_libraries(simExtRobomaster
+target_include_directories(simRobomaster PRIVATE ${OpenCV_INCLUDE_DIRS})
+target_link_libraries(simRobomaster
+ PRIVATE
robomaster
spdlog::spdlog
${Boost_LIBRARIES}
)
if (USE_OPENCV)
- target_link_libraries(simExtRobomaster ${OpenCV_LIBS})
-endif()
-
+ target_link_libraries(simRobomaster ${OpenCV_LIBS})
+endif()
+
IF (WIN32)
- target_compile_options(simExtRobomaster PUBLIC
+ target_compile_options(simRobomaster PUBLIC
)
ELSE()
- target_compile_options(simExtRobomaster PUBLIC
+ target_compile_options(simRobomaster PUBLIC
"-Wno-reorder-ctor"
"-Wno-sign-compare"
"-Wno-delete-non-abstract-non-virtual-dtor"
diff --git a/coppeliaSim_plugin/CMakeLists.txt b/coppeliaSim_plugin/CMakeLists.txt
index c1ab878..a86f49f 100644
--- a/coppeliaSim_plugin/CMakeLists.txt
+++ b/coppeliaSim_plugin/CMakeLists.txt
@@ -8,13 +8,6 @@ set(CMAKE_MACOSX_RPATH 1)
set(COPPELIASIM_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include)
endif()
endif()
-if(NOT LIBPLUGIN_DIR)
- if(DEFINED ENV{COPPELIASIM_ROOT_DIR})
- set(LIBPLUGIN_DIR $ENV{COPPELIASIM_ROOT_DIR}/programming/libPlugin)
- else()
- set(LIBPLUGIN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../libPlugin)
- endif()
-endif()
set(MODEL_FOLDER $ENV{COPPELIASIM_ROOT_DIR}/models/robots/mobile)
@@ -22,10 +15,9 @@ set(MODEL_SENSOR_FOLDER $ENV{COPPELIASIM_ROOT_DIR}/models/components/sensors)
list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules
- ${COPPELIASIM_INCLUDE_DIR}/cmake
- ${LIBPLUGIN_DIR}/cmake)
+ ${COPPELIASIM_INCLUDE_DIR}/cmake)
-find_package(CoppeliaSim 4 REQUIRED)
+find_package(CoppeliaSim 4.5.1.7 REQUIRED)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/generated)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external)
@@ -34,7 +26,7 @@ coppeliasim_generate_stubs(${CMAKE_CURRENT_BINARY_DIR}/generated XML_FILE ${CMAK
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h ESCAPE_QUOTES)
-coppeliasim_add_plugin(simExtRobomaster SOURCES plugin.cpp coppeliasim_robot.cpp)
+coppeliasim_add_plugin(simRobomaster SOURCES plugin.cpp coppeliasim_robot.cpp)
install(FILES ../models/RoboMasterEP.ttm ../models/RoboMasterS1.ttm DESTINATION ${MODEL_FOLDER})
install(FILES ../models/RoboMasterDistanceSensor.ttm DESTINATION ${MODEL_SENSOR_FOLDER})
diff --git a/coppeliaSim_plugin/callbacks.xml b/coppeliaSim_plugin/callbacks.xml
index 4971768..4bd887c 100644
--- a/coppeliaSim_plugin/callbacks.xml
+++ b/coppeliaSim_plugin/callbacks.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<?xml-stylesheet type="text/xsl" href="callbacks.xsl"?>
-<plugin name="Robomaster" author="jerome@idsia.ch">
+<plugin name="simRobomaster" author="jerome@idsia.ch">
<description></description>
<command name="create">
@@ -802,7 +802,7 @@
<params>
<param name="handle" type="int">
<description>The RoboMaster controller handle</description>
- </param>
+ </param>
<param name="name" type="string">
<description>TThe name of the model (without the leading "/")</description>
</param>
@@ -817,7 +817,7 @@
<params>
<param name="handle" type="int">
<description>The RoboMaster controller handle</description>
- </param>
+ </param>
<param name="min_width" type="float" default="0.5">
<description>Minimal visible horizontal portion of the object to be detectable</description>
</param>
@@ -835,7 +835,7 @@
<params>
<param name="handle" type="int">
<description>The RoboMaster controller handle</description>
- </param>
+ </param>
<param name="mask" type="int">
<description>A bit mask: set to 0 to disable vision, to 2 to detect people, or to 128 to detect robots</description>
</param>
@@ -847,7 +847,7 @@
<params>
<param name="handle" type="int">
<description>The RoboMaster controller handle</description>
- </param>
+ </param>
</params>
<return>
<param name="bounding_boxes" type="table" item-type="CS_BoundingBox">
@@ -861,7 +861,7 @@
<params>
<param name="handle" type="int">
<description>The RoboMaster controller handle</description>
- </param>
+ </param>
</params>
<return>
<param name="bounding_boxes" type="table" item-type="CS_BoundingBox">
diff --git a/coppeliaSim_plugin/plugin.cpp b/coppeliaSim_plugin/plugin.cpp
index 954e0e0..299e18a 100644
--- a/coppeliaSim_plugin/plugin.cpp
+++ b/coppeliaSim_plugin/plugin.cpp
@@ -213,7 +213,7 @@ static int add_robot(int cs_handle, std::string serial_number,
std::string gyro_signal = "gyro#" + std::to_string(gyro_handle);
int accelerometer_handle = get_handle(accelerometer_name, cs_handle);
std::string accelerometer_signal = "accelerometer#" + std::to_string(accelerometer_handle);
-
+
_robots.emplace(handle, std::make_unique<CoppeliaSimRobot>(
cs_handle,
wheel_handles, chassis_led_handles, enable_arm,
@@ -249,7 +249,7 @@ std::string action_name(int action_handle) {
class Plugin : public sim::Plugin {
public:
- void onStart() {
+ void onInit() {
if (!registerScriptStuff())
throw std::runtime_error("script stuff initialization failed");
@@ -692,5 +692,5 @@ class Plugin : public sim::Plugin {
// }
};
-SIM_PLUGIN(PLUGIN_NAME, PLUGIN_VERSION, Plugin)
+SIM_PLUGIN(Plugin)
#include "stubsPlusPlus.cpp"
diff --git a/coppeliaSim_plugin/simRobomaster.lua b/coppeliaSim_plugin/simRobomaster.lua
index 3f51fb3..23b386f 100644
--- a/coppeliaSim_plugin/simRobomaster.lua
+++ b/coppeliaSim_plugin/simRobomaster.lua
@@ -1,4 +1,5 @@
-local simRobomaster={}
+local simRobomaster = loadPlugin 'simRobomaster';
+(require 'simRobomaster-typecheck')(simRobomaster)
function simRobomaster.wait_for_completed(robot_handle, action_handle)
local savedLockLevel=sim.setThreadAutomaticSwitch(false) -- forbid automatic switches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment