From 255135e29a4ec902f55dfd394e3e0d6dceb3a501 Mon Sep 17 00:00:00 2001 From: MinyazevR <89993880+MinyazevR@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:56:12 +0300 Subject: [PATCH] Add support for Network blocks in the visual language (#1795) 1. The `mailbox` entity has been taken to a higher level for use in visual language 2. Support for `TrikJoinNetwork`, `TrikWaitForMessage`, `TrikSendMessage` blocks in visual language 3. Cut out unnecessary functionality due to the use of the TrikJoinNetwork block --- .../robotModel/robotParts/communicator.h | 41 ++++++++++ plugins/robots/common/kitBase/kitBase.pri | 2 + .../src/robotModel/commonRobotModel.cpp | 7 +- .../robotModel/robotParts/communicator.cpp | 22 ++++++ .../parts/trikNetworkCommunicator.h | 50 ++++++++++++ .../trikKit/robotModel/trikRobotModelBase.h | 1 + .../src/blocks/details/joinNetworkBlock.cpp | 32 ++++++++ .../src/blocks/details/joinNetworkBlock.h | 36 +++++++++ .../src/blocks/details/sendMessageBlock.cpp | 30 +++++++ .../src/blocks/details/sendMessageBlock.h | 36 +++++++++ .../blocks/details/waitForMessageBlock.cpp | 76 ++++++++++++++++++ .../src/blocks/details/waitForMessageBlock.h | 45 +++++++++++ .../src/blocks/trikBlocksFactoryBase.cpp | 9 ++- .../parts/trikNetworkCommunicator.cpp | 22 ++++++ .../src/robotModel/trikRobotModelBase.cpp | 9 +++ plugins/robots/common/trikKit/trikKit.pri | 8 ++ .../robots/editor/trik/generated/elements.h | 4 +- plugins/robots/editor/trik/trikMetamodel.xml | 4 +- .../twoD/parts/twoDNetworkCommunicator.h | 63 +++++++++++++++ .../robotModel/twoD/trikTwoDRobotModel.h | 5 ++ .../trikKitInterpreterPluginBase.h | 4 +- .../trikTextualInterpreter.h | 4 +- .../twoD/parts/twoDNetworkCommunicator.cpp | 78 +++++++++++++++++++ .../robotModel/twoD/trikTwoDRobotModel.cpp | 19 ++++- .../src/trikAdditionalPreferences.cpp | 4 - .../src/trikAdditionalPreferences.ui | 16 +--- .../src/trikKitInterpreter.pri | 2 + .../src/trikKitInterpreterPluginBase.cpp | 13 +++- .../src/trikTextualInterpreter.cpp | 11 +-- .../trikKitInterpreterCommon.pri | 2 + .../fr/plugins/robots/kitBase_fr.ts | 8 ++ .../robots/trikKitInterpreterCommon_fr.ts | 18 +---- .../fr/plugins/robots/trikKit_fr.ts | 12 ++- .../ru/plugins/robots/kitBase_ru.ts | 8 ++ .../robots/trikKitInterpreterCommon_ru.ts | 16 ++-- .../ru/plugins/robots/trikKit_ru.ts | 12 ++- 36 files changed, 655 insertions(+), 74 deletions(-) create mode 100644 plugins/robots/common/kitBase/include/kitBase/robotModel/robotParts/communicator.h create mode 100644 plugins/robots/common/kitBase/src/robotModel/robotParts/communicator.cpp create mode 100644 plugins/robots/common/trikKit/include/trikKit/robotModel/parts/trikNetworkCommunicator.h create mode 100644 plugins/robots/common/trikKit/src/blocks/details/joinNetworkBlock.cpp create mode 100644 plugins/robots/common/trikKit/src/blocks/details/joinNetworkBlock.h create mode 100644 plugins/robots/common/trikKit/src/blocks/details/sendMessageBlock.cpp create mode 100644 plugins/robots/common/trikKit/src/blocks/details/sendMessageBlock.h create mode 100644 plugins/robots/common/trikKit/src/blocks/details/waitForMessageBlock.cpp create mode 100644 plugins/robots/common/trikKit/src/blocks/details/waitForMessageBlock.h create mode 100644 plugins/robots/common/trikKit/src/robotModel/parts/trikNetworkCommunicator.cpp create mode 100644 plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/robotModel/twoD/parts/twoDNetworkCommunicator.h create mode 100644 plugins/robots/interpreters/trikKitInterpreterCommon/src/robotModel/twoD/parts/twoDNetworkCommunicator.cpp diff --git a/plugins/robots/common/kitBase/include/kitBase/robotModel/robotParts/communicator.h b/plugins/robots/common/kitBase/include/kitBase/robotModel/robotParts/communicator.h new file mode 100644 index 0000000000..03e76a86d6 --- /dev/null +++ b/plugins/robots/common/kitBase/include/kitBase/robotModel/robotParts/communicator.h @@ -0,0 +1,41 @@ +/* Copyright 2024 CyberTech Labs 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. */ + +#pragma once + +#include "device.h" +#include "kitBase/kitBaseDeclSpec.h" + +namespace kitBase { +namespace robotModel { +namespace robotParts { + +/// Base class for robot network communication. +class ROBOTS_KIT_BASE_EXPORT Communicator : public Device +{ + Q_OBJECT + Q_CLASSINFO("name", "communicator") + Q_CLASSINFO("friendlyName", tr("Communicator")) + Q_CLASSINFO("direction", "output") + +public: + /// Constructor, takes device type info and port on which this device is configured. + Communicator(const DeviceInfo &info, const PortInfo &port); + + /// Deinitializing a network communicator + virtual void release() = 0; +}; +} +} +} diff --git a/plugins/robots/common/kitBase/kitBase.pri b/plugins/robots/common/kitBase/kitBase.pri index af5d4998e4..dbfb8a730d 100644 --- a/plugins/robots/common/kitBase/kitBase.pri +++ b/plugins/robots/common/kitBase/kitBase.pri @@ -70,6 +70,7 @@ HEADERS += \ $$PWD/include/kitBase/robotModel/robotParts/colorSensorAmbient.h \ $$PWD/include/kitBase/robotModel/robotParts/colorSensorReflected.h \ $$PWD/include/kitBase/robotModel/robotParts/speaker.h \ + $$PWD/include/kitBase/robotModel/robotParts/communicator.h \ $$PWD/include/kitBase/robotModel/robotParts/motor.h \ $$PWD/include/kitBase/robotModel/robotParts/display.h \ $$PWD/include/kitBase/robotModel/robotParts/button.h \ @@ -126,6 +127,7 @@ SOURCES += \ $$PWD/src/robotModel/portInfo.cpp \ $$PWD/src/robotModel/deviceInfo.cpp \ $$PWD/src/robotModel/robotParts/speaker.cpp \ + $$PWD/src/robotModel/robotParts/communicator.cpp \ $$PWD/src/robotModel/robotParts/motor.cpp \ $$PWD/src/robotModel/robotParts/display.cpp \ $$PWD/src/robotModel/robotParts/button.cpp \ diff --git a/plugins/robots/common/kitBase/src/robotModel/commonRobotModel.cpp b/plugins/robots/common/kitBase/src/robotModel/commonRobotModel.cpp index c2f9930e85..fe37692e67 100644 --- a/plugins/robots/common/kitBase/src/robotModel/commonRobotModel.cpp +++ b/plugins/robots/common/kitBase/src/robotModel/commonRobotModel.cpp @@ -21,6 +21,7 @@ #include "kitBase/robotModel/robotParts/motor.h" #include "kitBase/robotModel/robotParts/random.h" +#include "kitBase/robotModel/robotParts/communicator.h" const int updateInterval = 200; @@ -72,10 +73,14 @@ void CommonRobotModel::connectToRobot() void CommonRobotModel::stopRobot() { for (robotParts::Device * const device : mConfiguration.devices()) { - robotParts::Motor * const motor = dynamic_cast(device); + auto* const motor = qobject_cast(device); if (motor) { motor->off(); } + auto* const communicator = qobject_cast(device); + if (communicator) { + communicator->release(); + } } /// @todo: add known deinitialization methods here (for example sensors termination after extending their inteface) } diff --git a/plugins/robots/common/kitBase/src/robotModel/robotParts/communicator.cpp b/plugins/robots/common/kitBase/src/robotModel/robotParts/communicator.cpp new file mode 100644 index 0000000000..18439bc1a1 --- /dev/null +++ b/plugins/robots/common/kitBase/src/robotModel/robotParts/communicator.cpp @@ -0,0 +1,22 @@ +/* Copyright 2024 CyberTech Labs 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 "kitBase/robotModel/robotParts/communicator.h" + +using namespace kitBase::robotModel; +using namespace robotParts; + +Communicator::Communicator(const DeviceInfo &info, const PortInfo &port) + : Device(info, port) +{} diff --git a/plugins/robots/common/trikKit/include/trikKit/robotModel/parts/trikNetworkCommunicator.h b/plugins/robots/common/trikKit/include/trikKit/robotModel/parts/trikNetworkCommunicator.h new file mode 100644 index 0000000000..8f68eb4226 --- /dev/null +++ b/plugins/robots/common/trikKit/include/trikKit/robotModel/parts/trikNetworkCommunicator.h @@ -0,0 +1,50 @@ +/* Copyright 2024 CyberTech Labs 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. */ + +#pragma once +#include + +namespace trik { +namespace robotModel { +namespace parts { + +/// Class for TRIK robot network communication. +class TrikNetworkCommunicator : public kitBase::robotModel::robotParts::Communicator +{ + Q_OBJECT + +public: + TrikNetworkCommunicator(const kitBase::robotModel::DeviceInfo &info + , const kitBase::robotModel::PortInfo &port); + + + /// Send a message to a robot + virtual void send(const QString& message, int hullNumber) = 0; + + /// Receive message from robot + virtual QString receive(bool wait) = 0; + + /// Join the network with the specified hull number + virtual void joinNetwork(const QString &ip, int port, int hullNumber) = 0; + + /// Send an interrupt to stop waiting for a message + virtual void stopWaiting() = 0; + + /// Clean the incoming message queue + virtual void clearQueue() = 0; +}; + +} +} +} diff --git a/plugins/robots/common/trikKit/include/trikKit/robotModel/trikRobotModelBase.h b/plugins/robots/common/trikKit/include/trikKit/robotModel/trikRobotModelBase.h index 578f042e94..81a0c3c85b 100644 --- a/plugins/robots/common/trikKit/include/trikKit/robotModel/trikRobotModelBase.h +++ b/plugins/robots/common/trikKit/include/trikKit/robotModel/trikRobotModelBase.h @@ -75,6 +75,7 @@ class TrikRobotModelBase : public kitBase::robotModel::CommonRobotModel virtual kitBase::robotModel::PortInfo video2Port() const; virtual kitBase::robotModel::PortInfo lidarPort() const; + virtual kitBase::robotModel::DeviceInfo networkInfo() const; }; } diff --git a/plugins/robots/common/trikKit/src/blocks/details/joinNetworkBlock.cpp b/plugins/robots/common/trikKit/src/blocks/details/joinNetworkBlock.cpp new file mode 100644 index 0000000000..1eeb3ff772 --- /dev/null +++ b/plugins/robots/common/trikKit/src/blocks/details/joinNetworkBlock.cpp @@ -0,0 +1,32 @@ +/* Copyright 2024 CyberTech Labs 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 "joinNetworkBlock.h" + +using namespace trik; +using namespace blocks::details; + +JoinNetworkBlock::JoinNetworkBlock(kitBase::robotModel::RobotModelInterface &robotModel): + kitBase::blocksBase::common::DeviceBlock(robotModel) +{} + +void JoinNetworkBlock::doJob(robotModel::parts::TrikNetworkCommunicator &network) +{ + auto address = stringProperty("Address"); + auto port = intProperty("IPPort"); + auto hullNumber = intProperty("HullNumber"); + network.joinNetwork(address, port, hullNumber); + emit done(mNextBlockId); +} diff --git a/plugins/robots/common/trikKit/src/blocks/details/joinNetworkBlock.h b/plugins/robots/common/trikKit/src/blocks/details/joinNetworkBlock.h new file mode 100644 index 0000000000..2102e8abd9 --- /dev/null +++ b/plugins/robots/common/trikKit/src/blocks/details/joinNetworkBlock.h @@ -0,0 +1,36 @@ +/* Copyright 2024 CyberTech Labs 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. */ + +#pragma once + +#include +#include "trikKit/robotModel/parts/trikNetworkCommunicator.h" + +namespace trik { +namespace blocks { +namespace details { + +class JoinNetworkBlock: public kitBase::blocksBase::common::DeviceBlock +{ + Q_OBJECT +public: + JoinNetworkBlock(kitBase::robotModel::RobotModelInterface &robotModel); + +private: + void doJob(robotModel::parts::TrikNetworkCommunicator &network) override; +}; + +} +} +} diff --git a/plugins/robots/common/trikKit/src/blocks/details/sendMessageBlock.cpp b/plugins/robots/common/trikKit/src/blocks/details/sendMessageBlock.cpp new file mode 100644 index 0000000000..28893bd7c6 --- /dev/null +++ b/plugins/robots/common/trikKit/src/blocks/details/sendMessageBlock.cpp @@ -0,0 +1,30 @@ +/* Copyright 2024 CyberTech Labs 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 "sendMessageBlock.h" + +using namespace trik; +using namespace blocks::details; + +SendMessageBlock::SendMessageBlock(kitBase::robotModel::RobotModelInterface &robotModel): + kitBase::blocksBase::common::DeviceBlock(robotModel) +{} + +void SendMessageBlock::doJob(robotModel::parts::TrikNetworkCommunicator &network) +{ + auto message = stringProperty("Message"); + auto hullNumber = intProperty("HullNumber"); + network.send(message, hullNumber); + emit done(mNextBlockId); +} diff --git a/plugins/robots/common/trikKit/src/blocks/details/sendMessageBlock.h b/plugins/robots/common/trikKit/src/blocks/details/sendMessageBlock.h new file mode 100644 index 0000000000..b5304e8fe6 --- /dev/null +++ b/plugins/robots/common/trikKit/src/blocks/details/sendMessageBlock.h @@ -0,0 +1,36 @@ +/* Copyright 2024 CyberTech Labs 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. */ + +#pragma once + +#include +#include "trikKit/robotModel/parts/trikNetworkCommunicator.h" + +namespace trik { +namespace blocks { +namespace details { + +class SendMessageBlock: public kitBase::blocksBase::common::DeviceBlock +{ + Q_OBJECT +public: + SendMessageBlock(kitBase::robotModel::RobotModelInterface &robotModel); + +private: + void doJob(robotModel::parts::TrikNetworkCommunicator &network) override; +}; + +} +} +} diff --git a/plugins/robots/common/trikKit/src/blocks/details/waitForMessageBlock.cpp b/plugins/robots/common/trikKit/src/blocks/details/waitForMessageBlock.cpp new file mode 100644 index 0000000000..9d2676e110 --- /dev/null +++ b/plugins/robots/common/trikKit/src/blocks/details/waitForMessageBlock.cpp @@ -0,0 +1,76 @@ +/* Copyright 2024 CyberTech Labs 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 "waitForMessageBlock.h" +#include "trikKit/robotModel/parts/trikNetworkCommunicator.h" +#include +#include +#include +#include + +using namespace trik; +using namespace blocks::details; +using namespace kitBase::robotModel; + +WaitForMessageBlock::WaitForMessageBlock(kitBase::robotModel::RobotModelInterface &robotModel): + WaitBlock(robotModel) +{ + mActiveWaitingTimer->setSingleShot(true); + mActiveWaitingTimer->setInterval(100); +} + +void WaitForMessageBlock::handle() +{ + evalCode(stringProperty("Variable") + " = " + mMessage); + stop(); + emit done(mNextBlockId); + return; +} + +void WaitForMessageBlock::run() +{ + mNetwork = RobotModelUtils::findDevice(mRobotModel, "CommunicatorPort"); + + if (!mNetwork) { + error(tr("Device not found for port name CommunicatorPort")); + return; + } + + auto wait = boolProperty("Synchronized"); + + if (!wait) { + mMessage = utils::StringUtils::wrap(utils::StringUtils::dequote(mNetwork->receive(wait))); + handle(); + return; + } + + mActiveWaitingTimer->start(); +} + +void WaitForMessageBlock::timerTimeout() +{ + auto message = mNetwork->receive(false); + if (message != QString()) { + mMessage = utils::StringUtils::wrap(utils::StringUtils::dequote(message)); + handle(); + return; + } + + mActiveWaitingTimer->start(); +} + +DeviceInfo WaitForMessageBlock::device() const +{ + return DeviceInfo::create(); +} diff --git a/plugins/robots/common/trikKit/src/blocks/details/waitForMessageBlock.h b/plugins/robots/common/trikKit/src/blocks/details/waitForMessageBlock.h new file mode 100644 index 0000000000..468325fc78 --- /dev/null +++ b/plugins/robots/common/trikKit/src/blocks/details/waitForMessageBlock.h @@ -0,0 +1,45 @@ +/* Copyright 2024 CyberTech Labs 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. */ + +#pragma once + +#include "trikKit/robotModel/parts/trikNetworkCommunicator.h" +#include + +namespace trik { +namespace blocks { +namespace details { + +class WaitForMessageBlock: public kitBase::blocksBase::common::WaitBlock +{ + Q_OBJECT +public: + explicit WaitForMessageBlock(kitBase::robotModel::RobotModelInterface &robotModel); + +private slots: + void timerTimeout() override; +private: + void run() override; + + void handle(); + + kitBase::robotModel::DeviceInfo device() const override; + + robotModel::parts::TrikNetworkCommunicator *mNetwork {}; + QString mMessage {}; +}; + +} +} +} diff --git a/plugins/robots/common/trikKit/src/blocks/trikBlocksFactoryBase.cpp b/plugins/robots/common/trikKit/src/blocks/trikBlocksFactoryBase.cpp index 52fad8caee..c036dc24e3 100644 --- a/plugins/robots/common/trikKit/src/blocks/trikBlocksFactoryBase.cpp +++ b/plugins/robots/common/trikKit/src/blocks/trikBlocksFactoryBase.cpp @@ -58,6 +58,9 @@ #include "details/waitGamepadWheelBlock.h" #include "details/waitPadPressBlock.h" #include "details/trikWaitForGyroscopeBlock.h" +#include "details/joinNetworkBlock.h" +#include "details/sendMessageBlock.h" +#include "details/waitForMessageBlock.h" #include "details/writeToFileBlock.h" #include "details/removeFileBlock.h" @@ -98,11 +101,11 @@ qReal::interpretation::Block *TrikBlocksFactoryBase::produceBlock(const qReal::I } else if (elementMetatypeIs(element, "TrikInitVideoStreaming")) { return new InitVideoStreamingBlock(mRobotModelManager->model()); } else if (elementMetatypeIs(element, "TrikSendMessage")) { - return new qReal::interpretation::blocks::EmptyBlock(); + return new SendMessageBlock(mRobotModelManager->model()); } else if (elementMetatypeIs(element, "TrikWaitForMessage")) { - return new qReal::interpretation::blocks::EmptyBlock(); + return new WaitForMessageBlock(mRobotModelManager->model()); } else if (elementMetatypeIs(element, "TrikJoinNetwork")) { - return new qReal::interpretation::blocks::EmptyBlock(); + return new JoinNetworkBlock(mRobotModelManager->model()); } else if (elementMetatypeIs(element, "TrikLed")) { return new LedBlock(mRobotModelManager->model()); diff --git a/plugins/robots/common/trikKit/src/robotModel/parts/trikNetworkCommunicator.cpp b/plugins/robots/common/trikKit/src/robotModel/parts/trikNetworkCommunicator.cpp new file mode 100644 index 0000000000..3631b6568c --- /dev/null +++ b/plugins/robots/common/trikKit/src/robotModel/parts/trikNetworkCommunicator.cpp @@ -0,0 +1,22 @@ +/* Copyright 2024 CyberTech Labs 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 "trikKit/robotModel/parts/trikNetworkCommunicator.h" + +using namespace trik::robotModel::parts; +using namespace kitBase::robotModel; + +TrikNetworkCommunicator::TrikNetworkCommunicator(const DeviceInfo &info, const PortInfo &port) + : kitBase::robotModel::robotParts::Communicator(info, port) +{} diff --git a/plugins/robots/common/trikKit/src/robotModel/trikRobotModelBase.cpp b/plugins/robots/common/trikKit/src/robotModel/trikRobotModelBase.cpp index a30e9503b3..a55d8003f2 100644 --- a/plugins/robots/common/trikKit/src/robotModel/trikRobotModelBase.cpp +++ b/plugins/robots/common/trikKit/src/robotModel/trikRobotModelBase.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "trikKit/robotModel/parts/trikLightSensor.h" #include "trikKit/robotModel/parts/trikTouchSensor.h" @@ -124,6 +125,8 @@ TrikRobotModelBase::TrikRobotModelBase(const QString &kitId, const QString &robo addAllowedConnection(PortInfo("GamepadConnectionIndicatorPort", input, {}, "gamepadConnected") , { gamepadConnectionIndicatorInfo() }); + + addAllowedConnection(PortInfo("CommunicatorPort", output), { networkInfo() }); } QList TrikRobotModelBase::configurablePorts() const @@ -279,6 +282,12 @@ DeviceInfo TrikRobotModelBase::videoCameraInfo() const { return DeviceInfo::create(); } +DeviceInfo TrikRobotModelBase::networkInfo() const +{ + return DeviceInfo::create(); +} + + QHash TrikRobotModelBase::buttonCodes() const { QHash result; diff --git a/plugins/robots/common/trikKit/trikKit.pri b/plugins/robots/common/trikKit/trikKit.pri index 5b6805ca8d..7a95cf74a4 100644 --- a/plugins/robots/common/trikKit/trikKit.pri +++ b/plugins/robots/common/trikKit/trikKit.pri @@ -35,6 +35,7 @@ HEADERS += \ $$PWD/include/trikKit/robotModel/parts/trikGamepadPadPressSensor.h \ $$PWD/include/trikKit/robotModel/parts/trikGamepadWheel.h \ $$PWD/include/trikKit/robotModel/parts/trikSpeaker.h \ + $$PWD/include/trikKit/robotModel/parts/trikNetworkCommunicator.h \ $$PWD/include/trikKit/robotModel/parts/trikPowerMotor.h \ $$PWD/include/trikKit/robotModel/parts/trikServoMotor.h \ $$PWD/include/trikKit/robotModel/parts/trikInfraredSensor.h \ @@ -53,6 +54,9 @@ HEADERS += \ $$PWD/include/trikKit/blocks/trikV62BlocksFactory.h \ $$PWD/src/blocks/details/setBackgroundBlock.h \ $$PWD/src/blocks/details/smileBlock.h \ + $$PWD/src/blocks/details/sendMessageBlock.h \ + $$PWD/src/blocks/details/joinNetworkBlock.h \ + $$PWD/src/blocks/details/waitForMessageBlock.h \ $$PWD/src/blocks/details/trikEnginesForwardBlock.h \ $$PWD/src/blocks/details/trikEnginesBackwardBlock.h \ $$PWD/src/blocks/details/waitForMotionBlock.h \ @@ -102,6 +106,7 @@ SOURCES += \ $$PWD/src/robotModel/parts/trikServoMotor.cpp \ $$PWD/src/robotModel/parts/trikSonarSensor.cpp \ $$PWD/src/robotModel/parts/trikSpeaker.cpp \ + $$PWD/src/robotModel/parts/trikNetworkCommunicator.cpp \ $$PWD/src/robotModel/parts/trikShell.cpp \ $$PWD/src/robotModel/parts/trikMotorsAggregator.cpp \ $$PWD/src/robotModel/parts/trikTouchSensor.cpp \ @@ -111,6 +116,9 @@ SOURCES += \ $$PWD/src/blocks/trikV62BlocksFactory.cpp \ $$PWD/src/blocks/details/setBackgroundBlock.cpp \ $$PWD/src/blocks/details/smileBlock.cpp \ + $$PWD/src/blocks/details/sendMessageBlock.cpp \ + $$PWD/src/blocks/details/joinNetworkBlock.cpp \ + $$PWD/src/blocks/details/waitForMessageBlock.cpp \ $$PWD/src/blocks/details/trikEnginesForwardBlock.cpp \ $$PWD/src/blocks/details/trikEnginesBackwardBlock.cpp \ $$PWD/src/blocks/details/waitForMotionBlock.cpp \ diff --git a/plugins/robots/editor/trik/generated/elements.h b/plugins/robots/editor/trik/generated/elements.h index 7065816128..d0453664a1 100644 --- a/plugins/robots/editor/trik/generated/elements.h +++ b/plugins/robots/editor/trik/generated/elements.h @@ -753,7 +753,7 @@ label_1->setPlainTextMode(false); label_1->setPrefix(QObject::tr("Address:")); addLabel(label_1); - QSharedPointer label_2(new qReal::LabelProperties(2, 0.9, 1.8, "Port", false, 0)); + QSharedPointer label_2(new qReal::LabelProperties(2, 0.9, 1.8, "IPPort", false, 0)); label_2->setBackground(Qt::white); label_2->setScalingX(false); label_2->setScalingY(false); @@ -793,7 +793,7 @@ { addProperty("Address", "string", QObject::tr("192.168.77.1"), QObject::tr("Address"), QObject::tr(""), false); addProperty("HullNumber", "int", QString::fromUtf8("-1"), QObject::tr("Hull Number"), QObject::tr(""), false); - addProperty("Port", "int", QString::fromUtf8("-1"), QObject::tr("Port"), QObject::tr(""), false); + addProperty("IPPort", "int", QString::fromUtf8("-1"), QObject::tr("Port"), QObject::tr(""), false); } }; diff --git a/plugins/robots/editor/trik/trikMetamodel.xml b/plugins/robots/editor/trik/trikMetamodel.xml index 5042177879..5b5d188690 100644 --- a/plugins/robots/editor/trik/trikMetamodel.xml +++ b/plugins/robots/editor/trik/trikMetamodel.xml @@ -1282,7 +1282,7 @@ @@ -1292,7 +1292,7 @@ 192.168.77.1 - + -1 diff --git a/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/robotModel/twoD/parts/twoDNetworkCommunicator.h b/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/robotModel/twoD/parts/twoDNetworkCommunicator.h new file mode 100644 index 0000000000..3084be7667 --- /dev/null +++ b/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/robotModel/twoD/parts/twoDNetworkCommunicator.h @@ -0,0 +1,63 @@ +/* Copyright 2024 CyberTech Labs 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. */ + +#pragma once + +#include +#include +#include +#include "trikKitInterpreterCommon/declSpec.h" + +namespace trik { +namespace robotModel { +namespace twoD { +namespace parts { + +/// Class for implementing 2D-model network communication between robots +class ROBOTS_TRIK_KIT_INTERPRETER_COMMON_EXPORT TwoDNetworkCommunicator + : public robotModel::parts::TrikNetworkCommunicator +{ + Q_OBJECT + +public: + TwoDNetworkCommunicator(const kitBase::robotModel::DeviceInfo &info + , const kitBase::robotModel::PortInfo &port + , trikNetwork::MailboxInterface *mailbox); + ~TwoDNetworkCommunicator(); + + /// Send a message to a robot + void send(const QString& message, int hullNumber) override; + + /// Receive message from robot + QString receive(bool wait) override; + + /// Send an interrupt to stop waiting for a message + void stopWaiting() override; + + /// Clean the incoming message queue + void clearQueue() override; + + /// Join the network with the specified hull number + void joinNetwork(const QString &ip, int port, int hullNumber) override; + + /// Deinitializing a TRIK network communicator + void release() override; +private: + trikNetwork::MailboxInterface *mMailbox {}; // ownership --- TrikKitInterpreterPluginBase +}; + +} +} +} +} diff --git a/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/robotModel/twoD/trikTwoDRobotModel.h b/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/robotModel/twoD/trikTwoDRobotModel.h index 740369ee94..57693d0a2f 100644 --- a/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/robotModel/twoD/trikTwoDRobotModel.h +++ b/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/robotModel/twoD/trikTwoDRobotModel.h @@ -17,6 +17,7 @@ #include #include "trikKitInterpreterCommon/declSpec.h" +#include "trikNetwork/mailboxInterface.h" namespace qReal { class ErrorReporterInterface; @@ -68,6 +69,9 @@ class ROBOTS_TRIK_KIT_INTERPRETER_COMMON_EXPORT TrikTwoDRobotModel : public twoD /// Sets the error reporter for writing bubbling messages by shell emulator. void setErrorReporter(qReal::ErrorReporterInterface &errorReporter); + /// Sets the trik mailbox for twoDNetworkCommunicator execution. + void setMailbox(trikNetwork::MailboxInterface &mailbox); + private: kitBase::robotModel::robotParts::Device *createDevice( const kitBase::robotModel::PortInfo &port @@ -81,6 +85,7 @@ class ROBOTS_TRIK_KIT_INTERPRETER_COMMON_EXPORT TrikTwoDRobotModel : public twoD twoDModel::engine::TwoDModelDisplayWidget *mDisplayWidget; qReal::ErrorReporterInterface *mErrorReporter {}; QPolygonF mCollidingPolygon; + trikNetwork::MailboxInterface *mMailbox {}; //ownership TrikKitInterpreterPluginBase }; } diff --git a/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/trikKitInterpreterPluginBase.h b/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/trikKitInterpreterPluginBase.h index 04a3a2ca96..e5630b365b 100644 --- a/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/trikKitInterpreterPluginBase.h +++ b/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/trikKitInterpreterPluginBase.h @@ -26,7 +26,7 @@ #include "robotModel/twoD/trikTwoDRobotModel.h" #include "trikAdditionalPreferences.h" - +#include #include /// @todo: refactor @@ -55,7 +55,6 @@ class ROBOTS_TRIK_KIT_INTERPRETER_COMMON_EXPORT TrikKitInterpreterPluginBase QSharedPointer blocksFactoryFor( const kitBase::robotModel::RobotModelInterface *model) override; - QList settingsWidgets() override; QWidget *quickPreferencesFor(const kitBase::robotModel::RobotModelInterface &model) override; @@ -105,6 +104,7 @@ private slots: QSharedPointer mTwoDRobotModel; QScopedPointer mTextualInterpreter; + QScopedPointer mMailbox; QAction mStart; QAction mStop; diff --git a/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/trikTextualInterpreter.h b/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/trikTextualInterpreter.h index 6be88f0dc5..1cc10f9464 100644 --- a/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/trikTextualInterpreter.h +++ b/plugins/robots/interpreters/trikKitInterpreterCommon/include/trikKitInterpreterCommon/trikTextualInterpreter.h @@ -33,6 +33,7 @@ class ROBOTS_TRIK_KIT_INTERPRETER_COMMON_EXPORT TrikTextualInterpreter public: TrikTextualInterpreter(const QSharedPointer &model + , trikNetwork::MailboxInterface *mailbox , bool enablePython = false); ~TrikTextualInterpreter() override; @@ -46,7 +47,6 @@ class ROBOTS_TRIK_KIT_INTERPRETER_COMMON_EXPORT TrikTextualInterpreter bool isRunning() const; void setRunning(bool running); void setCurrentDir(const QString &dir, const QString &languageExtension); - void setMailboxHullNumber(); QStringList supportedRobotModelNames() const; QStringList knownMethodNames() const; @@ -67,7 +67,7 @@ private slots: bool mRunning { false }; TrikBrick mBrick; - trikNetwork::MailboxInterface *mMailbox {}; + trikNetwork::MailboxInterface *mMailbox {}; // ownership --- TrikKitInterpreterPluginBase TwoDExecutionControl *mExecutionControl {}; trikScriptRunner::TrikScriptRunner mScriptRunner; qReal::ErrorReporterInterface *mErrorReporter {}; diff --git a/plugins/robots/interpreters/trikKitInterpreterCommon/src/robotModel/twoD/parts/twoDNetworkCommunicator.cpp b/plugins/robots/interpreters/trikKitInterpreterCommon/src/robotModel/twoD/parts/twoDNetworkCommunicator.cpp new file mode 100644 index 0000000000..59c80e166a --- /dev/null +++ b/plugins/robots/interpreters/trikKitInterpreterCommon/src/robotModel/twoD/parts/twoDNetworkCommunicator.cpp @@ -0,0 +1,78 @@ +/* Copyright 2024 CyberTech Labs 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 "trikKitInterpreterCommon/robotModel/twoD/parts/twoDNetworkCommunicator.h" +#include +#include + +using namespace trik::robotModel::twoD::parts; +using namespace kitBase::robotModel; + +TwoDNetworkCommunicator::TwoDNetworkCommunicator(const DeviceInfo &info + , const PortInfo &port + ,trikNetwork::MailboxInterface *mailbox) + : robotModel::parts::TrikNetworkCommunicator(info, port) + , mMailbox(mailbox) +{} + + +TwoDNetworkCommunicator::~TwoDNetworkCommunicator(){ +} + +void TwoDNetworkCommunicator::send(const QString& message, int hullNumber) +{ + if (mMailbox) { + mMailbox->send(hullNumber, message); + } +} + +QString TwoDNetworkCommunicator::receive(bool wait) +{ + if (mMailbox) { + return mMailbox->receive(wait); + } + + return QString(); +} + +void TwoDNetworkCommunicator::stopWaiting() +{ + if (mMailbox) { + mMailbox->stopWaiting(); + } +} + +void TwoDNetworkCommunicator::clearQueue() +{ + if (mMailbox) { + mMailbox->clearQueue(); + } +} + +void TwoDNetworkCommunicator::release() +{ + if (mMailbox) { + mMailbox->stopWaiting(); + mMailbox->clearQueue(); + } +} + +void TwoDNetworkCommunicator::joinNetwork(const QString &ip, int port, int hullNumber) +{ + if (mMailbox) { + mMailbox->joinNetwork(ip, port, hullNumber); + } +} + + diff --git a/plugins/robots/interpreters/trikKitInterpreterCommon/src/robotModel/twoD/trikTwoDRobotModel.cpp b/plugins/robots/interpreters/trikKitInterpreterCommon/src/robotModel/twoD/trikTwoDRobotModel.cpp index da88056ee7..a8d67c9bed 100644 --- a/plugins/robots/interpreters/trikKitInterpreterCommon/src/robotModel/twoD/trikTwoDRobotModel.cpp +++ b/plugins/robots/interpreters/trikKitInterpreterCommon/src/robotModel/twoD/trikTwoDRobotModel.cpp @@ -45,7 +45,7 @@ #include "trikKitInterpreterCommon/robotModel/twoD/parts/twoDColorSensor.h" #include "trikKitInterpreterCommon/robotModel/twoD/parts/twoDLightSensor.h" #include "trikKitInterpreterCommon/robotModel/twoD/parts/twoDGyroscopeSensor.h" - +#include "trikKitInterpreterCommon/robotModel/twoD/parts/twoDNetworkCommunicator.h" using namespace trik::robotModel; using namespace trik::robotModel::twoD; using namespace kitBase::robotModel; @@ -79,6 +79,11 @@ QPair TrikTwoDRobotModel::rangeSensorAngleAndDistance robotParts::Device *TrikTwoDRobotModel::createDevice(const PortInfo &port, const DeviceInfo &deviceInfo) { + if (deviceInfo.isA()) { + return new parts::TwoDNetworkCommunicator(deviceInfo, port, mMailbox); + } + + if (deviceInfo.isA()) { return new parts::Display(deviceInfo, port, *engine()); } @@ -140,6 +145,13 @@ void TrikTwoDRobotModel::onInterpretationStarted() } else { QLOG_WARN() << "TRIK shell is not configured before intepretation start!"; } + + auto * const mailbox = RobotModelUtils::findDevice(*this, "CommunicatorPort"); + if (mailbox) { + mailbox->release(); + } else { + QLOG_WARN() << "TRIK network is not configured before intepretation start!"; + } } QString TrikTwoDRobotModel::robotImage() const @@ -264,3 +276,8 @@ void TrikTwoDRobotModel::setErrorReporter(qReal::ErrorReporterInterface &errorRe { mErrorReporter = &errorReporter; } + +void TrikTwoDRobotModel::setMailbox(trikNetwork::MailboxInterface &mailbox) +{ + mMailbox = &mailbox; +} diff --git a/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikAdditionalPreferences.cpp b/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikAdditionalPreferences.cpp index e0b0b7b0a7..f509a52a2c 100644 --- a/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikAdditionalPreferences.cpp +++ b/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikAdditionalPreferences.cpp @@ -55,9 +55,6 @@ TrikAdditionalPreferences::TrikAdditionalPreferences(const QStringList &realRobo connect(mUi->packImagesPushButton, &QPushButton::clicked , this, &TrikAdditionalPreferences::packImagesToProjectClicked); - - connect(mUi->mailboxCheckBox, &QCheckBox::toggled, mUi->mailboxHullNumberLabel, &QLabel::setVisible); - connect(mUi->mailboxCheckBox, &QCheckBox::toggled, mUi->mailboxHullNumber, &QLineEdit::setVisible); } TrikAdditionalPreferences::~TrikAdditionalPreferences() @@ -73,7 +70,6 @@ void TrikAdditionalPreferences::save() SettingsManager::setValue("TrikSimulatedCameraImagesFromProject", mUi->imagesFromProjectCheckBox->isChecked()); SettingsManager::setValue("TrikWebCameraRealName", mUi->cameraNameLineEdit->text()); SettingsManager::setValue("TRIK2DMailbox", mUi->mailboxCheckBox->isChecked()); - SettingsManager::setValue("TRIK2DHullNumber", mUi->mailboxHullNumber->text()); mUi->robotImagePicker->save(); if (mailboxSavedState != mUi->mailboxCheckBox->isChecked()) { diff --git a/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikAdditionalPreferences.ui b/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikAdditionalPreferences.ui index 787eec7e1a..6f014d99f4 100644 --- a/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikAdditionalPreferences.ui +++ b/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikAdditionalPreferences.ui @@ -7,7 +7,7 @@ 0 0 357 - 427 + 445 @@ -146,20 +146,6 @@ Enable Mailbox - - - - - Hull number: - - - - - - - 999 - - diff --git a/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikKitInterpreter.pri b/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikKitInterpreter.pri index f2c9198ad1..286564363d 100644 --- a/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikKitInterpreter.pri +++ b/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikKitInterpreter.pri @@ -56,6 +56,7 @@ HEADERS += \ $$PWD/robotModel/twoD/parts/twoDObjectSensor.h \ $$PWD/robotModel/twoD/parts/twoDColorSensor.h \ $$PWD/robotModel/twoD/parts/twoDShell.h \ + $$PWD/robotModel/twoD/parts/twoDNetworkCommunicator.h \ $$PWD/robotModel/real/trikV62RealRobotModel.h \ $$PWD/robotModel/twoD/trikV62TwoDRobotModel.h \ $$PWD/trikV62AdditionalPreferences.h \ @@ -93,6 +94,7 @@ SOURCES += \ $$PWD/robotModel/twoD/parts/twoDColorSensor.cpp \ $$PWD/robotModel/twoD/parts/twoDLed.cpp \ $$PWD/robotModel/twoD/parts/twoDShell.cpp \ + $$PWD/robotModel/twoD/parts/twoDNetworkCommunicator.cpp \ $$PWD/trikV62AdditionalPreferences.cpp \ $$PWD/trikV62DisplayWidget.cpp \ $$PWD/trikV62KitInterpreterPlugin.cpp \ diff --git a/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikKitInterpreterPluginBase.cpp b/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikKitInterpreterPluginBase.cpp index 5ee3aa5585..2bb34a9deb 100644 --- a/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikKitInterpreterPluginBase.cpp +++ b/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikKitInterpreterPluginBase.cpp @@ -25,9 +25,9 @@ #include #include #include - #include #include +#include "trikNetwork/mailboxFactory.h" using namespace trik; using namespace qReal; @@ -51,8 +51,15 @@ void TrikKitInterpreterPluginBase::initKitInterpreterPluginBase , const QSharedPointer &blocksFactory ) { + auto isMailboxEnabled = qReal::SettingsManager::value("TRIK2DMailbox", "").toBool(); + if (isMailboxEnabled) { + mMailbox.reset(trikNetwork::MailboxFactory::create(8889)); + } mRealRobotModel.reset(realRobotModel); mTwoDRobotModel.reset(twoDRobotModel); + if (mMailbox) { + mTwoDRobotModel->setMailbox(*mMailbox); + } mBlocksFactory = blocksFactory; const auto modelEngine = new twoDModel::engine::TwoDModelEngineFacade(*mTwoDRobotModel); @@ -84,9 +91,7 @@ void TrikKitInterpreterPluginBase::initKitInterpreterPluginBase } } #endif - mTextualInterpreter.reset(new TrikTextualInterpreter(mTwoDRobotModel, enablePython)); - connect(mAdditionalPreferences, &TrikAdditionalPreferences::settingsChanged - , mTextualInterpreter.data(), &TrikTextualInterpreter::setMailboxHullNumber); + mTextualInterpreter.reset(new TrikTextualInterpreter(mTwoDRobotModel, mMailbox.data(), enablePython)); } void TrikKitInterpreterPluginBase::startCodeInterpretation(const QString &code, const QString &extension) diff --git a/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp b/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp index 538899482c..9cbf18c88c 100644 --- a/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp +++ b/plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp @@ -36,10 +36,10 @@ const QString jsOverrides = "Date.now = script.time;"; trik::TrikTextualInterpreter::TrikTextualInterpreter( const QSharedPointer &model + , trikNetwork::MailboxInterface *mailbox , bool enablePython) : mBrick(model) - , mMailbox(qReal::SettingsManager::value("TRIK2DMailbox", "").toBool() - ? trikNetwork::MailboxFactory::create(8889): nullptr) + , mMailbox(mailbox) , mScriptRunner(mBrick, mMailbox, new TwoDExecutionControl(mBrick, model)) { connect(&mBrick, &TrikBrick::error, this, &TrikTextualInterpreter::reportError); @@ -73,13 +73,6 @@ trik::TrikTextualInterpreter::~TrikTextualInterpreter() abort(); } -void trik::TrikTextualInterpreter::setMailboxHullNumber() -{ - if (mMailbox) { - mMailbox->setHullNumber(qReal::SettingsManager::value("TRIK2DHullNumber", "999").toInt()); - } -} - void trik::TrikTextualInterpreter::interpretCommand(const QString &script) { mScriptRunner.runDirectCommand(script); diff --git a/plugins/robots/interpreters/trikKitInterpreterCommon/trikKitInterpreterCommon.pri b/plugins/robots/interpreters/trikKitInterpreterCommon/trikKitInterpreterCommon.pri index 6655b36e24..4a5e493b44 100644 --- a/plugins/robots/interpreters/trikKitInterpreterCommon/trikKitInterpreterCommon.pri +++ b/plugins/robots/interpreters/trikKitInterpreterCommon/trikKitInterpreterCommon.pri @@ -73,6 +73,7 @@ HEADERS += \ $$PWD/include/trikKitInterpreterCommon/robotModel/twoD/parts/twoDObjectSensor.h \ $$PWD/include/trikKitInterpreterCommon/robotModel/twoD/parts/twoDColorSensor.h \ $$PWD/include/trikKitInterpreterCommon/robotModel/twoD/parts/twoDShell.h \ + $$PWD/include/trikKitInterpreterCommon/robotModel/twoD/parts/twoDNetworkCommunicator.h \ $$PWD/include/trikKitInterpreterCommon/robotModel/twoD/parts/twoDGyroscopeSensor.h \ $$PWD/include/trikKitInterpreterCommon/robotModel/twoD/trikTwoDRobotModel.h \ $$PWD/include/trikKitInterpreterCommon/trikAdditionalPreferences.h \ @@ -128,6 +129,7 @@ SOURCES += \ $$PWD/src/robotModel/twoD/parts/twoDColorSensor.cpp \ $$PWD/src/robotModel/twoD/parts/twoDLed.cpp \ $$PWD/src/robotModel/twoD/parts/twoDShell.cpp \ + $$PWD/src/robotModel/twoD/parts/twoDNetworkCommunicator.cpp \ $$PWD/src/robotModel/twoD/parts/twoDGyroscopeSensor.cpp \ $$PWD/src/robotModel/twoD/trikTwoDRobotModel.cpp \ $$PWD/src/trikAdditionalPreferences.cpp \ diff --git a/qrtranslations/fr/plugins/robots/kitBase_fr.ts b/qrtranslations/fr/plugins/robots/kitBase_fr.ts index ac6c9485c7..edbb2f6f9e 100644 --- a/qrtranslations/fr/plugins/robots/kitBase_fr.ts +++ b/qrtranslations/fr/plugins/robots/kitBase_fr.ts @@ -158,6 +158,14 @@ + + kitBase::robotModel::robotParts::Communicator + + + Communicator + + + kitBase::robotModel::robotParts::Display diff --git a/qrtranslations/fr/plugins/robots/trikKitInterpreterCommon_fr.ts b/qrtranslations/fr/plugins/robots/trikKitInterpreterCommon_fr.ts index 9d05841d33..065fb9d533 100644 --- a/qrtranslations/fr/plugins/robots/trikKitInterpreterCommon_fr.ts +++ b/qrtranslations/fr/plugins/robots/trikKitInterpreterCommon_fr.ts @@ -4,7 +4,7 @@ QObject - + Bogus input values @@ -52,17 +52,7 @@ - - Hull number: - - - - - 999 - - - - + Camera: @@ -129,7 +119,7 @@ - + Information @@ -248,7 +238,7 @@ - + TRIK_PYTHONPATH must be set correctly to run Python script. diff --git a/qrtranslations/fr/plugins/robots/trikKit_fr.ts b/qrtranslations/fr/plugins/robots/trikKit_fr.ts index 18952abc68..d57ad99b42 100644 --- a/qrtranslations/fr/plugins/robots/trikKit_fr.ts +++ b/qrtranslations/fr/plugins/robots/trikKit_fr.ts @@ -1,6 +1,14 @@ + + trik::blocks::details::WaitForMessageBlock + + + Device not found for port name CommunicatorPort + + + trik::blocks::details::WaitGamepadButtonBlock @@ -12,8 +20,8 @@ trik::robotModel::TrikRobotModelBase - - + + Video 2 diff --git a/qrtranslations/ru/plugins/robots/kitBase_ru.ts b/qrtranslations/ru/plugins/robots/kitBase_ru.ts index 10508327d2..dd287664c4 100644 --- a/qrtranslations/ru/plugins/robots/kitBase_ru.ts +++ b/qrtranslations/ru/plugins/robots/kitBase_ru.ts @@ -158,6 +158,14 @@ Датчик цвета EV3 (отраженный) + + kitBase::robotModel::robotParts::Communicator + + + Communicator + + + kitBase::robotModel::robotParts::Display diff --git a/qrtranslations/ru/plugins/robots/trikKitInterpreterCommon_ru.ts b/qrtranslations/ru/plugins/robots/trikKitInterpreterCommon_ru.ts index 1a42cc83c1..180c0de675 100644 --- a/qrtranslations/ru/plugins/robots/trikKitInterpreterCommon_ru.ts +++ b/qrtranslations/ru/plugins/robots/trikKitInterpreterCommon_ru.ts @@ -4,7 +4,7 @@ QObject - + Bogus input values Неподходящие значения аргументов @@ -76,17 +76,11 @@ Активировать Mailbox - Hull number: - Бортномер: - - - - 999 - + Бортномер: - + Images: Изображения: @@ -185,7 +179,7 @@ Выберите папку - + Information Информация @@ -313,7 +307,7 @@ Оставновить - + TRIK_PYTHONPATH must be set correctly to run Python script. Для запуска программы на Python доложна быть корректно выставлена переменная окружения TRIK_PYTHONPATH diff --git a/qrtranslations/ru/plugins/robots/trikKit_ru.ts b/qrtranslations/ru/plugins/robots/trikKit_ru.ts index ef01950958..5d22287a61 100644 --- a/qrtranslations/ru/plugins/robots/trikKit_ru.ts +++ b/qrtranslations/ru/plugins/robots/trikKit_ru.ts @@ -1,6 +1,14 @@ + + trik::blocks::details::WaitForMessageBlock + + + Device not found for port name CommunicatorPort + + + trik::blocks::details::WaitGamepadButtonBlock @@ -12,8 +20,8 @@ trik::robotModel::TrikRobotModelBase - - + + Video 2