diff --git a/.gitmodules b/.gitmodules index 2eac8723791..a1efd3045a5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,6 @@ [submodule "src/glm"] path = src/glm url = https://github.com/g-truc/glm.git -[submodule "projects/robots/mobsya/thymio/libraries/dashel-src"] - path = projects/robots/mobsya/thymio/libraries/dashel-src - url = https://github.com/aseba-community/dashel.git -[submodule "projects/robots/mobsya/thymio/controllers/thymio2_aseba/aseba"] - path = projects/robots/mobsya/thymio/controllers/thymio2_aseba/aseba - url = https://github.com/aseba-community/aseba.git [submodule "src/stb"] path = src/stb url = https://github.com/nothings/stb.git diff --git a/Makefile b/Makefile index a6e972783ae..585481e732f 100644 --- a/Makefile +++ b/Makefile @@ -164,15 +164,15 @@ install: help: @+echo - @+echo -e "\033[32;1mWebots Makefile targets:\033[0m" + @+$(ECHO) "\033[32;1mWebots Makefile targets:\033[0m" @+echo - @+echo -e "\033[33;1mmake -j$(THREADS) release\033[0m\t# compile with maximum optimization (default)" - @+echo -e "\033[33;1mmake -j$(THREADS) debug\033[0m \t# compile with gdb debugging symbols" - @+echo -e "\033[33;1mmake -j$(THREADS) profile\033[0m\t# compile with gprof profiling information" - @+echo -e "\033[33;1mmake -j$(THREADS) distrib\033[0m\t# compile in release mode & create distribution package" - @+echo -e "\033[33;1mmake -j$(THREADS) clean\033[0m \t# clean-up the compilation output" - @+echo -e "\033[33;1mmake -j$(THREADS) cleanse\033[0m\t# deep clean-up (dependencies are also removed)" - @+echo -e "\033[33;1mmake help\033[0m\t\t# display this message and exit" + @+$(ECHO) "\033[33;1mmake -j$(THREADS) release\033[0m\t# compile with maximum optimization (default)" + @+$(ECHO) "\033[33;1mmake -j$(THREADS) debug\033[0m \t# compile with gdb debugging symbols" + @+$(ECHO) "\033[33;1mmake -j$(THREADS) profile\033[0m\t# compile with gprof profiling information" + @+$(ECHO) "\033[33;1mmake -j$(THREADS) distrib\033[0m\t# compile in release mode & create distribution package" + @+$(ECHO) "\033[33;1mmake -j$(THREADS) clean\033[0m \t# clean-up the compilation output" + @+$(ECHO) "\033[33;1mmake -j$(THREADS) cleanse\033[0m\t# deep clean-up (dependencies are also removed)" + @+$(ECHO) "\033[33;1mmake help\033[0m\t\t# display this message and exit" @+echo - @+echo -e "\033[32;1mNote:\033[0m You seem to have a processor with $(NUMBER_OF_PROCESSORS) virtual cores," - @+echo -e " hence the \033[33;1m-j$(THREADS)\033[0m option to speed-up the compilation." + @+$(ECHO) "\033[32;1mNote:\033[0m You seem to have a processor with $(NUMBER_OF_PROCESSORS) virtual cores," + @+$(ECHO) " hence the \033[33;1m-j$(THREADS)\033[0m option to speed-up the compilation." diff --git a/docs/guide/images/robots/thymio2/aseba_target_selection.png b/docs/guide/images/robots/thymio2/aseba_target_selection.png deleted file mode 100644 index fd753830126..00000000000 Binary files a/docs/guide/images/robots/thymio2/aseba_target_selection.png and /dev/null differ diff --git a/docs/guide/thymio2.md b/docs/guide/thymio2.md index 9f84c1a75ae..88b0a877d55 100644 --- a/docs/guide/thymio2.md +++ b/docs/guide/thymio2.md @@ -9,8 +9,6 @@ More information about the Thymio II is available from its official [website](ht Webots contains an accurate model of the Thymio II robot. Almost all the Thymio II devices have been modeled and calibrated. -Moreover Aseba studio and VPL for Thymio II can be connected on the simulated model allowing you to program the simulated robot using Aseba. -Many Aseba examples are working directly with the simulated robot. Finally several objects related to the Thymio II are available, including a pen which can draw on any 3D object. ### Thymio II Model @@ -67,8 +65,8 @@ Thymio2 { SFVec3f translation 0 0 0 SFRotation rotation 0 0 1 0 SFString name "Thymio II" - SFString controller "thymio2_aseba" - MFString controllerArgs "port=33333" + SFString controller "thymio2_demo" + MFString controllerArgs [] SFString customData "" SFBool supervisor FALSE SFBool synchronization TRUE @@ -89,31 +87,8 @@ Thymio2 { - `bodySlot`: Extends the robot with new nodes in the body slot. -### Connect Aseba to the Thymio II Model +### Robot Window -The default controller of the Thymio II PROTO is the `thymio2_demo` controller. -It should be changed to `thymio2_aseba` to allow the connection to Aseba programming environment. -However, most world files including the Thymio II robot are already configured to use `thymio2_aseba` as a controller for the Thymio II robot. -Technically, `thymio2_aseba` creates a TCP/IP server on which Aseba can be connected, and it wraps the Aseba API with the Webots API. - -Here is how to proceed to connect Aseba to the Thymio II model in Webots. -Make sure that the simulation is running (the controller has started) and that the controller of the Thymio II robot is `thymio2_aseba`. -You can check this from the Webots scene tree, by opening the Thymio2 node. -Aseba Studio or VPL for Thymio II can then be started. -From the Aseba target selection dialog (see the [figure](#aseba-studio-and-vpl-target-selection-dialog).), select the `Network TCP/IP` option with the following parameters: `Host = localhost` and `Port = 33333`. -Then just click on the `Connect` button. - -In case of a simulation containing several Thymio II, the TCP/IP port of the `thymio2_aseba` controller should be unique for each robot instance. -This value can be modified by editing the `Thymio2::controllerArgs` field. - -%figure "Aseba Studio and VPL target selection dialog" - -![aseba_target_selection.png](images/robots/thymio2/aseba_target_selection.png) - -%end - -The Thymio II window (see the [figure](#thymio-ii-robot-window)) can help you to raise some events easily. -These events are mainly useful when using the VPL for Thymio II software. To open the Thymio II window, select the "Show Robot Window" option in the robot [context menu](the-3d-window.md#context-menu). %figure "Thymio II robot window" diff --git a/lib/controller/.gitignore b/lib/controller/.gitignore index 259d2720dcc..0e997d1775b 100644 --- a/lib/controller/.gitignore +++ b/lib/controller/.gitignore @@ -6,8 +6,4 @@ /python38 /python39 /python310 -/python37_brew -/python38_brew -/python39_brew -/python310_brew /*.so.* diff --git a/projects/default/controllers/ros/Makefile b/projects/default/controllers/ros/Makefile index 8df963517af..43e847366d1 100644 --- a/projects/default/controllers/ros/Makefile +++ b/projects/default/controllers/ros/Makefile @@ -38,11 +38,11 @@ endif PYTHON_COMMAND ?= python3 ifeq (, $(ROS_DISTRO)) release debug profile clean: - @echo "# \033[0;33mROS not installed or 'ROS_DISTRO' not defined\033[0m" + @$(ECHO) "# \033[0;33mROS not installed or 'ROS_DISTRO' not defined\033[0m" else ifeq (2, $(ROS_VERSION)) release debug profile clean: - @echo "# \033[0;33mROS_DISTRO should not be a ROS2 distribution\033[0m" + @$(ECHO) "# \033[0;33mROS_DISTRO should not be a ROS2 distribution\033[0m" else CXX_SOURCES = $(wildcard *.cpp) CXX_SOURCES += $(wildcard highlevel/*.cpp) diff --git a/projects/default/libraries/vehicle/java/Makefile b/projects/default/libraries/vehicle/java/Makefile index ff1b2971f6a..95072f3e9f7 100644 --- a/projects/default/libraries/vehicle/java/Makefile +++ b/projects/default/libraries/vehicle/java/Makefile @@ -64,10 +64,10 @@ LIB += -L"$(WEBOTS_CONTROLLER_LIB_PATH)" -lCppController -lCppCar -lCppDriver # rules ifeq ($(SWIG_EXISTS),) all release debug profile: - @echo -e "# \033[0;33mSWIG not installed, skipping Java API\033[0m" + @$(ECHO) "# \033[0;33mSWIG not installed, skipping Java API\033[0m" else ifeq ($(JAVA_HOME),) all release debug profile: - @echo -e "# \033[0;33mJava not installed or 'JAVA_HOME' not set, skipping Java API\033[0m" + @$(ECHO) "# \033[0;33mJava not installed or 'JAVA_HOME' not set, skipping Java API\033[0m" else all release debug profile: $(JAR) $(LIBRARY) diff --git a/projects/robots/Makefile b/projects/robots/Makefile index 4e0321ddf3a..9d98ec892ad 100644 --- a/projects/robots/Makefile +++ b/projects/robots/Makefile @@ -14,7 +14,6 @@ LIBRARIES=robotis/darwin-op/libraries.Makefile \ neuronics/ipr/libraries.Makefile \ - mobsya/thymio/libraries.Makefile \ kuka/youbot/libraries.Makefile CONTROLLERS=\ @@ -96,8 +95,6 @@ robotis/darwin-op/controllers.Makefile robotis/darwin-op/plugins/robot_windows.M neuronics/ipr/controllers.Makefile: neuronics/ipr/libraries.Makefile -mobsya/thymio/controllers.Makefile: mobsya/thymio/libraries.Makefile - kuka/youbot/controllers.Makefile: kuka/youbot/libraries.Makefile %.Makefile: diff --git a/projects/robots/mobsya/thymio/controllers/Makefile b/projects/robots/mobsya/thymio/controllers/Makefile index 4b83bba082b..ad4a71df3e4 100644 --- a/projects/robots/mobsya/thymio/controllers/Makefile +++ b/projects/robots/mobsya/thymio/controllers/Makefile @@ -13,18 +13,6 @@ # limitations under the License. TARGETS = thymio2_demo.Makefile -ifneq (,$(wildcard ../libraries/dashel/dashel/dashel.h)) -ADD_THYMIO2_ASEBA = 1 -endif - -ifeq ($(MAKECMDGOALS),clean) -ADD_THYMIO2_ASEBA = 1 -endif - -ifdef ADD_THYMIO2_ASEBA -TARGETS += thymio2_aseba.Makefile -endif - .PHONY: release debug profile clean release debug profile clean: $(TARGETS) diff --git a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/.gitignore b/projects/robots/mobsya/thymio/controllers/thymio2_aseba/.gitignore deleted file mode 100644 index 3b3801c49c0..00000000000 --- a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/thymio2_aseba diff --git a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Makefile b/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Makefile deleted file mode 100644 index 5fc57e4d1d7..00000000000 --- a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 1996-2022 Cyberbotics Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Webots Makefile system -# -# You may add some variable definitions hereafter to customize the build process -# See documentation in $(WEBOTS_HOME_PATH)/resources/Makefile.include - -null := -space := $(null) $(null) -WEBOTS_HOME_PATH?=$(subst $(space),\ ,$(strip $(subst \,/,$(WEBOTS_HOME)))) -include $(WEBOTS_HOME_PATH)/resources/Makefile.os.include - -DASHEL_HOME = $(WEBOTS_HOME)/projects/robots/mobsya/thymio/libraries/dashel/ - -C_SOURCES = \ - thymio2_definitions.c \ - thymio2_natives.c \ - aseba/aseba/transport/buffer/vm-buffer.c \ - aseba/aseba/vm/natives.c \ - aseba/aseba/vm/vm.c -CXX_SOURCES = $(wildcard *.cpp) - -ifneq ($(OSTYPE),darwin) -CFLAGS = -fno-strict-aliasing -endif - -ifeq ($(OSTYPE),windows) -CFLAGS = -Wno-address -Wno-unused-function -DDISABLE_WEAK_CALLBACKS -endif - -INCLUDE = -I"$(DASHEL_HOME)" -Iaseba/aseba -LIBRARIES = -L"$(DASHEL_HOME)" -ldashel -NO_FAT_BINARY = 1 - -include $(WEBOTS_HOME_PATH)/resources/Makefile.include diff --git a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Thymio2AsebaHub.cpp b/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Thymio2AsebaHub.cpp deleted file mode 100644 index 2fde759d4f0..00000000000 --- a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Thymio2AsebaHub.cpp +++ /dev/null @@ -1,256 +0,0 @@ -// Copyright 1996-2022 Cyberbotics Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Strongly inspired from https://github.com/aseba-community/aseba/blob/master/targets/challenge/challenge.cpp - -#include "Thymio2AsebaHub.hpp" - -#include -#include -#include - -#include // memcpy -#include -#include - -using namespace std; - -static Thymio2AsebaHub *thymio2 = NULL; - -Thymio2AsebaHub::Thymio2AsebaHub(int port) : stream(0), lastMessageSource(0), lastMessageData(0) { - thymio2 = this; - - vm.nodeId = 1; - - bytecode.resize(512); - vm.bytecode = &bytecode[0]; - vm.bytecodeSize = bytecode.size(); - - stack.resize(64); - vm.stack = &stack[0]; - vm.stackSize = stack.size(); - - vm.variables = reinterpret_cast(&variables); - vm.variablesSize = sizeof(variables) / sizeof(short int); - - try { - std::ostringstream o; - o << "tcpin:port=" << port; - Dashel::Hub::connect(o.str()); - cout << "Server started on port " << port << "..." << std::endl; - } catch (Dashel::DashelException &e) { - cerr << "Cannot create listening port " << port << ": " << e.what() << std::endl; - abort(); - } - - AsebaVMInit(&vm); - - variables.productid = ASEBA_PID_THYMIO2; // TODO: is this useful ? -} - -Thymio2AsebaHub::~Thymio2AsebaHub() { - thymio2 = NULL; -} - -void Thymio2AsebaHub::connectionCreated(Dashel::Stream *stream) { - std::string targetName = stream->getTargetName(); - if (targetName.substr(0, targetName.find_first_of(':')) == "tcp") { - cout << "New client connected." << endl; - if (this->stream) { - closeStream(this->stream); - cerr << " Disconnected old client." << endl; - } - this->stream = stream; - } -} - -void Thymio2AsebaHub::incomingData(Dashel::Stream *stream) { - unsigned short int temp; - unsigned short int len; - - stream->read(&temp, 2); - len = bswap16(temp); - stream->read(&temp, 2); - lastMessageSource = bswap16(temp); - lastMessageData.resize(len + 2); - stream->read(&lastMessageData[0], lastMessageData.size()); - - if (bswap16(*(unsigned short int *)&lastMessageData[0]) >= 0xA000) - AsebaProcessIncomingEvents(&vm); - else - cerr << "Non debug event dropped." << endl; -} - -void Thymio2AsebaHub::connectionClosed(Dashel::Stream *stream, bool abnormal) { - if (stream == this->stream) { - this->stream = 0; - vm.breakpointsCount = 0; - } - if (abnormal) - cerr << "Client has disconnected unexpectedly." << endl; - else - cout << "Client has disconnected properly." << endl; -} - -void Thymio2AsebaHub::sendEvents(bool events[]) { - bool vmHasRun = false; - - if (AsebaMaskIsClear(vm.flags, ASEBA_VM_STEP_BY_STEP_MASK) || AsebaMaskIsClear(vm.flags, ASEBA_VM_EVENT_ACTIVE_MASK)) { - for (int i = 0; i < EVENT_COUNT; ++i) { - if (events[i]) { - AsebaVMSetupEvent(&vm, ASEBA_EVENT_LOCAL_EVENTS_START - i); - AsebaVMRun(&vm, 1000); - vmHasRun = true; - } - } - } - - if (!vmHasRun) - AsebaVMRun(&vm, 1000); -} - -extern "C" { - -void AsebaPutVmToSleep(AsebaVMState *vm) { -} - -void AsebaSendBuffer(AsebaVMState *vm, const unsigned char *data, unsigned short int length) { - Dashel::Stream *stream = thymio2->stream; - if (!stream) { - cerr << "Invalid stream" << std::endl; - return; - } - - try { - unsigned short int temp; - temp = bswap16(length - 2); - stream->write(&temp, 2); - temp = bswap16(vm->nodeId); - stream->write(&temp, 2); - stream->write(data, length); - stream->flush(); - } catch (Dashel::DashelException &e) { - cerr << "Cannot write to socket: " << stream->getFailReason() << std::endl; - } -} - -unsigned short int AsebaGetBuffer(AsebaVMState *vm, unsigned char *data, unsigned short int maxLength, - unsigned short int *source) { - if (thymio2->lastMessageData.size()) { - *source = thymio2->lastMessageSource; - memcpy(data, &thymio2->lastMessageData[0], thymio2->lastMessageData.size()); - } - return thymio2->lastMessageData.size(); -} - -extern AsebaVMDescription vmDescription; -const AsebaVMDescription *AsebaGetVMDescription(AsebaVMState *vm) { - return &vmDescription; -} - -extern AsebaLocalEventDescription localEvents[]; -const AsebaLocalEventDescription *AsebaGetLocalEventsDescriptions(AsebaVMState *vm) { - return localEvents; -} - -extern AsebaNativeFunctionDescription *nativeFunctionsDescriptions[]; -const AsebaNativeFunctionDescription *const *AsebaGetNativeFunctionsDescriptions(AsebaVMState *vm) { - return nativeFunctionsDescriptions; -} - -extern AsebaNativeFunctionPointer nativeFunctions[]; -void AsebaNativeFunction(AsebaVMState *vm, unsigned short int id) { - nativeFunctions[id](vm); -} - -void AsebaWriteBytecode(AsebaVMState *vm) { -} - -void AsebaResetIntoBootloader(AsebaVMState *vm) { -} - -#ifndef DISABLE_WEAK_CALLBACKS -void AsebaVMRunCB(AsebaVMState *vm) { -} - -void AsebaVMErrorCB(AsebaVMState *vm, const char *message) { -} - -void AsebaVMResetCB(AsebaVMState *vm) { -} -#endif - -void AsebaAssert(AsebaVMState *vm, AsebaAssertReason reason) { - cerr << "\nFatal error: "; - switch (vm->nodeId) { - case 1: - cerr << "left motor module"; - break; - case 2: - cerr << "right motor module"; - break; - case 3: - cerr << "proximity sensors module"; - break; - case 4: - cerr << "distance sensors module"; - break; - default: - cerr << "unknown module"; - break; - } - cerr << " has produced exception: "; - switch (reason) { - case ASEBA_ASSERT_UNKNOWN: - cerr << "undefined"; - break; - case ASEBA_ASSERT_UNKNOWN_UNARY_OPERATOR: - cerr << "unknown unary operator"; - break; - case ASEBA_ASSERT_UNKNOWN_BINARY_OPERATOR: - cerr << "unknown binary operator"; - break; - case ASEBA_ASSERT_UNKNOWN_BYTECODE: - cerr << "unknown bytecode"; - break; - case ASEBA_ASSERT_STACK_OVERFLOW: - cerr << "stack overflow"; - break; - case ASEBA_ASSERT_STACK_UNDERFLOW: - cerr << "stack underflow"; - break; - case ASEBA_ASSERT_OUT_OF_VARIABLES_BOUNDS: - cerr << "out of variables bounds"; - break; - case ASEBA_ASSERT_OUT_OF_BYTECODE_BOUNDS: - cerr << "out of bytecode bounds"; - break; - case ASEBA_ASSERT_STEP_OUT_OF_RUN: - cerr << "step out of run"; - break; - case ASEBA_ASSERT_BREAKPOINT_OUT_OF_BYTECODE_BOUNDS: - cerr << "breakpoint out of bytecode bounds"; - break; - case ASEBA_ASSERT_EMIT_BUFFER_TOO_LONG: - cerr << "tried to emit a buffer too long"; - break; - default: - cerr << "unknown exception"; - break; - } - cerr << ".\npc = " << vm->pc << ", sp = " << vm->sp; - cerr << "\nResetting VM" << std::endl; - AsebaVMInit(vm); -} -} diff --git a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Thymio2AsebaHub.hpp b/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Thymio2AsebaHub.hpp deleted file mode 100644 index ceb54b249ae..00000000000 --- a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Thymio2AsebaHub.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 1996-2022 Cyberbotics Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Strongly inspired from https://github.com/aseba-community/aseba/blob/master/targets/challenge/challenge.cpp - -#ifndef THYMIO2_ASEBA_STUDIO_HUB_HPP -#define THYMIO2_ASEBA_STUDIO_HUB_HPP - -#ifndef ASEBA_ASSERT -#define ASEBA_ASSERT -#endif - -#include "thymio2_definitions.h" - -#include - -#include - -#include - -class Thymio2AsebaHub : public Dashel::Hub { -public: - explicit Thymio2AsebaHub(int port); - virtual ~Thymio2AsebaHub(); - - void connectionCreated(Dashel::Stream *stream); - void incomingData(Dashel::Stream *stream); - void connectionClosed(Dashel::Stream *stream, bool abnormal); - void sendEvents(bool events[]); - - Dashel::Stream *stream; - AsebaVMState vm; - std::valarray bytecode; - std::valarray stack; - _vmVariables variables; - - unsigned short int lastMessageSource; - std::valarray lastMessageData; -}; - -#endif diff --git a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Thymio2Model.cpp b/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Thymio2Model.cpp deleted file mode 100644 index 40704fbe19c..00000000000 --- a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Thymio2Model.cpp +++ /dev/null @@ -1,518 +0,0 @@ -// Copyright 1996-2022 Cyberbotics Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "Thymio2Model.hpp" - -#include "Thymio2AsebaHub.hpp" - -#include -#include -#include -#include -#include -#include - -#include // sscanf -#include -#include -#include - -#define VELOCITY_RATIO (9.53 / 500.0) - -using namespace webots; -using namespace std; - -static Thymio2Model *thymio2 = NULL; - -Thymio2Model::Thymio2Model() : Robot() { - thymio2 = this; - - mStepCounter = -1; // the first step will be step 0, the modulo tests on the period is facilitated this way - mTimeStep = (int)getBasicTimeStep(); - - if (mTimeStep != 10) - cout << "In order to have an accurate simulation, it is recommended to set WorldInfo::basicTimeStep to 10." << endl; - - // Hertz value from https://aseba.wdfiles.com/local--files/en:thymioprogram/ThymioCheatSheet.pdf - mAccelerometerPeriod = hertzToBestMsPeriod(16); // only sensor not tolerand to the recommended 10ms basic time step - mProxsPeriod = hertzToBestMsPeriod(10); - mButtonsPeriod = hertzToBestMsPeriod(20); - mMotorsPeriod = hertzToBestMsPeriod(100); - - initDevices(); - reset(); - safeStep(); -} - -Thymio2Model::~Thymio2Model() { -} - -void Thymio2Model::reset() { - mLastMotorPosition[M_LEFT] = 0.0; - mLastMotorPosition[M_RIGHT] = 0.0; - - for (int i = 0; i < 5; ++i) - mLastButtonsState[i] = false; - - for (int i = 0; i < 2; ++i) { - mLastTimerPeriod[i] = 0; - mTimerStepStart[i] = -1; - } - - mAutomaticBehaviorAccLeds = true; - mAutomaticBehaviorButtonLeds = true; - mAutomaticBehaviorProxLeds = true; -} - -bool Thymio2Model::safeStep() { - if (mAutomaticBehaviorAccLeds) - behaviorAccLeds(); - if (mAutomaticBehaviorButtonLeds) - behaviorButtonLeds(); - if (mAutomaticBehaviorProxLeds) - behaviorProxLeds(); - - ++mStepCounter; - return step(mTimeStep) != -1; -} - -void Thymio2Model::initDevices() { - mAccelerometer = getAccelerometer("acc"); - mAccelerometer->enable(mAccelerometerPeriod); - - for (int i = 0; i < 7; ++i) { - ostringstream s; - s << "prox.horizontal." << i; - mHorizontalProxs[i] = getDistanceSensor(s.str()); - mHorizontalProxs[i]->enable(mProxsPeriod); - } - - mVerticalProxs[M_LEFT] = getDistanceSensor("prox.ground.0"); - mVerticalProxs[M_RIGHT] = getDistanceSensor("prox.ground.1"); - for (int i = 0; i < 2; ++i) - mVerticalProxs[i]->enable(mProxsPeriod); - - mMotors[M_LEFT] = getMotor("motor.left"); - mMotors[M_RIGHT] = getMotor("motor.right"); - for (int i = 0; i < 2; ++i) - mMotors[i]->setPosition(numeric_limits::infinity()); - - mPositionSensors[M_LEFT] = getPositionSensor("motor.left.position"); - mPositionSensors[M_RIGHT] = getPositionSensor("motor.right.position"); - for (int i = 0; i < 2; ++i) - mPositionSensors[i]->enable(mMotorsPeriod); - - mButtons[B_FORWARD] = getTouchSensor("button.forward"); - mButtons[B_RIGHT] = getTouchSensor("button.right"); - mButtons[B_BACKWARD] = getTouchSensor("button.backward"); - mButtons[B_LEFT] = getTouchSensor("button.left"); - mButtons[B_CENTER] = getTouchSensor("button.center"); - for (int i = 0; i < 5; ++i) - mButtons[i]->enable(mButtonsPeriod); -} - -void Thymio2Model::sensorToHub(Thymio2AsebaHub *hub) { - updateWindowData(); - - if (isPeriodicEventFired(mAccelerometerPeriod)) { - const double *accValues = mAccelerometer->getValues(); - for (int i = 0; i < 3; ++i) - hub->variables.acc[i] = accValues[i]; - } - - if (isPeriodicEventFired(mProxsPeriod)) { - std::stringstream wwiMessage; - for (int i = 0; i < 7; ++i) { - const double value = mHorizontalProxs[i]->getValue(); - hub->variables.prox[i] = value; - wwiMessage << int(value) << " "; - } - for (int i = 0; i < 2; ++i) { - // TODO: - // the following is a already good approximation - // a more precise solution could be achieved by adding calibrated LightSensors - // and to set ground_ambiant, and to compute delta as - // ground_reflected - ground_ambiant - const double value = mVerticalProxs[i]->getValue(); - hub->variables.ground_reflected[i] = value; - hub->variables.ground_delta[i] = value; - wwiMessage << int(value) << " "; - } - - wwiSendText(wwiMessage.str()); - } - - if (isPeriodicEventFired(mButtonsPeriod)) - for (int i = 0; i < 5; ++i) - hub->variables.buttons_state[i] = mButtons[i]->getValue() || mWindowData[i]; - - if (isPeriodicEventFired(mMotorsPeriod)) - for (int i = 0; i < 2; ++i) { - double currentPosition = mPositionSensors[i]->getValue(); - double velocity = (currentPosition - mLastMotorPosition[i]) / (0.001 * mTimeStep); - hub->variables.uind[i] = velocity / VELOCITY_RATIO; - hub->variables.pwm[i] = -1.6 * hub->variables.uind[i]; // poor approximation - mLastMotorPosition[i] = currentPosition; - } -} - -static double clamp(double n, double lower, double upper) { - return std::max(lower, std::min(n, upper)); -} - -void Thymio2Model::hubToActuators(const Thymio2AsebaHub *hub) { - double leftVelocity = VELOCITY_RATIO * clamp(hub->variables.target[0], -500, 500); - double rightVelocity = VELOCITY_RATIO * clamp(hub->variables.target[1], -500, 500); - mMotors[M_LEFT]->setVelocity(leftVelocity); - mMotors[M_RIGHT]->setVelocity(rightVelocity); -} - -void Thymio2Model::updateEvents(const Thymio2AsebaHub *hub, bool events[]) { - // clear all events - for (int i = 0; i < EVENT_COUNT; ++i) - events[i] = false; - - // set the appropriate events - events[EVENT_ACC] = isPeriodicEventFired(mButtonsPeriod); - events[EVENT_BUTTONS] = isPeriodicEventFired(mButtonsPeriod); - events[EVENT_MOTOR] = isPeriodicEventFired(mMotorsPeriod); - events[EVENT_PROX] = isPeriodicEventFired(mProxsPeriod); - - if (events[EVENT_BUTTONS]) { - for (int i = 0; i < 5; ++i) { - bool state = mButtons[i]->getValue() || mWindowData[i]; - if (mLastButtonsState[i] != state) - events[EVENT_B_BACKWARD + i] = true; - mLastButtonsState[i] = state; - } - } - - // timer management - for (int i = 0; i < 2; i++) { - if (hub->variables.timers[i] != mLastTimerPeriod[i]) { - if (hub->variables.timers[i] > 0) { - mTimerStepStart[i] = mStepCounter; - - // check that the timer period is a multiple of WorldInfo::timeStep - // but only for small periods (arbitrarily: < 2*timeStep) because after the generated error is less important - if (hub->variables.timers[i] < 2 * mTimeStep && hub->variables.timers[i] != mTimeStep) - cout << "In simulation, timer " << i << " period should be above or equal to WorldInfo::timeStep" << endl; - } else - mTimerStepStart[i] = -1; - - mLastTimerPeriod[i] = hub->variables.timers[i]; - } - - events[EVENT_TIMER0 + i] = isPeriodicEventFired(hub->variables.timers[i], mTimerStepStart[i]); - } - - // read the robot window events if any - events[EVENT_MIC] = mWindowData[5]; - events[EVENT_TAP] = mWindowData[6]; -} - -void Thymio2Model::updateWindowData() { - std::string text = wwiReceiveText(); - if (text.compare(0, 10, "mousedown ") == 0) { - std::string buttonName = text.substr(10); - if (buttonName.compare("backward") == 0) - mWindowData[B_BACKWARD] = true; - else if (buttonName.compare("forward") == 0) - mWindowData[B_FORWARD] = true; - else if (buttonName.compare("center") == 0) - mWindowData[B_CENTER] = true; - else if (buttonName.compare("right") == 0) - mWindowData[B_RIGHT] = true; - else if (buttonName.compare("left") == 0) - mWindowData[B_LEFT] = true; - else if (buttonName.compare("clap") == 0) - mWindowData[5] = true; - else if (buttonName.compare("tap") == 0) - mWindowData[6] = true; - } else if (text.compare("mouseup") == 0) { - for (int i = 0; i < 7; ++i) - mWindowData[i] = false; - } -} - -void Thymio2Model::behaviorButtonLeds() { - // cf. https://github.com/aseba-community/aseba-target-thymio2/blob/master/behavior.c - - static unsigned int counter[5]; - int i; - for (i = 0; i < 5; ++i) { - if (mButtons[i]->getValue()) { - counter[i] += 3; - if (counter[i] > 32) - counter[i] = 32; - } else - counter[i] = 0; - } - - if (counter[2]) { - thymio2->getLED("leds.buttons.led0")->set(counter[2]); - thymio2->getLED("leds.buttons.led1")->set(counter[2]); - thymio2->getLED("leds.buttons.led2")->set(counter[2]); - thymio2->getLED("leds.buttons.led3")->set(counter[2]); - } else { - thymio2->getLED("leds.buttons.led0")->set(counter[3]); - thymio2->getLED("leds.buttons.led1")->set(counter[4]); - thymio2->getLED("leds.buttons.led2")->set(counter[0]); - thymio2->getLED("leds.buttons.led3")->set(counter[1]); - } - - // Note: removed the multi touch behavior: not possible in Webots -} - -void Thymio2Model::behaviorProxLeds() { - // cf. https://github.com/aseba-community/aseba-target-thymio2/blob/master/behavior.c - - static int max[9] = {4000, 4000, 4000, 4000, 4000, 4000, 4000, 900, 900}; - static int min[9] = {1200, 1200, 1200, 1200, 1200, 1200, 1200, 0, 0}; - static string led[10] = {"leds.prox.h.led0", "leds.prox.h.led1", "leds.prox.h.led2", "leds.prox.h.led3", "leds.prox.h.led4", - "leds.prox.h.led5", "leds.prox.h.led6", "leds.prox.h.led7", "leds.prox.v.led0", "leds.prox.v.led1"}; - int i; - for (i = 0; i < 7; ++i) { - if (max[i] < mHorizontalProxs[i]->getValue()) - max[i] = mHorizontalProxs[i]->getValue(); - if (mHorizontalProxs[i]->getValue() != 0 && min[i] > mHorizontalProxs[i]->getValue()) - min[i] = mHorizontalProxs[i]->getValue(); - } - for (i = 0; i < 2; ++i) { - if (max[i + 7] < mVerticalProxs[i]->getValue()) - max[i + 7] = mVerticalProxs[i]->getValue(); - } - - for (i = 0; i < 7; ++i) { - int s = mHorizontalProxs[i]->getValue() - min[i]; - int d = max[i] - min[i]; - - if (s < 0) - s = 0; - - int b = d ? (s * 32 / d) : 0; - - if (i == 2) { - getLED(led[i])->set(b); - getLED(led[i + 1])->set(b); - } else if (i > 2) - getLED(led[i + 1])->set(b); - else - getLED(led[i])->set(b); - } - - for (i = 0; i < 2; ++i) { - int s = mVerticalProxs[i]->getValue() > 0 ? mVerticalProxs[i]->getValue() : 0; - int b = s * 32 / max[i + 7]; - getLED(led[i + 8])->set(b); - } -} - -void Thymio2Model::behaviorAccLeds() { - // cf. https://github.com/aseba-community/aseba-target-thymio2/blob/master/behavior.c - - static string previous_led = ""; - - string led = ""; - - if (mAccelerometer->getValues()[2] < 21) { - static double M_PI_8 = M_PI / 8.0; - double ha = atan2(mAccelerometer->getValues()[0], mAccelerometer->getValues()[1]); - if (ha >= -M_PI_8 && ha < M_PI_8) - led = "leds.circle.led4"; - else if (ha < -M_PI_8 && ha >= -3.0 * M_PI_8) - led = "leds.circle.led3"; - else if (ha < -3.0 * M_PI_8 && ha >= -5.0 * M_PI_8) - led = "leds.circle.led2"; - else if (ha < -5.0 * M_PI_8 && ha >= -7.0 * M_PI_8) - led = "leds.circle.led1"; - else if (ha < -7.0 * M_PI_8 || ha >= 7.0 * M_PI_8) - led = "leds.circle.led0"; - else if (ha < 3.0 * M_PI_8 && ha >= M_PI_8) - led = "leds.circle.led5"; - else if (ha < 5.0 * M_PI_8 && ha >= 3.0 * M_PI_8) - led = "leds.circle.led6"; - else if (ha < 7.0 * M_PI_8 && ha >= 5.0 * M_PI_8) - led = "leds.circle.led7"; - - int intensity = 40 - abs(mAccelerometer->getValues()[2]) * 2; - if (intensity < 0) - intensity = 0; - else if (intensity > 32) - intensity = 32; - - if (!led.empty()) { - // cppcheck-suppress knownConditionTrueFalse - if (!previous_led.empty()) - getLED(previous_led)->set(0); - getLED(led)->set(intensity); - } - previous_led = led; - } else { - // cppcheck-suppress knownConditionTrueFalse - if (!previous_led.empty()) - getLED(previous_led)->set(0); - - previous_led = ""; - } -} - -int Thymio2Model::hertzToBestMsPeriod(int hertz) const { - return mTimeStep * (1000 / hertz / mTimeStep); -} - -bool Thymio2Model::isPeriodicEventFired(int period, int startCounter) const { - if (period > 0) { - if (period < mTimeStep) - // Webots cannot go quicker. time constraints are not fullfilled. - return true; - else { - // Hypothesis: Webots is modifying the sensors according to the following rule: - bool fireRequired((mStepCounter - startCounter) % (period / mTimeStep) == 0); - - // for the timer case, don't fire the event directly, but wait at least on the next step - if (startCounter > 0 && mStepCounter == startCounter) - return false; - - return fireRequired; - } - } - return false; -} - -static int convertRGBColorToWebotsColor(int r, int g, int b, int scale) { - return ((0xFF & (r * 0xFF / scale)) << 16) + ((0xFF & (g * 0xFF / scale)) << 8) + (0xFF & (b * 0xFF / scale)); -} - -extern "C" { -#include - -// cf. https://github.com/aseba-community/aseba-target-thymio2/blob/master/thymio_natives.c - -void set_rgb_top(AsebaVMState *vm) { - int r = vm->variables[AsebaNativePopArg(vm)]; - int g = vm->variables[AsebaNativePopArg(vm)]; - int b = vm->variables[AsebaNativePopArg(vm)]; - - thymio2->getLED("leds.top")->set(convertRGBColorToWebotsColor(r, g, b, 32)); -} - -void set_led(AsebaVMState *vm) { - /*int led = vm->variables[*/ AsebaNativePopArg(vm) /*]*/; - /*int b = vm->variables[*/ AsebaNativePopArg(vm) /*]*/; - - // This function is not accessible from the user -} - -void set_led_circle(AsebaVMState *vm) { - int l0 = vm->variables[AsebaNativePopArg(vm)]; - int l1 = vm->variables[AsebaNativePopArg(vm)]; - int l2 = vm->variables[AsebaNativePopArg(vm)]; - int l3 = vm->variables[AsebaNativePopArg(vm)]; - int l4 = vm->variables[AsebaNativePopArg(vm)]; - int l5 = vm->variables[AsebaNativePopArg(vm)]; - int l6 = vm->variables[AsebaNativePopArg(vm)]; - int l7 = vm->variables[AsebaNativePopArg(vm)]; - - thymio2->setAutomaticBehaviorAccLeds(false); - - thymio2->getLED("leds.circle.led0")->set(l0); - thymio2->getLED("leds.circle.led1")->set(l1); - thymio2->getLED("leds.circle.led2")->set(l2); - thymio2->getLED("leds.circle.led3")->set(l3); - thymio2->getLED("leds.circle.led4")->set(l4); - thymio2->getLED("leds.circle.led5")->set(l5); - thymio2->getLED("leds.circle.led6")->set(l6); - thymio2->getLED("leds.circle.led7")->set(l7); -} - -void set_rgb_br(AsebaVMState *vm) { - int r = vm->variables[AsebaNativePopArg(vm)]; - int g = vm->variables[AsebaNativePopArg(vm)]; - int b = vm->variables[AsebaNativePopArg(vm)]; - - thymio2->getLED("leds.bottom.right")->set(convertRGBColorToWebotsColor(r, g, b, 32)); -} - -void set_rgb_bl(AsebaVMState *vm) { - int r = vm->variables[AsebaNativePopArg(vm)]; - int g = vm->variables[AsebaNativePopArg(vm)]; - int b = vm->variables[AsebaNativePopArg(vm)]; - - thymio2->getLED("leds.bottom.left")->set(convertRGBColorToWebotsColor(r, g, b, 32)); -} - -void set_buttons_leds(AsebaVMState *vm) { - int l0 = vm->variables[AsebaNativePopArg(vm)]; - int l1 = vm->variables[AsebaNativePopArg(vm)]; - int l2 = vm->variables[AsebaNativePopArg(vm)]; - int l3 = vm->variables[AsebaNativePopArg(vm)]; - - thymio2->setAutomaticBehaviorButtonLeds(false); - - thymio2->getLED("leds.buttons.led0")->set(l0); - thymio2->getLED("leds.buttons.led1")->set(l1); - thymio2->getLED("leds.buttons.led2")->set(l2); - thymio2->getLED("leds.buttons.led3")->set(l3); -} - -void set_hprox_leds(AsebaVMState *vm) { - int l0 = vm->variables[AsebaNativePopArg(vm)]; - int l1 = vm->variables[AsebaNativePopArg(vm)]; - int l2 = vm->variables[AsebaNativePopArg(vm)]; - int l3 = vm->variables[AsebaNativePopArg(vm)]; - int l4 = vm->variables[AsebaNativePopArg(vm)]; - int l5 = vm->variables[AsebaNativePopArg(vm)]; - int l6 = vm->variables[AsebaNativePopArg(vm)]; - int l7 = vm->variables[AsebaNativePopArg(vm)]; - - thymio2->setAutomaticBehaviorProxLeds(false); - - thymio2->getLED("leds.prox.h.led0")->set(l0); - thymio2->getLED("leds.prox.h.led1")->set(l1); - thymio2->getLED("leds.prox.h.led2")->set(l2); - thymio2->getLED("leds.prox.h.led3")->set(l3); - thymio2->getLED("leds.prox.h.led4")->set(l4); - thymio2->getLED("leds.prox.h.led5")->set(l5); - thymio2->getLED("leds.prox.h.led6")->set(l6); - thymio2->getLED("leds.prox.h.led7")->set(l7); -} - -void set_vprox_leds(AsebaVMState *vm) { - int l0 = vm->variables[AsebaNativePopArg(vm)]; - int l1 = vm->variables[AsebaNativePopArg(vm)]; - - thymio2->setAutomaticBehaviorProxLeds(false); - - thymio2->getLED("leds.prox.v.led0")->set(l0); - thymio2->getLED("leds.prox.v.led1")->set(l1); -} - -void set_rc_leds(AsebaVMState *vm) { - int l = vm->variables[AsebaNativePopArg(vm)]; - thymio2->getLED("leds.rc")->set(l); -} - -void set_sound_leds(AsebaVMState *vm) { - int l = vm->variables[AsebaNativePopArg(vm)]; - thymio2->getLED("leds.sound")->set(l); -} - -void set_ntc_leds(AsebaVMState *vm) { - int l0 = vm->variables[AsebaNativePopArg(vm)]; - int l1 = vm->variables[AsebaNativePopArg(vm)]; - thymio2->getLED("leds.temperature.red")->set(l0); - thymio2->getLED("leds.temperature.blue")->set(l1); -} -} diff --git a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Thymio2Model.hpp b/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Thymio2Model.hpp deleted file mode 100644 index 3138325c32b..00000000000 --- a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/Thymio2Model.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 1996-2022 Cyberbotics Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef THYMIO_2_MODEL_HPP -#define THYMIO_2_MODEL_HPP - -#include - -namespace webots { - class Accelerometer; - class DistanceSensor; - class Motor; - class PositionSensor; - class TouchSensor; -} // namespace webots - -class Thymio2AsebaHub; - -class Thymio2Model : public webots::Robot { -public: - Thymio2Model(); - virtual ~Thymio2Model(); - - bool safeStep(); - - void sensorToHub(Thymio2AsebaHub *hub); - void hubToActuators(const Thymio2AsebaHub *hub); - void updateEvents(const Thymio2AsebaHub *hub, bool events[]); - - void setAutomaticBehaviorAccLeds(bool enable) { mAutomaticBehaviorAccLeds = enable; } - void setAutomaticBehaviorButtonLeds(bool enable) { mAutomaticBehaviorButtonLeds = enable; } - void setAutomaticBehaviorProxLeds(bool enable) { mAutomaticBehaviorProxLeds = enable; } - -private: - enum Button { B_BACKWARD, B_LEFT, B_CENTER, B_FORWARD, B_RIGHT }; - enum MotorSide { M_LEFT, M_RIGHT }; - - void initDevices(); - void reset(); - - void behaviorAccLeds(); - void behaviorButtonLeds(); - void behaviorProxLeds(); - - int hertzToBestMsPeriod(int hertz) const; - bool isPeriodicEventFired(int period, int startCounter = 0) const; - - int mTimeStep; - int mStepCounter; - - int mAccelerometerPeriod; - int mProxsPeriod; - int mButtonsPeriod; - int mMotorsPeriod; - - int mLastTimerPeriod[2]; - int mTimerStepStart[2]; - - bool mAutomaticBehaviorAccLeds; - bool mAutomaticBehaviorButtonLeds; - bool mAutomaticBehaviorProxLeds; - - double mLastMotorPosition[2]; - bool mLastButtonsState[5]; - - void updateWindowData(); - int mWindowData[7]; // should match with the robot window implementation - - webots::Accelerometer *mAccelerometer; - webots::TouchSensor *mButtons[5]; - webots::Motor *mMotors[2]; - webots::PositionSensor *mPositionSensors[2]; - webots::DistanceSensor *mHorizontalProxs[7]; - webots::DistanceSensor *mVerticalProxs[2]; -}; - -#endif diff --git a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/aseba b/projects/robots/mobsya/thymio/controllers/thymio2_aseba/aseba deleted file mode 160000 index 3c14f0cb951..00000000000 --- a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/aseba +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3c14f0cb9510c60502821bfd7adb22e795540479 diff --git a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/main.cpp b/projects/robots/mobsya/thymio/controllers/thymio2_aseba/main.cpp deleted file mode 100644 index 8561e8f7ed2..00000000000 --- a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/main.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 1996-2022 Cyberbotics Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include -#include - -#include "Thymio2AsebaHub.hpp" -#include "Thymio2Model.hpp" - -#include "thymio2_definitions.h" - -#include - -#include // sscanf -#include - -using namespace std; -using namespace webots; - -static void welcomeMessage() { - cout << "Thymio II Aseba server" << endl; - cout << "- Connect Aseba Studio or VPL for Thymio II to this controller through TCP/IP." << endl; - cout << "- Use the Thymio II robot window to access some special events (tap, clap, etc.)." << endl; - cout << "- Change the server port using the Thymio2::controllerArgs field." << endl; -} - -static void usage(const char *command) { - cout << "Usage: " << command << " [port=33333]" << endl; -} - -int main(int argc, char **argv) { - welcomeMessage(); - - Thymio2Model *thymio2 = new Thymio2Model; - - int port = ASEBA_DEFAULT_PORT; - if (argc > 2) { - cerr << "Invalid arguments" << endl; - usage(argv[0]); - } else if (argc == 2) { - if (sscanf(argv[1], "port=%d", &port) != 1) { - cerr << "Invalid arguments" << endl; - usage(argv[0]); - port = ASEBA_DEFAULT_PORT; - } - } - - Thymio2AsebaHub *hub = new Thymio2AsebaHub(port); - - bool events[EVENT_COUNT]; - - while (thymio2->safeStep()) { - hub->step(); - thymio2->sensorToHub(hub); - thymio2->updateEvents(hub, events); - hub->sendEvents(events); - thymio2->hubToActuators(hub); - } - - delete thymio2; - - return EXIT_SUCCESS; -} diff --git a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/thymio2_definitions.c b/projects/robots/mobsya/thymio/controllers/thymio2_aseba/thymio2_definitions.c deleted file mode 100644 index 8e81acc6374..00000000000 --- a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/thymio2_definitions.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 1996-2022 Cyberbotics Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Strongly inspired from https://github.com/aseba-community/aseba-target-thymio2/blob/master/skel-usb-user.c - -#include "thymio2_definitions.h" -#include "thymio2_natives.h" - -const AsebaVMDescription vmDescription = {"thymio-II", - {{1, "_id"}, - {1, "event.source"}, - {VM_VARIABLES_ARG_SIZE, "event.args"}, - {2, "_fwversion"}, - {1, "_productId"}, - - // {5, "buttons._raw"}, - {1, "button.backward"}, - {1, "button.left"}, - {1, "button.center"}, - {1, "button.forward"}, - {1, "button.right"}, - - // {5, "buttons._mean"}, - // {5, "buttons._noise"}, - - {7, "prox.horizontal"}, - - // {7, "prox.comm.rx._payloads"}, - // {7, "prox.comm.rx._intensities"}, - {1, "prox.comm.rx"}, // not implemented - {1, "prox.comm.tx"}, // not implemented - - {2, "prox.ground.ambiant"}, - {2, "prox.ground.reflected"}, - {2, "prox.ground.delta"}, - - {1, "motor.left.target"}, - {1, "motor.right.target"}, - // {2, "_vbat"}, - // {2, "_imot"}, - {1, "motor.left.speed"}, - {1, "motor.right.speed"}, - {1, "motor.left.pwm"}, - {1, "motor.right.pwm"}, - - {3, "acc"}, - - {1, "temperature"}, // not implemented - - {1, "rc5.address"}, // not implemented - {1, "rc5.command"}, // not implemented - - {1, "mic.intensity"}, // not implemented - {1, "mic.threshold"}, // not implemented - {1, "mic._mean"}, // not implemented - - {2, "timer.period"}, - - {1, "acc._tap"}, // not implemented - - {0, NULL}}}; - -const AsebaLocalEventDescription localEvents[] = { - {"button.backward", "Backward button status changed"}, - {"button.left", "Left button status changed"}, - {"button.center", "Center button status changed"}, - {"button.forward", "Forward button status changed"}, - {"button.right", "Right button status changed"}, - {"buttons", "Buttons values updated"}, - {"prox", "Proximity values updated"}, - {"prox.comm", "Data received on the proximity communication"}, // not implemented - {"tap", "A tap is detected"}, // not implemented - {"acc", "Accelerometer values updated"}, - {"mic", "Fired when microphone intensity is above threshold"}, // not implemented - {"sound.finished", "Fired when the playback of a user initiated sound is finished"}, // not implemented - {"temperature", "Temperature value updated"}, // not implemented - {"rc5", "RC5 message received"}, // not implemented - {"motor", "Motor timer"}, - {"timer0", "Timer 0"}, - {"timer1", "Timer 1"}, - {NULL, NULL}}; - -const AsebaNativeFunctionDescription *nativeFunctionsDescriptions[] = {&AsebaNativeDescription__system_reboot, - &AsebaNativeDescription__system_settings_read, - &AsebaNativeDescription__system_settings_write, - &AsebaNativeDescription__system_settings_flash, - - ASEBA_NATIVES_STD_DESCRIPTIONS, - - THYMIO_NATIVES_DESCRIPTIONS, - - &AsebaNativeDescription_poweroff, - 0}; - -AsebaNativeFunctionPointer nativeFunctions[] = {AsebaNative__system_reboot, - AsebaNative__system_settings_read, - AsebaNative__system_settings_write, - AsebaNative__system_settings_flash, - - ASEBA_NATIVES_STD_FUNCTIONS, - - THYMIO_NATIVES_FUNCTIONS, - - power_off}; diff --git a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/thymio2_definitions.h b/projects/robots/mobsya/thymio/controllers/thymio2_aseba/thymio2_definitions.h deleted file mode 100644 index 37ddaa25a1e..00000000000 --- a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/thymio2_definitions.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 1996-2022 Cyberbotics Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Strongly inspired from https://github.com/aseba-community/aseba-target-thymio2/blob/master/skel-usb-user.h - -#ifndef SKEL_USB_USER_H -#define SKEL_USB_USER_H - -#include - -#define PRODUCT_ID 8 -#define VM_VARIABLES_FREE_SPACE 512 -#define VM_VARIABLES_ARG_SIZE 32 - -struct _vmVariables { - short int id; - short int source; - short int args[VM_VARIABLES_ARG_SIZE]; - short int fwversion[2]; - short int productid; - - // short int buttons[5]; - - short int buttons_state[5]; - // short int buttons_mean[5]; - // short int buttons_noise[5]; - - short int prox[7]; - - // short int sensor_data[7]; - // short int intensity[7]; - short int rx_data; // not implemented - short int ir_tx_data; // not implemented - - short int ground_ambiant[2]; - short int ground_reflected[2]; - short int ground_delta[2]; - - short int target[2]; - // short int vbat[2]; - // short int imot[2]; - short int uind[2]; - short int pwm[2]; - - short int acc[3]; - - short int ntc; // not implemented - - short int rc5_address; // not implemented - short int rc5_command; // not implemented - - short int sound_level; // not implemented - short int sound_tresh; // not implemented - short int sound_mean; // not implemented - - short int timers[2]; - - short int acc_tap; // not implemented - - short int freeSpace[VM_VARIABLES_FREE_SPACE]; -}; - -enum Event { - EVENT_B_BACKWARD = 0, - EVENT_B_LEFT, - EVENT_B_CENTER, - EVENT_B_FORWARD, - EVENT_B_RIGHT, - EVENT_BUTTONS, - EVENT_PROX, - EVENT_DATA, // not implemented - EVENT_TAP, - EVENT_ACC, - EVENT_MIC, - EVENT_SOUND_FINISHED, // not implemented - EVENT_TEMPERATURE, // not implemented - EVENT_RC5, // not implemented - EVENT_MOTOR, - EVENT_TIMER0, - EVENT_TIMER1, - EVENT_COUNT -}; - -#endif diff --git a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/thymio2_natives.c b/projects/robots/mobsya/thymio/controllers/thymio2_aseba/thymio2_natives.c deleted file mode 100644 index 599bcf26938..00000000000 --- a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/thymio2_natives.c +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright 1996-2022 Cyberbotics Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Strongly inspired from https://github.com/aseba-community/aseba-target-thymio2/blob/master/thymio_natives.c -// and https://github.com/aseba-community/aseba-target-thymio2/blob/master/skel-usb.c - -#include "thymio2_natives.h" - -AsebaNativeFunctionDescription AsebaNativeDescription_poweroff = {"_poweroff", "Poweroff", {{0, 0}}}; - -void power_off(AsebaVMState *vm) { -} - -AsebaNativeFunctionDescription AsebaNativeDescription__system_reboot = {"_system.reboot", - "Reboot the microcontroller", - {{0, 0}}}; - -void AsebaNative__system_reboot(AsebaVMState *vm) { -} - -AsebaNativeFunctionDescription AsebaNativeDescription__system_settings_read = {"_system.settings.read", - "Read a setting", - {{1, "address"}, {1, "value"}, {0, 0}}}; - -void AsebaNative__system_settings_read(AsebaVMState *vm) { - /*uint16 address = vm->variables[*/ AsebaNativePopArg(vm) /*]*/; - /*uint16 destidx =*/AsebaNativePopArg(vm); -} - -AsebaNativeFunctionDescription AsebaNativeDescription__system_settings_write = {"_system.settings.write", - "Write a setting", - {{1, "address"}, {1, "value"}, {0, 0}}}; - -void AsebaNative__system_settings_write(AsebaVMState *vm) { - /*uint16 address = vm->variables[*/ AsebaNativePopArg(vm) /*]*/; - /*uint16 sourceidx =*/AsebaNativePopArg(vm); -} - -AsebaNativeFunctionDescription AsebaNativeDescription__system_settings_flash = {"_system.settings.flash", - "Write the settings into flash", - {{0, 0}}}; - -void AsebaNative__system_settings_flash(AsebaVMState *vm) { -} - -AsebaNativeFunctionDescription AsebaNativeDescription_set_led = {"_leds.set", - "Set the led", - {{1, "led"}, {1, "brightness"}, {0, 0}}}; - -AsebaNativeFunctionDescription AsebaNativeDescription_record = {"sound.record", - "Start recording of rN.wav", - { - {1, "N"}, - {0, 0}, - }}; - -AsebaNativeFunctionDescription AsebaNativeDescription_play = {"sound.play", - "Start playback of pN.wav", - { - {1, "N"}, - {0, 0}, - }}; - -AsebaNativeFunctionDescription AsebaNativeDescription_replay = {"sound.replay", - "Start playback of rN.wav", - { - {1, "N"}, - {0, 0}, - }}; - -AsebaNativeFunctionDescription AsebaNativeDescription_sound_system = {"sound.system", - "Start playback of system sound N", - { - {1, "N"}, - {0, 0}, - }}; - -void sound_playback(AsebaVMState *vm) { - /*int number = vm->variables[*/ AsebaNativePopArg(vm) /*]*/; -} - -void sound_record(AsebaVMState *vm) { - /*int number = vm->variables[*/ AsebaNativePopArg(vm) /*]*/; -} - -void sound_replay(AsebaVMState *vm) { - /*int number = vm->variables[*/ AsebaNativePopArg(vm) /*]*/; -} - -void sound_system(AsebaVMState *vm) { - /*int number = vm->variables[*/ AsebaNativePopArg(vm) /*]*/; -} - -AsebaNativeFunctionDescription AsebaNativeDescription_set_led_circle = {"leds.circle", - "Set circular ring leds", - { - {1, "l0"}, - {1, "l1"}, - {1, "l2"}, - {1, "l3"}, - {1, "l4"}, - {1, "l5"}, - {1, "l6"}, - {1, "l7"}, - {0, 0}, - }}; - -AsebaNativeFunctionDescription AsebaNativeDescription_set_led_rgb_top = {"leds.top", - "Set RGB top led", - { - {1, "red"}, - {1, "green"}, - {1, "blue"}, - {0, 0}, - }}; - -AsebaNativeFunctionDescription AsebaNativeDescription_set_led_rgb_br = {"leds.bottom.right", - "Set RGB botom right led", - { - {1, "red"}, - {1, "green"}, - {1, "blue"}, - {0, 0}, - }}; - -AsebaNativeFunctionDescription AsebaNativeDescription_set_led_rgb_bl = {"leds.bottom.left", - "Set RGB botom left led", - { - {1, "red"}, - {1, "green"}, - {1, "blue"}, - {0, 0}, - }}; - -AsebaNativeFunctionDescription AsebaNativeDescription_set_led_buttons = {"leds.buttons", - "Set buttons leds", - { - {1, "l0"}, - {1, "l1"}, - {1, "l2"}, - {1, "l3"}, - {0, 0}, - }}; - -AsebaNativeFunctionDescription AsebaNativeDescription_set_hprox_leds = {"leds.prox.h", - "Set horizontal proximity leds", - { - {1, "l0"}, - {1, "l1"}, - {1, "l2"}, - {1, "l3"}, - {1, "l4"}, - {1, "l5"}, - {1, "l6"}, - {1, "l7"}, - {0, 0}, - }}; - -AsebaNativeFunctionDescription AsebaNativeDescription_set_vprox_leds = {"leds.prox.v", - "Set vertical proximity leds", - { - {1, "l0"}, - {1, "l1"}, - {0, 0}, - }}; - -AsebaNativeFunctionDescription AsebaNativeDescription_set_rc_leds = {"leds.rc", - "Set rc led", - { - {1, "led"}, - {0, 0}, - }}; - -AsebaNativeFunctionDescription AsebaNativeDescription_set_sound_leds = {"leds.sound", - "Set sound led", - { - {1, "led"}, - {0, 0}, - }}; - -AsebaNativeFunctionDescription AsebaNativeDescription_set_ntc_leds = {"leds.temperature", - "Set ntc led", - { - {1, "red"}, - {1, "blue"}, - {0, 0}, - }}; - -AsebaNativeFunctionDescription AsebaNativeDescription_play_freq = {"sound.freq", - "Play frequency", - { - {1, "Hz"}, - {1, "ds"}, - {0, 0}, - }}; - -void play_freq(AsebaVMState *vm) { - /*int freq = vm->variables[*/ AsebaNativePopArg(vm) /*]*/; - /*int time = vm->variables[*/ AsebaNativePopArg(vm) /*]*/; -} - -#define WAVEFORM_SIZE 142 -AsebaNativeFunctionDescription AsebaNativeDescription_set_wave = {"sound.wave", - "Set the primary wave of the tone generator", - { - {WAVEFORM_SIZE, "wave"}, - {0, 0}, - }}; - -void set_wave(AsebaVMState *vm) { - /*int *wave = (int *) vm->variables + */ AsebaNativePopArg(vm); -} - -AsebaNativeFunctionDescription AsebaNativeDescription_prox_network = {"prox.comm.enable", - "Enable or disable the proximity communication", - { - {1, "state"}, - {0, 0}, - }}; - -void prox_network(AsebaVMState *vm) { - /*int enable = vm->variables[*/ AsebaNativePopArg(vm) /*]*/; -} - -AsebaNativeFunctionDescription AsebaNativeDescription_sd_open = {"sd.open", - "Open a file on the SD card", - { - {1, "number"}, - {1, "status"}, - {0, 0}, - }}; - -void thymio_native_sd_open(AsebaVMState *vm) { - /*int no = vm->variables[*/ AsebaNativePopArg(vm) /*]*/; - /*unsigned int status = */ AsebaNativePopArg(vm); -} - -AsebaNativeFunctionDescription AsebaNativeDescription_sd_write = {"sd.write", - "Write data to the opened file", - { - {-1, "data"}, - {1, "written"}, - {0, 0}, - }}; - -void thymio_native_sd_write(AsebaVMState *vm) { - /*unsigned char * data = (unsigned char *) (vm->variables + */ AsebaNativePopArg(vm) /*)*/; - /*uint16 status = */ AsebaNativePopArg(vm); - /*uint16 length = */ AsebaNativePopArg(vm) /* * 2*/; -} - -AsebaNativeFunctionDescription AsebaNativeDescription_sd_read = {"sd.read", - "Read data from the opened file", - { - {-1, "data"}, - {1, "read"}, - {0, 0}, - }}; - -void thymio_native_sd_read(AsebaVMState *vm) { - /*unsigned char * data = (unsigned char *) (vm->variables + */ AsebaNativePopArg(vm) /*)*/; - /*uint16 status =*/AsebaNativePopArg(vm); - /*uint16 length =*/AsebaNativePopArg(vm) /* * 2*/; -} - -AsebaNativeFunctionDescription AsebaNativeDescription_sd_seek = {"sd.seek", - "Seek the opened file", - { - {1, "position"}, - {1, "status"}, - {0, 0}, - }}; - -void thymio_native_sd_seek(AsebaVMState *vm) { - /*unsigned long seek = vm->variables[*/ AsebaNativePopArg(vm) /*]*/; - /*unsigned int status = */ AsebaNativePopArg(vm); -} diff --git a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/thymio2_natives.h b/projects/robots/mobsya/thymio/controllers/thymio2_aseba/thymio2_natives.h deleted file mode 100644 index ce2d2f2fbeb..00000000000 --- a/projects/robots/mobsya/thymio/controllers/thymio2_aseba/thymio2_natives.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 1996-2022 Cyberbotics Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Strongly inspired from https://github.com/aseba-community/aseba-target-thymio2/blob/master/thymio_natives.h - -#ifndef THYMIO2_NATIVES_H -#define THYMIO2_NATIVES_H - -#include - -extern AsebaNativeFunctionDescription AsebaNativeDescription_poweroff; -void power_off(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription__system_reboot; -void AsebaNative__system_reboot(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription__system_settings_read; -void AsebaNative__system_settings_read(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription__system_settings_write; -void AsebaNative__system_settings_write(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription__system_settings_flash; -void AsebaNative__system_settings_flash(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_set_led; -void set_led(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_record; -void sound_record(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_play; -void sound_playback(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_replay; -void sound_replay(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_sound_system; -void sound_system(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_set_led_circle; -void set_led_circle(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_set_led_rgb_top; -void set_rgb_top(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_set_led_rgb_bl; -void set_rgb_bl(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_set_led_rgb_br; -void set_rgb_br(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_play_freq; -void play_freq(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_set_led_buttons; -void set_buttons_leds(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_set_hprox_leds; -void set_hprox_leds(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_set_vprox_leds; -void set_vprox_leds(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_set_rc_leds; -void set_rc_leds(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_set_sound_leds; -void set_sound_leds(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_set_ntc_leds; -void set_ntc_leds(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_set_wave; -void set_wave(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_prox_network; -void prox_network(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_sd_open; -void thymio_native_sd_open(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_sd_write; -void thymio_native_sd_write(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_sd_read; -void thymio_native_sd_read(AsebaVMState *vm); - -extern AsebaNativeFunctionDescription AsebaNativeDescription_sd_seek; -void thymio_native_sd_seek(AsebaVMState *vm); - -#define THYMIO_NATIVES_DESCRIPTIONS \ - &AsebaNativeDescription_set_led, &AsebaNativeDescription_record, &AsebaNativeDescription_play, \ - &AsebaNativeDescription_replay, &AsebaNativeDescription_sound_system, &AsebaNativeDescription_set_led_circle, \ - &AsebaNativeDescription_set_led_rgb_top, &AsebaNativeDescription_set_led_rgb_bl, &AsebaNativeDescription_set_led_rgb_br, \ - &AsebaNativeDescription_play_freq, &AsebaNativeDescription_set_led_buttons, &AsebaNativeDescription_set_hprox_leds, \ - &AsebaNativeDescription_set_vprox_leds, &AsebaNativeDescription_set_rc_leds, &AsebaNativeDescription_set_sound_leds, \ - &AsebaNativeDescription_set_ntc_leds, &AsebaNativeDescription_set_wave, &AsebaNativeDescription_prox_network, \ - &AsebaNativeDescription_sd_open, &AsebaNativeDescription_sd_write, &AsebaNativeDescription_sd_read, \ - &AsebaNativeDescription_sd_seek - -#define THYMIO_NATIVES_FUNCTIONS \ - set_led, sound_record, sound_playback, sound_replay, sound_system, set_led_circle, set_rgb_top, set_rgb_bl, set_rgb_br, \ - play_freq, set_buttons_leds, set_hprox_leds, set_vprox_leds, set_rc_leds, set_sound_leds, set_ntc_leds, set_wave, \ - prox_network, thymio_native_sd_open, thymio_native_sd_write, thymio_native_sd_read, thymio_native_sd_seek - -#endif diff --git a/projects/robots/mobsya/thymio/libraries/.gitignore b/projects/robots/mobsya/thymio/libraries/.gitignore deleted file mode 100644 index 4bcd9a2732d..00000000000 --- a/projects/robots/mobsya/thymio/libraries/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/dashel diff --git a/projects/robots/mobsya/thymio/libraries/Makefile b/projects/robots/mobsya/thymio/libraries/Makefile deleted file mode 100644 index 1252ade1217..00000000000 --- a/projects/robots/mobsya/thymio/libraries/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 1996-2022 Cyberbotics Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -null := -space := $(null) $(null) -WEBOTS_HOME_PATH?=$(subst $(space),\ ,$(strip $(subst \,/,$(WEBOTS_HOME)))) -include $(WEBOTS_HOME_PATH)/resources/Makefile.os.include - -ifeq ($(OSTYPE),windows) -CMAKE_FLAGS = -G "MSYS Makefiles" -endif - -ifeq ($(OSTYPE),linux) -unexport LD_LIBRARY_PATH -endif - -release debug profile: -ifneq (, $(shell which cmake 2> /dev/null)) - @mkdir -p dashel/dashel - @cmake -Bdashel -Hdashel-src $(CMAKE_FLAGS) > /dev/null - @cp dashel-src/dashel/dashel.h dashel/dashel/ - @+make -C dashel > /dev/null -else - @echo -e "# \033[0;33mcmake not installed, skipping dashel library\033[0m" -endif - -clean: - @rm -fr dashel diff --git a/projects/robots/mobsya/thymio/libraries/dashel-src b/projects/robots/mobsya/thymio/libraries/dashel-src deleted file mode 160000 index 1a8d36e7fe4..00000000000 --- a/projects/robots/mobsya/thymio/libraries/dashel-src +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1a8d36e7fe48ce0f4fd292f5b64b2a0a880953da diff --git a/projects/robots/mobsya/thymio/protos/Thymio2.proto b/projects/robots/mobsya/thymio/protos/Thymio2.proto index df0c34549c9..399a1692c96 100644 --- a/projects/robots/mobsya/thymio/protos/Thymio2.proto +++ b/projects/robots/mobsya/thymio/protos/Thymio2.proto @@ -13,18 +13,18 @@ EXTERNPROTO "Thymio2DistanceSensor.proto" EXTERNPROTO "Thymio2LED.proto" PROTO Thymio2 [ - field SFVec3f translation 0 0 0 # Is `Transform.translation`. - field SFRotation rotation 0 0 1 0 # Is `Transform.rotation`. - field SFString name "Thymio II" # Is `Solid.name`. - field SFString controller "thymio2_aseba" # Is `Robot.controller`. - field MFString controllerArgs "port=33333" # Is `Robot.controllerArgs`. - field SFString window "" # Is `Robot.window`. - field SFString customData "" # Is `Robot.customData`. - field SFBool supervisor FALSE # Is `Robot.supervisor`. - field SFBool synchronization TRUE # Is `Robot.synchronization`. - field SFString contactMaterial "thymio body" # Defines the `Solid.contactMaterial` for the body. - field SFBool castLight TRUE # Defines whether OpenGL lights are cerated for each LEDs. - field MFNode bodySlot [] # Extends the robot with new nodes in the body slot. + field SFVec3f translation 0 0 0 # Is `Transform.translation`. + field SFRotation rotation 0 0 1 0 # Is `Transform.rotation`. + field SFString name "Thymio II" # Is `Solid.name`. + field SFString controller "thymio2_demo" # Is `Robot.controller`. + field MFString controllerArgs [] # Is `Robot.controllerArgs`. + field SFString window "" # Is `Robot.window`. + field SFString customData "" # Is `Robot.customData`. + field SFBool supervisor FALSE # Is `Robot.supervisor`. + field SFBool synchronization TRUE # Is `Robot.synchronization`. + field SFString contactMaterial "thymio body" # Defines the `Solid.contactMaterial` for the body. + field SFBool castLight TRUE # Defines whether OpenGL lights are cerated for each LEDs. + field MFNode bodySlot [] # Extends the robot with new nodes in the body slot. ] { Robot { diff --git a/projects/robots/robotis/darwin-op/plugins/robot_windows/Makefile b/projects/robots/robotis/darwin-op/plugins/robot_windows/Makefile index 3a2e35e3e87..4d43d141c76 100644 --- a/projects/robots/robotis/darwin-op/plugins/robot_windows/Makefile +++ b/projects/robots/robotis/darwin-op/plugins/robot_windows/Makefile @@ -36,10 +36,10 @@ release debug profile clean: $(TARGETS) %.Makefile: ifeq ($(NO_LIBSSH),1) - +@echo -e "# \033[0;33mlibssh not installed, skipping Robotis OP2 robot window\033[0m" + +@$(ECHO) "# \033[0;33mlibssh not installed, skipping Robotis OP2 robot window\033[0m" else ifeq ($(NO_LIBZIP),1) - +@echo -e "# \033[0;33mlibzip not installed, skipping Robotis OP2 robot window\033[0m" + +@$(ECHO) "# \033[0;33mlibzip not installed, skipping Robotis OP2 robot window\033[0m" else +@echo "# make" $(MAKECMDGOALS) $(@:.Makefile=) +@make -s -C $(@:.Makefile=) $(MAKECMDGOALS) diff --git a/projects/robots/robotis/darwin-op/plugins/robot_windows/robotis-op2_window/Makefile b/projects/robots/robotis/darwin-op/plugins/robot_windows/robotis-op2_window/Makefile index 03a69e72070..bf96fa1b4b4 100644 --- a/projects/robots/robotis/darwin-op/plugins/robot_windows/robotis-op2_window/Makefile +++ b/projects/robots/robotis/darwin-op/plugins/robot_windows/robotis-op2_window/Makefile @@ -41,6 +41,7 @@ ifeq ($(OSTYPE),darwin) LIBRARIES += -L"$(WEBOTS_HOME)/projects/robots/robotis/darwin-op/libraries/libzip" -lnihzip -L"$(WEBOTS_HOME)/projects/robots/robotis/darwin-op/libraries/libssh" -lssh INCLUDE += -I"$(WEBOTS_HOME)/projects/robots/robotis/darwin-op/libraries/libzip/include/libzip" -I"$(WEBOTS_HOME)/projects/robots/robotis/darwin-op/libraries/libssh/include/libssh" NO_FAT_BINARY = 1 +PROCESSOR = x86_64 endif ifeq ($(OSTYPE),linux) @@ -79,6 +80,7 @@ ifeq ($(OSTYPE),darwin) INCLUDE += -F"$(FRAMEWORKS_DIR)" FRAMEWORKS += -F"$(FRAMEWORKS_DIR)" DYNAMIC_LIBRARIES += -bind_at_load $(FRAMEWORKS) + LD_FLAGS = -target $(PROCESSOR)-apple-macos11 MOC = "$(WEBOTS_HOME)/bin/qt/moc" MOC_PLATFORM_FLAGS = -D__APPLE__ FRAMEWORKS += -framework QtCore -framework QtGui -framework QtWidgets -framework QtConcurrent diff --git a/projects/vehicles/controllers/ros_automobile/Makefile b/projects/vehicles/controllers/ros_automobile/Makefile index f3bca867be0..c7d7d163c1f 100644 --- a/projects/vehicles/controllers/ros_automobile/Makefile +++ b/projects/vehicles/controllers/ros_automobile/Makefile @@ -30,11 +30,11 @@ endif PYTHON_COMMAND ?= python3 ifeq (, $(ROS_DISTRO)) release debug profile clean: - @echo "# \033[0;33mROS not installed or 'ROS_DISTRO' not defined\033[0m" + @$(ECHO) "# \033[0;33mROS not installed or 'ROS_DISTRO' not defined\033[0m" else ifeq (2, $(ROS_VERSION)) release debug profile clean: - @echo "# \033[0;33mROS_DISTRO should not be a ROS2 distribution\033[0m" + @$(ECHO) "# \033[0;33mROS_DISTRO should not be a ROS2 distribution\033[0m" else CXX_SOURCES = $(wildcard *.cpp) CXX_SOURCES += $(wildcard $(WEBOTS_HOME_PATH)/projects/default/controllers/ros/Ros*.cpp) diff --git a/projects/vehicles/plugins/robot_windows/automobile_window/Makefile b/projects/vehicles/plugins/robot_windows/automobile_window/Makefile index 022a6b2e4ce..3421d073f37 100644 --- a/projects/vehicles/plugins/robot_windows/automobile_window/Makefile +++ b/projects/vehicles/plugins/robot_windows/automobile_window/Makefile @@ -27,6 +27,7 @@ HPP_FILES_TO_MOC = GeneralInformationWidget.hpp AbstractWidget.hpp USE_C_API = true NO_FAT_BINARY = 1 +PROCESSOR = x86_64 QT_UTILS = $(WEBOTS_HOME)/resources/projects/libraries/qt_utils INCLUDE = -I"$(QT_UTILS)" LIBRARIES = -L"$(QT_UTILS)" -lqt_utils -ldriver -lcar @@ -59,10 +60,11 @@ ifeq ($(OSTYPE),linux) endif ifeq ($(OSTYPE),darwin) - WBCFLAGS += -Wno-unknown-pragmas + WBCFLAGS += -Wno-unknown-pragmas -target $(PROCESSOR)-apple-macos11 FRAMEWORKS_DIR = $(WEBOTS_HOME)/Contents/Frameworks INCLUDE += -F"$(FRAMEWORKS_DIR)" FRAMEWORKS += -F"$(FRAMEWORKS_DIR)" + LD_FLAGS = -target $(PROCESSOR)-apple-macos11 DYNAMIC_LIBRARIES += -bind_at_load $(FRAMEWORKS) MOC = "$(WEBOTS_HOME)/bin/qt/moc" MOC_PLATFORM_FLAGS = -D__APPLE__ diff --git a/resources/Makefile.include b/resources/Makefile.include index e20bd5c0cc4..1d10d985bde 100644 --- a/resources/Makefile.include +++ b/resources/Makefile.include @@ -320,6 +320,10 @@ ifeq ($(OSTYPE),linux) endif ifeq ($(OSTYPE),darwin) +ifdef NO_FAT_BINARY + WBCFLAGS += -target $(PROCESSOR)-apple-macos11 + DYNAMIC_LINK_FLAGS += -target $(PROCESSOR)-apple-macos11 +endif WBCFLAGS += -mmacosx-version-min=$(MACOSX_MIN_SDK_VERSION) DYNAMIC_LINK_FLAGS += -mmacosx-version-min=$(MACOSX_MIN_SDK_VERSION) endif @@ -511,7 +515,7 @@ ifdef VS_DEF_NAME mv out.lib $(MAIN_TARGET_WINDOWS64_LIB); \ rm -f *.exp; \ else \ - echo "'VISUAL_STUDIO_PATH' environmental variable not set or Microsoft Visual Studio not installed, skipping $(NAME).lib"; \ + $(ECHO) "\033[0;33m'VISUAL_STUDIO_PATH' environmental variable not set or Microsoft Visual Studio not installed, skipping $(NAME).lib\033[0m"; \ fi \ fi endif @@ -533,7 +537,7 @@ ifdef VS_DEF_NAME mv out.lib $(MAIN_TARGET_WINDOWS64_LIB); \ rm -f *.exp; \ else \ - echo "'VISUAL_STUDIO_PATH' environmental variable not set or Microsoft Visual Studio not installed, skipping $(NAME).lib"; \ + $(ECHO) "\033[0;33m'VISUAL_STUDIO_PATH' environmental variable not set or Microsoft Visual Studio not installed, skipping $(NAME).lib\033[0m"; \ fi \ fi endif @@ -551,12 +555,10 @@ ARM64_OBJECTS = $(addprefix $(BUILD_GOAL_DIR)/arm64/, $(OBJECTS_LIST)) $(BUILD_GOAL_DIR)/$(MAIN_TARGET): $(BUILD_GOAL_DIR)/x86_64/$(MAIN_TARGET) $(BUILD_GOAL_DIR)/arm64/$(MAIN_TARGET) @echo "# creating fat" $(notdir $@) $(SILENT)lipo -create -output $@ $(BUILD_GOAL_DIR)/x86_64/$(MAIN_TARGET) $(BUILD_GOAL_DIR)/arm64/$(MAIN_TARGET) - $(SILENT)codesign -s - $@ $(TARGET_LIB_DIR)/$(MAIN_TARGET): $(BUILD_GOAL_DIR)/x86_64/$(MAIN_TARGET) $(BUILD_GOAL_DIR)/arm64/$(MAIN_TARGET) @echo "# creating fat" $(notdir $@) $(SILENT)lipo -create -output $@ $(BUILD_GOAL_DIR)/x86_64/$(MAIN_TARGET) $(BUILD_GOAL_DIR)/arm64/$(MAIN_TARGET) - $(SILENT)codesign -s - $@ $(BUILD_GOAL_DIR)/x86_64/$(MAIN_TARGET): $(X86_64_OBJECTS) $(LINK_DEPENDENCIES) @echo "# linking" $(notdir $@) "(x86_64)" diff --git a/resources/Makefile.java.include b/resources/Makefile.java.include index 1433ec3db62..9f3f0166a05 100644 --- a/resources/Makefile.java.include +++ b/resources/Makefile.java.include @@ -101,10 +101,10 @@ endif ifeq ($(JAVA_HOME),) release debug profile: - @echo -e "# \033[0;33mJava not installed or 'JAVA_HOME' not set, skipping Java API\033[0m" + @$(ECHO) "# \033[0;33mJava not installed or 'JAVA_HOME' not set, skipping Java API\033[0m" else ifeq (,$(wildcard $(WEBOTS_JAVA_LIB))) release debug profile: - @echo -e "# \033[0;33mJava library not compiled, skipping Java API\033[0m" + @$(ECHO) "# \033[0;33mJava library not compiled, skipping Java API\033[0m" else release debug profile: @javac $(JAVAC_OPTS) *.java diff --git a/resources/Makefile.os.include b/resources/Makefile.os.include index 31adaeb7c98..35d05e89c70 100644 --- a/resources/Makefile.os.include +++ b/resources/Makefile.os.include @@ -19,7 +19,7 @@ ifeq ($(OS),Windows_NT) endif ifndef OSTYPE - OSTYPE = $(shell uname) + OSTYPE := $(shell uname) endif ifeq ($(OSTYPE),Linux) @@ -74,7 +74,7 @@ ifeq ($(OSTYPE),darwin) SUPPORTED_SDK = 11 12 MACOSX_MIN_SDK_VERSION = 11 - + ECHO = echo # cf. https://stackoverflow.com/a/30225756/2210777 MACOSX_SDK_PATH = $(shell xcrun --sdk macosx --show-sdk-path) ifeq ($(wildcard $(MACOSX_SDK_PATH)),) @@ -85,6 +85,8 @@ ifeq ($(OSTYPE),darwin) ## Only recent SDKs are working, but this doesn't prevent to use others. $(warning Your macOS SDK ("$(MACOSX_SDK_PATH)") is $(MACOSX_SDK_VERSION) while Webots supports the $(SUPPORTED_SDK) SDKs.) endif +else + ECHO = echo -e endif # extensions and prefixes diff --git a/scripts/install/bash_profile.mac b/scripts/install/bash_profile.mac index b4548c0470f..afd0b3779fe 100644 --- a/scripts/install/bash_profile.mac +++ b/scripts/install/bash_profile.mac @@ -18,4 +18,4 @@ export WEBOTS_ALLOW_MODIFY_INSTALLATION=1 # If defined, you are ######################################################################### export WEBOTS_HOME=$HOME/webots # Defines the path to Webots home. -export WEBOTS_HOME_PATH=$WEBOTS_HOME/Contents # Defines the path to Webots home Contents folder (used for finding include files when compiling from a terminal). +export JAVA_HOME="$(/usr/libexec/java_home)" diff --git a/scripts/packaging/files_core.txt b/scripts/packaging/files_core.txt index a6dba9c6794..081ed160f46 100644 --- a/scripts/packaging/files_core.txt +++ b/scripts/packaging/files_core.txt @@ -87,6 +87,8 @@ lib/controller/generic_robot_window [dll,windows,linux] lib/controller/python/ [windows,linux] lib/controller/python/controller/ [windows,linux] lib/controller/python/controller/*.py [windows,linux] +lib/controller/python/vehicle/ [windows,linux] +lib/controller/python/vehicle/*.py [windows,linux] lib/controller/matlab/ [windows,linux] lib/controller/matlab/allincludes.h [windows,linux] @@ -322,6 +324,8 @@ Contents/lib/controller/generic_robot_window [dll,mac] Contents/lib/controller/python/ [mac] Contents/lib/controller/python/controller/ [mac] Contents/lib/controller/python/controller/*.py [mac] +Contents/lib/controller/python/vehicle/ [mac] +Contents/lib/controller/python/vehicle/*.py [mac] Contents/lib/controller/matlab/ [mac] Contents/lib/controller/matlab/allincludes.h [mac] diff --git a/scripts/packaging/generate_asset_cache.py b/scripts/packaging/generate_asset_cache.py index 82e983a16e3..fb7370e99ba 100644 --- a/scripts/packaging/generate_asset_cache.py +++ b/scripts/packaging/generate_asset_cache.py @@ -27,7 +27,7 @@ ] SKIPPED_DIRECTORIES = [ - '/robot_windows/', '/thymio2_aseba/' + '/robot_windows/' ] # ensure WEBOTS_HOME is set and tag was provided diff --git a/scripts/packaging/mac_distro.py b/scripts/packaging/mac_distro.py index 23d3fa02f24..29d3780dddf 100644 --- a/scripts/packaging/mac_distro.py +++ b/scripts/packaging/mac_distro.py @@ -43,7 +43,7 @@ def check_rpath(home_path): frameworkFiles[i] = re.sub(r"^/", "", frameworkFiles[i]) controllerFiles = command('find projects resources -name controllers | ' 'xargs -I{} find {} -maxdepth 1 -mindepth 1 -type d | ' - 'grep -v ros | grep -v thymio2_aseba | ' + 'grep -v ros | ' 'sed -e "s:\\(.*\\)/\\([^/]*\\):\\1/\\2/\\2:" | ' 'perl -ne \'chomp(); if (-e $_) {print "$_\n"}\' ').split() binaryFiles = [ @@ -69,6 +69,8 @@ def check_rpath(home_path): dependencies = command('otool -L ' + f + ' | grep -v ' + f + ': | sed -e "s: (compatibility.*::" | ' 'sed -e "s:^[ \t]*::"').split('\n') for d in dependencies: + if d.startswith(f + ' ('): + continue if (not d.startswith('/') and not d.startswith('@rpath/')) or 'local' in d: success = False sys.stderr.write('Dependency error:\n') diff --git a/scripts/packaging/recurse_in_projects.txt b/scripts/packaging/recurse_in_projects.txt index 54f83e2a0db..2a3767b15a4 100644 --- a/scripts/packaging/recurse_in_projects.txt +++ b/scripts/packaging/recurse_in_projects.txt @@ -1,3 +1,2 @@ projects/default/resources/sumo projects/robots/gctronic/e-puck/transfer/xc16 -projects/robots/mobsya/thymio/controllers/thymio2_aseba/aseba diff --git a/src/controller/c/Makefile b/src/controller/c/Makefile index abb926774f6..739e820503d 100644 --- a/src/controller/c/Makefile +++ b/src/controller/c/Makefile @@ -127,7 +127,7 @@ $(WEBOTS_CONTROLLER_LIB_PATH)/Controller.dll: $(MINGW64_OBJECTS) Controller.def $(WEBOTS_CONTROLLER_LIB_PATH)/Controller.lib: $(WEBOTS_CONTROLLER_LIB_PATH)/Controller.dll Controller.def ifeq ($(VISUAL_STUDIO_PATH),) - @echo -e "# \033[0;33m'VISUAL_STUDIO_PATH' not set, skipping Controller.lib\033[0m" + @$(ECHO) "# \033[0;33m'VISUAL_STUDIO_PATH' not set, skipping Controller.lib\033[0m" else @echo "# creating "$@ @PATH="$(VISUAL_STUDIO_PATH)/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64":$PATH lib /machine:X64 /def:Controller.def /out:Controller.lib > /dev/null diff --git a/src/controller/java/Makefile b/src/controller/java/Makefile index 8a170bee37b..d35b6048793 100644 --- a/src/controller/java/Makefile +++ b/src/controller/java/Makefile @@ -133,10 +133,10 @@ endif # rules ifeq ($(SWIG_EXISTS),) release debug profile: - @echo -e "# \033[0;33mSWIG not installed, skipping Java API\033[0m" + @$(ECHO) "# \033[0;33mSWIG not installed, skipping Java API\033[0m" else ifeq ($(JAVA_HOME),) release debug profile: - @echo -e "# \033[0;33mJava not installed or 'JAVA_HOME' not set, skipping Java API\033[0m" + @$(ECHO) "# \033[0;33mJava not installed or 'JAVA_HOME' not set, skipping Java API\033[0m" else release debug profile: $(JAR_FILE) $(TARGET) diff --git a/src/controller/matlab/Makefile b/src/controller/matlab/Makefile index a9dc7c36f19..ffc374d6ae4 100644 --- a/src/controller/matlab/Makefile +++ b/src/controller/matlab/Makefile @@ -26,7 +26,7 @@ PYTHON_OK := $(shell which python3) release debug profile: @echo "# generating matlab" ifeq ('$(PYTHON_OK)','') - @echo "# \033[0;33mUnable to find python3, skipping matlab API\033[0m" + @$(ECHO) "# \033[0;33mUnable to find python3, skipping matlab API\033[0m" else $(shell python3 mgenerate.py;) endif