From 064c0af790289bd43712044ea5371ece7384d272 Mon Sep 17 00:00:00 2001 From: vinle0 Date: Fri, 4 Oct 2024 23:46:20 +0000 Subject: [PATCH 01/13] Initial code --- .../client_display_subsystem.cpp | 12 +++ .../client_display_subsystem.hpp | 22 +++++ .../client-display/command_client_display.cpp | 72 +++++++++++++++++ .../client-display/command_client_display.hpp | 80 +++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 ut-robomaster/src/contols/client-display/client_display_subsystem.cpp create mode 100644 ut-robomaster/src/contols/client-display/client_display_subsystem.hpp create mode 100644 ut-robomaster/src/contols/client-display/command_client_display.cpp create mode 100644 ut-robomaster/src/contols/client-display/command_client_display.hpp diff --git a/ut-robomaster/src/contols/client-display/client_display_subsystem.cpp b/ut-robomaster/src/contols/client-display/client_display_subsystem.cpp new file mode 100644 index 00000000..5898b9e1 --- /dev/null +++ b/ut-robomaster/src/contols/client-display/client_display_subsystem.cpp @@ -0,0 +1,12 @@ +#include "client_display_subsystem.hpp" + +#include "tap/communication/sensors/buzzer/buzzer.hpp" + +namespace subsystems::control +{ + ClientDisplaySubsystem::ClientDisplaySubsystem( + tap::Drivers *drivers + ) : Subsystem(drivers) + { + } +} \ No newline at end of file diff --git a/ut-robomaster/src/contols/client-display/client_display_subsystem.hpp b/ut-robomaster/src/contols/client-display/client_display_subsystem.hpp new file mode 100644 index 00000000..c885b4f2 --- /dev/null +++ b/ut-robomaster/src/contols/client-display/client_display_subsystem.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "drivers.hpp" +#include "tap/control/command.hpp" +#include "tap/control/subsystem.hpp" +#include "tap/communication/sensors/buzzer/buzzer.hpp" + +using namespace tap::control; + +namespace subsystems::control +{ +class ClientDisplaySubsystem : public Subsystem +{ +public: + ClientDisplaySubsystem(tap::Drivers*); + virtual ~ClientDisplaySubsystem() {} + + void initialize() override {}; + + const char* getName() override { return "client display"; } +}; +} \ No newline at end of file diff --git a/ut-robomaster/src/contols/client-display/command_client_display.cpp b/ut-robomaster/src/contols/client-display/command_client_display.cpp new file mode 100644 index 00000000..b9ea243a --- /dev/null +++ b/ut-robomaster/src/contols/client-display/command_client_display.cpp @@ -0,0 +1,72 @@ +#include "command_client_display.hpp" + + +modm::ResumableResult BeybladeIndicator::sendInitialGraphics() +{ + // The number represents the index of the resumable function in this class + RF_BEGIN(0); + + RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + + RF_END(); +} + +modm::ResumableResult BeybladeIndicator::update() +{ + // This is the second resumable function so its index is 1 + RF_BEGIN(1); + + RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + + RF_END(); +} + +void BeybladeIndicator::initialize() +{ + RefSerialTransmitter::configGraphicGenerics( + &msg.graphicData[0], + graphicName, + RefSerialData::Tx::GRAPHIC_ADD, + 1, // Graphic layer can be 0-9 + RefSerialData::Tx::GraphicColor::PINK + ); + RefSerialTransmitter::configCircle( + 50, + 1920/2, + 1080/2, + 200, + &msg.graphicData[0] + ); + } + +namespace commands +{ + +void CommandClientDisplay::restartHud() +{ + beybladeIndicator.initialize(); + + this->restarting = false; +} + +bool CommandClientDisplay::run() +{ + if (!this->isRunning()) { + restart(); + this->restartHud(); + } + + PT_BEGIN(); + + PT_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); + + PT_CALL(beybladeIndicator.sendInitialGraphics()); + + while (!this->restarting) { + PT_CALL(beybladeIndicator.update()); + PT_YIELD(); + } + + PT_END(); +} +} \ No newline at end of file diff --git a/ut-robomaster/src/contols/client-display/command_client_display.hpp b/ut-robomaster/src/contols/client-display/command_client_display.hpp new file mode 100644 index 00000000..2300978d --- /dev/null +++ b/ut-robomaster/src/contols/client-display/command_client_display.hpp @@ -0,0 +1,80 @@ +#pragma once + +#include "tap/control/command.hpp" +#include "tap/communication/serial/ref_serial_transmitter.hpp" +#include "tap/communication/serial/ref_serial_data.hpp" +#include "modm/processing/protothread.hpp" +#include "modm/processing/resumable.hpp" + +#include "tap/communication/sensors/buzzer/buzzer.hpp" + +#include "drivers.hpp" + +#include "control/client-display/client_display_subsystem.hpp" + +#include "subsystems/chassis/chassis_subsystem.hpp" + +using namespace tap::control; +using namespace tap::communication::serial; + +using subsystems::control::ClientDisplaySubsystem; +using subsystems::chassis::ChassisSubsystem; + +class BeybladeIndicator : protected modm::Resumable<2> +{ +private: + const uint8_t* graphicName = (uint8_t*)"\x00\x00\x01"; + RefSerialTransmitter &refSerialTransmitter; + RefSerialData::Tx::Graphic5Message msg; + +public: + BeybladeIndicator(RefSerialTransmitter refSerialTransmitter) + : refSerialTransmitter(refSerialTransmitter) + {} + + modm::ResumableResult sendInitialGraphics(); + modm::ResumableResult update(); + + void initialize(); +}; + +namespace commands +{ +class CommandClientDisplay : public Command, modm::pt::Protothread +{ +private: + src::Drivers* drivers; + RefSerialTransmitter refSerialTransmitter; + BeybladeIndicator beybladeIndicator; + bool restarting = true; + + void restartHud(); +public: + CommandClientDisplay( + src::Drivers *drivers, + ChassisSubsystem *chassis) + : Command(), + drivers(drivers), + refSerialTransmitter(drivers), + beybladeIndicator(refSerialTransmitter) + { + addSubsystemRequirement(chassis); + } + + bool run(); + + const char *getName() const override { return "client display"; } + void initialize() override + { + tap::buzzer::playNote(&drivers->pwm, 880); + this->restarting = true; + }; + + void execute() override + { + run(); + } + void end(bool) override {} + bool isFinished() const override { return false; } +}; +} \ No newline at end of file From a7c4715464aaa6a16e3e7a57ddaeacba5b9c0929 Mon Sep 17 00:00:00 2001 From: vinle0 Date: Fri, 4 Oct 2024 23:46:20 +0000 Subject: [PATCH 02/13] Bad directory --- .../client-display/client_display_subsystem.cpp | 0 .../client-display/client_display_subsystem.hpp | 0 .../client-display/command_client_display.cpp | 0 .../client-display/command_client_display.hpp | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename ut-robomaster/src/{contols => control}/client-display/client_display_subsystem.cpp (100%) rename ut-robomaster/src/{contols => control}/client-display/client_display_subsystem.hpp (100%) rename ut-robomaster/src/{contols => control}/client-display/command_client_display.cpp (100%) rename ut-robomaster/src/{contols => control}/client-display/command_client_display.hpp (100%) diff --git a/ut-robomaster/src/contols/client-display/client_display_subsystem.cpp b/ut-robomaster/src/control/client-display/client_display_subsystem.cpp similarity index 100% rename from ut-robomaster/src/contols/client-display/client_display_subsystem.cpp rename to ut-robomaster/src/control/client-display/client_display_subsystem.cpp diff --git a/ut-robomaster/src/contols/client-display/client_display_subsystem.hpp b/ut-robomaster/src/control/client-display/client_display_subsystem.hpp similarity index 100% rename from ut-robomaster/src/contols/client-display/client_display_subsystem.hpp rename to ut-robomaster/src/control/client-display/client_display_subsystem.hpp diff --git a/ut-robomaster/src/contols/client-display/command_client_display.cpp b/ut-robomaster/src/control/client-display/command_client_display.cpp similarity index 100% rename from ut-robomaster/src/contols/client-display/command_client_display.cpp rename to ut-robomaster/src/control/client-display/command_client_display.cpp diff --git a/ut-robomaster/src/contols/client-display/command_client_display.hpp b/ut-robomaster/src/control/client-display/command_client_display.hpp similarity index 100% rename from ut-robomaster/src/contols/client-display/command_client_display.hpp rename to ut-robomaster/src/control/client-display/command_client_display.hpp From 185c1dbac49e80e47f33da65722db08c0e4af55b Mon Sep 17 00:00:00 2001 From: Caleb Chalmers Date: Sat, 9 Nov 2024 00:02:35 +0000 Subject: [PATCH 03/13] Testing basic working example (not working) --- .../client_display_subsystem.cpp | 15 ++-- .../client_display_subsystem.hpp | 20 +++-- .../client-display/command_client_display.cpp | 79 +++++++---------- .../client-display/command_client_display.hpp | 87 ++++++++----------- .../src/robots/standard/standard_control.hpp | 7 ++ 5 files changed, 97 insertions(+), 111 deletions(-) diff --git a/ut-robomaster/src/control/client-display/client_display_subsystem.cpp b/ut-robomaster/src/control/client-display/client_display_subsystem.cpp index 5898b9e1..792fae33 100644 --- a/ut-robomaster/src/control/client-display/client_display_subsystem.cpp +++ b/ut-robomaster/src/control/client-display/client_display_subsystem.cpp @@ -4,9 +4,12 @@ namespace subsystems::control { - ClientDisplaySubsystem::ClientDisplaySubsystem( - tap::Drivers *drivers - ) : Subsystem(drivers) - { - } -} \ No newline at end of file +ClientDisplaySubsystem::ClientDisplaySubsystem(tap::Drivers *drivers) : Subsystem(drivers) {} + +void ClientDisplaySubsystem::initialize() {} + +void ClientDisplaySubsystem::refresh() {} + +void ClientDisplaySubsystem::runHardwareTests() {} + +} // namespace subsystems::control \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/client_display_subsystem.hpp b/ut-robomaster/src/control/client-display/client_display_subsystem.hpp index c885b4f2..055f3ea6 100644 --- a/ut-robomaster/src/control/client-display/client_display_subsystem.hpp +++ b/ut-robomaster/src/control/client-display/client_display_subsystem.hpp @@ -1,22 +1,24 @@ #pragma once -#include "drivers.hpp" +#include "tap/communication/sensors/buzzer/buzzer.hpp" #include "tap/control/command.hpp" #include "tap/control/subsystem.hpp" -#include "tap/communication/sensors/buzzer/buzzer.hpp" -using namespace tap::control; +#include "drivers.hpp" namespace subsystems::control { -class ClientDisplaySubsystem : public Subsystem +class ClientDisplaySubsystem : public tap::control::Subsystem { public: - ClientDisplaySubsystem(tap::Drivers*); - virtual ~ClientDisplaySubsystem() {} + ClientDisplaySubsystem(tap::Drivers*); + + void initialize() override; + + void refresh() override; - void initialize() override {}; + void runHardwareTests() override; - const char* getName() override { return "client display"; } + const char* getName() override { return "Client Display subsystem"; } }; -} \ No newline at end of file +} // namespace subsystems::control \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/command_client_display.cpp b/ut-robomaster/src/control/client-display/command_client_display.cpp index b9ea243a..0f5de75a 100644 --- a/ut-robomaster/src/control/client-display/command_client_display.cpp +++ b/ut-robomaster/src/control/client-display/command_client_display.cpp @@ -1,72 +1,59 @@ #include "command_client_display.hpp" - -modm::ResumableResult BeybladeIndicator::sendInitialGraphics() +modm::ResumableResult BeybladeIndicator::sendInitialGraphics(src::Drivers *drivers) { - // The number represents the index of the resumable function in this class - RF_BEGIN(0); - - RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + // The number represents the index of the resumable function in this class + RF_BEGIN(0); + + tap::buzzer::playNote(&drivers->pwm, 880); + RF_CALL(refSerialTransmitter.sendGraphic(&msg)); - RF_END(); + RF_END(); } modm::ResumableResult BeybladeIndicator::update() { - // This is the second resumable function so its index is 1 - RF_BEGIN(1); + // This is the second resumable function so its index is 1 + RF_BEGIN(1); - RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + RF_CALL(refSerialTransmitter.sendGraphic(&msg)); - RF_END(); + RF_END(); } void BeybladeIndicator::initialize() { - RefSerialTransmitter::configGraphicGenerics( - &msg.graphicData[0], - graphicName, - RefSerialData::Tx::GRAPHIC_ADD, - 1, // Graphic layer can be 0-9 - RefSerialData::Tx::GraphicColor::PINK - ); - RefSerialTransmitter::configCircle( - 50, - 1920/2, - 1080/2, - 200, - &msg.graphicData[0] - ); - } + RefSerialTransmitter::configGraphicGenerics( + &msg.graphicData[0], + graphicName, + RefSerialData::Tx::GRAPHIC_ADD, + 1, // Graphic layer can be 0-9 + RefSerialData::Tx::GraphicColor::PINK); + RefSerialTransmitter::configCircle(10, 400, 400, 200, &msg.graphicData[0]); +} namespace commands { -void CommandClientDisplay::restartHud() +void CommandClientDisplay::initialize() { - beybladeIndicator.initialize(); - - this->restarting = false; + beybladeIndicator.initialize(); + restart(); } -bool CommandClientDisplay::run() -{ - if (!this->isRunning()) { - restart(); - this->restartHud(); - } +void CommandClientDisplay::execute() { run(); } + +void CommandClientDisplay::end(bool) { tap::buzzer::silenceBuzzer(&drivers->pwm); } - PT_BEGIN(); - - PT_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); +bool CommandClientDisplay::isFinished() const { return !isRunning(); } - PT_CALL(beybladeIndicator.sendInitialGraphics()); +bool CommandClientDisplay::run() +{ + PT_BEGIN(); - while (!this->restarting) { - PT_CALL(beybladeIndicator.update()); - PT_YIELD(); - } + PT_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); + PT_CALL(beybladeIndicator.sendInitialGraphics(drivers)); - PT_END(); + PT_END(); } -} \ No newline at end of file +} // namespace commands \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/command_client_display.hpp b/ut-robomaster/src/control/client-display/command_client_display.hpp index 2300978d..15d519bf 100644 --- a/ut-robomaster/src/control/client-display/command_client_display.hpp +++ b/ut-robomaster/src/control/client-display/command_client_display.hpp @@ -1,41 +1,40 @@ #pragma once -#include "tap/control/command.hpp" -#include "tap/communication/serial/ref_serial_transmitter.hpp" +#include "tap/communication/sensors/buzzer/buzzer.hpp" #include "tap/communication/serial/ref_serial_data.hpp" +#include "tap/communication/serial/ref_serial_transmitter.hpp" +#include "tap/control/command.hpp" + +#include "control/client-display/client_display_subsystem.hpp" #include "modm/processing/protothread.hpp" #include "modm/processing/resumable.hpp" - -#include "tap/communication/sensors/buzzer/buzzer.hpp" +#include "subsystems/flywheel/flywheel_subsystem.hpp" #include "drivers.hpp" -#include "control/client-display/client_display_subsystem.hpp" - -#include "subsystems/chassis/chassis_subsystem.hpp" - using namespace tap::control; using namespace tap::communication::serial; using subsystems::control::ClientDisplaySubsystem; -using subsystems::chassis::ChassisSubsystem; +using subsystems::flywheel::FlywheelSubsystem; class BeybladeIndicator : protected modm::Resumable<2> { private: - const uint8_t* graphicName = (uint8_t*)"\x00\x00\x01"; - RefSerialTransmitter &refSerialTransmitter; - RefSerialData::Tx::Graphic5Message msg; + const uint8_t *graphicName = (uint8_t *)"\x00\x00\x01"; + RefSerialTransmitter &refSerialTransmitter; + RefSerialData::Tx::Graphic5Message msg; public: - BeybladeIndicator(RefSerialTransmitter refSerialTransmitter) - : refSerialTransmitter(refSerialTransmitter) - {} + BeybladeIndicator(RefSerialTransmitter refSerialTransmitter) + : refSerialTransmitter(refSerialTransmitter) + { + } + + modm::ResumableResult sendInitialGraphics(src::Drivers *drivers); + modm::ResumableResult update(); - modm::ResumableResult sendInitialGraphics(); - modm::ResumableResult update(); - - void initialize(); + void initialize(); }; namespace commands @@ -43,38 +42,26 @@ namespace commands class CommandClientDisplay : public Command, modm::pt::Protothread { private: - src::Drivers* drivers; - RefSerialTransmitter refSerialTransmitter; - BeybladeIndicator beybladeIndicator; - bool restarting = true; + src::Drivers *drivers; + RefSerialTransmitter refSerialTransmitter; + BeybladeIndicator beybladeIndicator; - void restartHud(); public: - CommandClientDisplay( - src::Drivers *drivers, - ChassisSubsystem *chassis) - : Command(), - drivers(drivers), - refSerialTransmitter(drivers), - beybladeIndicator(refSerialTransmitter) - { - addSubsystemRequirement(chassis); - } - - bool run(); - - const char *getName() const override { return "client display"; } - void initialize() override - { - tap::buzzer::playNote(&drivers->pwm, 880); - this->restarting = true; - }; + CommandClientDisplay(src::Drivers *drivers, FlywheelSubsystem *flywheel) + : Command(), + drivers(drivers), + refSerialTransmitter(drivers), + beybladeIndicator(refSerialTransmitter) + { + addSubsystemRequirement(flywheel); + } + + bool run(); - void execute() override - { - run(); - } - void end(bool) override {} - bool isFinished() const override { return false; } + void initialize() override; + void execute() override; + void end(bool) override; + bool isFinished() const override; + const char *getName() const override { return "client display"; } }; -} \ No newline at end of file +} // namespace commands \ No newline at end of file diff --git a/ut-robomaster/src/robots/standard/standard_control.hpp b/ut-robomaster/src/robots/standard/standard_control.hpp index d9aa5d20..651113e1 100644 --- a/ut-robomaster/src/robots/standard/standard_control.hpp +++ b/ut-robomaster/src/robots/standard/standard_control.hpp @@ -1,3 +1,4 @@ +#include "control/client-display/command_client_display.hpp" #include "robots/common/common_control_manual.hpp" #include "subsystems/agitator/command_agitator_continuous.hpp" @@ -15,6 +16,8 @@ class StandardControl : CommonControlManual drivers->commandMapper.addMap(&leftMouseDown); drivers->commandMapper.addMap(&leftSwitchUp); + + drivers->commandMapper.addMap(&hudTestKey); } private: @@ -29,6 +32,8 @@ class StandardControl : CommonControlManual BarrelId::STANDARD1, true}; + commands::CommandClientDisplay hudTest{drivers, &flywheel}; + // Mappings HoldCommandMapping leftMouseDown{ drivers, @@ -39,4 +44,6 @@ class StandardControl : CommonControlManual drivers, {&rotateAgitator_SwitchUp, &rotateFlywheel_SwitchMid}, RemoteMapState(Remote::Switch::LEFT_SWITCH, Remote::SwitchState::UP)}; + + HoldCommandMapping hudTestKey{drivers, {&hudTest}, RemoteMapState({Remote::Key::Q})}; }; \ No newline at end of file From 28b77bee7473b5b35fa142c55e131bd68549df63 Mon Sep 17 00:00:00 2001 From: Caleb Chalmers Date: Sun, 10 Nov 2024 01:24:41 +0000 Subject: [PATCH 04/13] Add basic working example that actually works --- .../client-display/command_client_display.cpp | 58 ++++++++----------- .../client-display/command_client_display.hpp | 33 +++-------- .../src/robots/standard/standard_control.hpp | 2 +- 3 files changed, 33 insertions(+), 60 deletions(-) diff --git a/ut-robomaster/src/control/client-display/command_client_display.cpp b/ut-robomaster/src/control/client-display/command_client_display.cpp index 0f5de75a..3e0c3dd4 100644 --- a/ut-robomaster/src/control/client-display/command_client_display.cpp +++ b/ut-robomaster/src/control/client-display/command_client_display.cpp @@ -1,58 +1,50 @@ #include "command_client_display.hpp" -modm::ResumableResult BeybladeIndicator::sendInitialGraphics(src::Drivers *drivers) +namespace commands { - // The number represents the index of the resumable function in this class - RF_BEGIN(0); - - tap::buzzer::playNote(&drivers->pwm, 880); - RF_CALL(refSerialTransmitter.sendGraphic(&msg)); - - RF_END(); -} -modm::ResumableResult BeybladeIndicator::update() +void CommandClientDisplay::initialize() { - // This is the second resumable function so its index is 1 - RF_BEGIN(1); - - RF_CALL(refSerialTransmitter.sendGraphic(&msg)); - - RF_END(); -} + tap::buzzer::playNote(&drivers->pwm, 440); + restart(); -void BeybladeIndicator::initialize() -{ RefSerialTransmitter::configGraphicGenerics( - &msg.graphicData[0], - graphicName, + &msg.graphicData, + graphicId, RefSerialData::Tx::GRAPHIC_ADD, - 1, // Graphic layer can be 0-9 + 0, RefSerialData::Tx::GraphicColor::PINK); - RefSerialTransmitter::configCircle(10, 400, 400, 200, &msg.graphicData[0]); -} -namespace commands -{ - -void CommandClientDisplay::initialize() -{ - beybladeIndicator.initialize(); - restart(); + // RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY + RefSerialTransmitter::configCircle(10, 1920 / 2, 1080 / 2, 100, &msg.graphicData); } void CommandClientDisplay::execute() { run(); } void CommandClientDisplay::end(bool) { tap::buzzer::silenceBuzzer(&drivers->pwm); } -bool CommandClientDisplay::isFinished() const { return !isRunning(); } +bool CommandClientDisplay::isFinished() const { return false; } bool CommandClientDisplay::run() { + float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 4.0f) * 0.5f + 0.5f; + PT_BEGIN(); PT_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); - PT_CALL(beybladeIndicator.sendInitialGraphics(drivers)); + + // setup new graphic (GRAPHIC_ADD operation) + PT_CALL(refSerialTransmitter.sendGraphic(&msg)); + + while (true) + { + msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; + msg.graphicData.lineWidth = 5.0f + 25.0f * t; + msg.graphicData.radius = 100.0f + 300.0f * t; + + // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) + PT_CALL(refSerialTransmitter.sendGraphic(&msg)); + } PT_END(); } diff --git a/ut-robomaster/src/control/client-display/command_client_display.hpp b/ut-robomaster/src/control/client-display/command_client_display.hpp index 15d519bf..c6593f59 100644 --- a/ut-robomaster/src/control/client-display/command_client_display.hpp +++ b/ut-robomaster/src/control/client-display/command_client_display.hpp @@ -18,40 +18,15 @@ using namespace tap::communication::serial; using subsystems::control::ClientDisplaySubsystem; using subsystems::flywheel::FlywheelSubsystem; -class BeybladeIndicator : protected modm::Resumable<2> -{ -private: - const uint8_t *graphicName = (uint8_t *)"\x00\x00\x01"; - RefSerialTransmitter &refSerialTransmitter; - RefSerialData::Tx::Graphic5Message msg; - -public: - BeybladeIndicator(RefSerialTransmitter refSerialTransmitter) - : refSerialTransmitter(refSerialTransmitter) - { - } - - modm::ResumableResult sendInitialGraphics(src::Drivers *drivers); - modm::ResumableResult update(); - - void initialize(); -}; - namespace commands { class CommandClientDisplay : public Command, modm::pt::Protothread { -private: - src::Drivers *drivers; - RefSerialTransmitter refSerialTransmitter; - BeybladeIndicator beybladeIndicator; - public: CommandClientDisplay(src::Drivers *drivers, FlywheelSubsystem *flywheel) : Command(), drivers(drivers), - refSerialTransmitter(drivers), - beybladeIndicator(refSerialTransmitter) + refSerialTransmitter(drivers) { addSubsystemRequirement(flywheel); } @@ -63,5 +38,11 @@ class CommandClientDisplay : public Command, modm::pt::Protothread void end(bool) override; bool isFinished() const override; const char *getName() const override { return "client display"; } + +private: + src::Drivers *drivers; + RefSerialTransmitter refSerialTransmitter; + const uint8_t graphicId[3] = {0, 0, 1}; // 3 byte identifier for this graphic element + RefSerialData::Tx::Graphic1Message msg; }; } // namespace commands \ No newline at end of file diff --git a/ut-robomaster/src/robots/standard/standard_control.hpp b/ut-robomaster/src/robots/standard/standard_control.hpp index 651113e1..02d43400 100644 --- a/ut-robomaster/src/robots/standard/standard_control.hpp +++ b/ut-robomaster/src/robots/standard/standard_control.hpp @@ -45,5 +45,5 @@ class StandardControl : CommonControlManual {&rotateAgitator_SwitchUp, &rotateFlywheel_SwitchMid}, RemoteMapState(Remote::Switch::LEFT_SWITCH, Remote::SwitchState::UP)}; - HoldCommandMapping hudTestKey{drivers, {&hudTest}, RemoteMapState({Remote::Key::Q})}; + HoldCommandMapping hudTestKey{drivers, {&hudTest}, RemoteMapState({Remote::Key::Z})}; }; \ No newline at end of file From e2002949dfdde347033db6e21d3f943f5fcd4a76 Mon Sep 17 00:00:00 2001 From: tonychen5427 Date: Wed, 20 Nov 2024 06:34:50 +0000 Subject: [PATCH 05/13] reticle display prototype --- .../client-display/reticle_display.cpp | 56 ++++++++++++++++++ .../client-display/reticle_display.hpp | 53 +++++++++++++++++ .../turret/command_move_turret_aimbot.cpp | 7 ++- .../subsystems/turret/turret_subsystem.cpp | 58 ++++++++++++++++++- .../subsystems/turret/turret_subsystem.hpp | 6 +- 5 files changed, 174 insertions(+), 6 deletions(-) create mode 100644 ut-robomaster/src/control/client-display/reticle_display.cpp create mode 100644 ut-robomaster/src/control/client-display/reticle_display.hpp diff --git a/ut-robomaster/src/control/client-display/reticle_display.cpp b/ut-robomaster/src/control/client-display/reticle_display.cpp new file mode 100644 index 00000000..0c41afe1 --- /dev/null +++ b/ut-robomaster/src/control/client-display/reticle_display.cpp @@ -0,0 +1,56 @@ +#include "reticle_display.hpp" + +namespace commands +{ + +void reticle_display::initialize() +{ + restart(); + + RefSerialTransmitter::configGraphicGenerics( + &msg.graphicData, + graphicId, + RefSerialData::Tx::GRAPHIC_ADD, + 0, + RefSerialData::Tx::GraphicColor::PINK); + + // RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY + RefSerialTransmitter::configCircle( + 10, CENTER_X, + CENTER_Y, + CIRCLE_SIZE, + &msg.graphicData); +} + +void reticle_display::execute() { run(); } + +void reticle_display::end(bool) { }//tap::buzzer::silenceBuzzer(&drivers->pwm); } + +bool reticle_display::isFinished() const { return false; } + +bool reticle_display::run() +{ + //float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 4.0f) * 0.5f + 0.5f; + + PT_BEGIN(); + + PT_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); + + // setup new graphic (GRAPHIC_ADD operation) + PT_CALL(refSerialTransmitter.sendGraphic(&msg)); + + while (true) + { + // msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; + // msg.graphicData.lineWidth = 5.0f + 25.0f * t; + // msg.graphicData.radius = 100.0f + 300.0f * t; + // DROP_DISTANCE = this.turret.getBulletDropReticle(); + msg.graphicData.startY = CENTER_Y-turret->getBulletDropReticle();; //startY is centerY + + // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) + PT_CALL(refSerialTransmitter.sendGraphic(&msg)); + } + + PT_END(); +} +} // namespace commands \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/reticle_display.hpp b/ut-robomaster/src/control/client-display/reticle_display.hpp new file mode 100644 index 00000000..89214438 --- /dev/null +++ b/ut-robomaster/src/control/client-display/reticle_display.hpp @@ -0,0 +1,53 @@ +#include "tap/communication/referee/state_hud_indicator.hpp" +#include "tap/communication/serial/ref_serial.hpp" +#include "tap/control/command.hpp" +#include "modm/processing/resumable.hpp" +#include "subsystems/turret/turret_subsystem.hpp" + +#include "client_display_subsystem.hpp" + +using namespace tap::control; +using namespace tap::communication::serial; + +using subsystems::control::ClientDisplaySubsystem; +using subsystems::turret::TurretSubsystem; + +namespace commands +{ +class reticle_display : public Command, modm::pt::Protothread +{ +public: + reticle_display(src::Drivers *drivers, TurretSubsystem *turret) + : Command(), + drivers(drivers), + refSerialTransmitter(drivers), + turret(turret) + { + addSubsystemRequirement(turret); + } + + bool run(); + + void initialize() override; + void execute() override; + void end(bool) override; + bool isFinished() const override; + const char *getName() const override { return "client display"; } + +private: + src::Drivers *drivers; + TurretSubsystem *turret; + RefSerialTransmitter refSerialTransmitter; + const uint8_t graphicId[3] = {1, 0, 1}; // 3 byte identifier for this graphic element + RefSerialData::Tx::Graphic1Message msg; + + static constexpr uint16_t CENTER_X = 1920 / 2; + static constexpr uint16_t CENTER_Y = 1080 / 2; + static constexpr uint16_t CIRCLE_SIZE = 10; + + // static int DROP_DISTANCE = 0; + + +}; + +} \ No newline at end of file diff --git a/ut-robomaster/src/subsystems/turret/command_move_turret_aimbot.cpp b/ut-robomaster/src/subsystems/turret/command_move_turret_aimbot.cpp index 18befc57..3c8792fe 100644 --- a/ut-robomaster/src/subsystems/turret/command_move_turret_aimbot.cpp +++ b/ut-robomaster/src/subsystems/turret/command_move_turret_aimbot.cpp @@ -30,7 +30,7 @@ void CommandMoveTurretAimbot::execute() Vector3f targetVel(data.xVel, data.zVel, data.yVel); Vector3f targetAcc(data.xAcc, data.zAcc, data.yAcc); - if (USE_BALLISTICS) + if (USE_BALLISTICS) // use ballistics to adjust turret pitch { // Rotate to world relative pitch float a = turret->getCurrentLocalPitch(); @@ -61,8 +61,9 @@ void CommandMoveTurretAimbot::execute() turret->setTargetWorldAngles(currentWorldYaw + turretYaw, turretPitch); } } - else - { + else // auto aim + { + // find the angle error based on target position from vision float deltaYaw = -atan(targetPos.x / targetPos.y); // yaw is opposite to camera X float deltaPitch = atan(targetPos.z / targetPos.y); float scale = 0.006f; diff --git a/ut-robomaster/src/subsystems/turret/turret_subsystem.cpp b/ut-robomaster/src/subsystems/turret/turret_subsystem.cpp index 9d770935..83c64594 100644 --- a/ut-robomaster/src/subsystems/turret/turret_subsystem.cpp +++ b/ut-robomaster/src/subsystems/turret/turret_subsystem.cpp @@ -61,11 +61,13 @@ void TurretSubsystem::refresh() } } -void TurretSubsystem::inputTargetData(Vector3f position, Vector3f velocity, Vector3f acceleration) +void TurretSubsystem::inputTargetData(Vector3f position, Vector3f velocity, Vector3f acceleration, float distance) { targetPosition = position; targetVelocity = velocity; targetAcceleration = acceleration; + if(distance<5.0) centerDistance = distance; + else centerDistance = 0.0f; } void TurretSubsystem::setTargetWorldAngles(float yaw, float pitch) @@ -90,6 +92,58 @@ float TurretSubsystem::getCurrentLocalPitch() return !isCalibrated ? 0.0f : pitch.getAngle() / PITCH_REDUCTION - basePitch; } +float TurretSubsystem::getBulletDropReticle(){ + if (centerDistance <= 0.1f) return 0; + /* bullet drop based on target position + Vector3f targetPos( + data.xPos + CAMERA_X_OFFSET, + data.zPos + CAMERA_TO_PITCH, + data.yPos + CAMERA_TO_BARRELS); + Vector3f targetVel(data.xVel, data.zVel, data.yVel); + Vector3f targetAcc(data.xAcc, data.zAcc, data.yAcc); + + // Rotate to world relative pitch + float a = turret->getCurrentLocalPitch(); + const float matData[9] = {1.0f, 0, 0, 0, cos(a), -sin(a), 0, sin(a), cos(a)}; + modm::Matrix3f rotMat(matData); + targetPos = rotMat * targetPos; + targetVel = rotMat * targetVel; + targetAcc = rotMat * targetAcc; + + MeasuredKinematicState kinState{targetPos, targetVel, targetAcc}; + + float turretPitch = 0.0f; + float turretYaw = 0.0f; + float travelTime = 0.0f; + + bool projectileTime = computeTravelTime( + kinState, + TARGET_PROJECTILE_VELOCITY, + BALLISTIC_ITERATIONS, + &turretPitch, + &turretYaw, + &travelTime, + -NOZZLE_TO_PITCH); + */ + + // physical distance = 0.5*9.8*powf(travelTime, 2) + // angle from turret = atan(hdrop/d) + float travelTime = centerDistance/TARGET_PROJECTILE_VELOCITY; + float dropDistance = 0.5*9.8*powf(travelTime, 2); + // float targetDistance = hypot(targetPos.x, targetPos.y) - NOZZLE_TO_PITCH; + float reticleDistance = atan(dropDistance/centerDistance); + // linear interpolation. simple, but it is less effective the more distorted the camera is + // 80, guess for vertical angle range. 720, number of pixels in vertical direction + float cameraAnglePixelScale = 80/720; // idk what the actual camera fov is, software didn't know and we can change it + + //number of pixels below current camera position + return reticleDistance*cameraAnglePixelScale+NOZZLE_TO_PITCH; // target pitch - current pitch = bullet drop over distance? + // } // i'm assuming that the camera is pointed above the turret + + // return 0; +} + + bool TurretSubsystem::getIsCalibrated() { return isCalibrated; } void TurretSubsystem::runHardwareTests() @@ -97,4 +151,4 @@ void TurretSubsystem::runHardwareTests() // TODO } } // namespace turret -} // namespace subsystems \ No newline at end of file +} // namespace subsystems diff --git a/ut-robomaster/src/subsystems/turret/turret_subsystem.hpp b/ut-robomaster/src/subsystems/turret/turret_subsystem.hpp index e793836f..9270912a 100644 --- a/ut-robomaster/src/subsystems/turret/turret_subsystem.hpp +++ b/ut-robomaster/src/subsystems/turret/turret_subsystem.hpp @@ -28,7 +28,7 @@ class TurretSubsystem : public tap::control::Subsystem void initialize() override; /// @brief Input target data from CV (relative to camera) - void inputTargetData(Vector3f position, Vector3f velocity, Vector3f acceleration); + void inputTargetData(Vector3f position, Vector3f velocity, Vector3f acceleration, float centerDistance); void setTargetWorldAngles(float yaw, float pitch); @@ -46,6 +46,8 @@ class TurretSubsystem : public tap::control::Subsystem float getCurrentLocalPitch(); + float getBulletDropReticle(); + bool getIsCalibrated(); void refresh() override; @@ -64,6 +66,8 @@ class TurretSubsystem : public tap::control::Subsystem Vector3f targetVelocity = Vector3f(0.0f); Vector3f targetAcceleration = Vector3f(0.0f); + float centerDistance = 0.0f; + #if defined(TARGET_STANDARD) || defined(TARGET_HERO) As5600 yawEncoder; DoubleYawMotor yaw; From 72c04addec58913ec6ebe1615868c10bcea1aaa1 Mon Sep 17 00:00:00 2001 From: vinle0 Date: Sat, 23 Nov 2024 00:08:15 +0000 Subject: [PATCH 06/13] Made an abstract class interface properly with HUD, currently a circle --- .../client_display_subsystem.cpp | 19 +++++- .../client_display_subsystem.hpp | 24 ++++++- .../client-display/command_client_display.cpp | 64 ++++++++++++------- .../client-display/command_client_display.hpp | 35 ++++++++-- .../graphics/graphic_abstract.hpp | 41 ++++++++++++ .../graphics/graphic_circle.hpp | 49 ++++++++++++++ .../graphics/graphic_flywheel_on.hpp | 64 +++++++++++++++++++ .../graphics/graphic_reticle.hpp | 62 ++++++++++++++++++ .../client-display/reticle_display.hpp | 2 +- .../src/robots/standard/standard_control.hpp | 4 +- .../taproot/src/tap/control/command.hpp | 1 + 11 files changed, 332 insertions(+), 33 deletions(-) create mode 100644 ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp create mode 100644 ut-robomaster/src/control/client-display/graphics/graphic_circle.hpp create mode 100644 ut-robomaster/src/control/client-display/graphics/graphic_flywheel_on.hpp create mode 100644 ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp diff --git a/ut-robomaster/src/control/client-display/client_display_subsystem.cpp b/ut-robomaster/src/control/client-display/client_display_subsystem.cpp index 792fae33..3ad57f7c 100644 --- a/ut-robomaster/src/control/client-display/client_display_subsystem.cpp +++ b/ut-robomaster/src/control/client-display/client_display_subsystem.cpp @@ -4,9 +4,24 @@ namespace subsystems::control { -ClientDisplaySubsystem::ClientDisplaySubsystem(tap::Drivers *drivers) : Subsystem(drivers) {} +ClientDisplaySubsystem::ClientDisplaySubsystem(src::Drivers* drivers, TurretSubsystem* turret) + : Subsystem(drivers), + drivers(drivers), + turret(turret), + currentGraphics(drivers) +{ +} -void ClientDisplaySubsystem::initialize() {} +void ClientDisplaySubsystem::initialize() +{ + // graphic::graphic_circle circle2(drivers); + // graphic::graphic_circle* circle = new graphic::graphic_circle(drivers); + // graphic::graphic_reticle* reticle = new graphic::graphic_reticle(drivers, turret); + // currentGraphics.emplace_back(circle); + // currentGraphics = circle2; + // currentGraphics = reticle; + *numGraphics = 2; +} void ClientDisplaySubsystem::refresh() {} diff --git a/ut-robomaster/src/control/client-display/client_display_subsystem.hpp b/ut-robomaster/src/control/client-display/client_display_subsystem.hpp index 055f3ea6..fc9e0605 100644 --- a/ut-robomaster/src/control/client-display/client_display_subsystem.hpp +++ b/ut-robomaster/src/control/client-display/client_display_subsystem.hpp @@ -1,24 +1,46 @@ #pragma once +#include + #include "tap/communication/sensors/buzzer/buzzer.hpp" #include "tap/control/command.hpp" #include "tap/control/subsystem.hpp" +#include "control/client-display/graphics/graphic_abstract.hpp" +#include "control/client-display/graphics/graphic_circle.hpp" +#include "control/client-display/graphics/graphic_reticle.hpp" +#include "subsystems/turret/turret_subsystem.hpp" + #include "drivers.hpp" +using subsystems::turret::TurretSubsystem; + namespace subsystems::control { class ClientDisplaySubsystem : public tap::control::Subsystem { public: - ClientDisplaySubsystem(tap::Drivers*); + ClientDisplaySubsystem(src::Drivers*, TurretSubsystem* turret); + // add graphics desired here void initialize() override; void refresh() override; + // function to get the vector of graphics + // std::vector getGraphics() {return currentGraphics;}; + graphic::graphic_abstract* getGraphics() { return ¤tGraphics; }; + void runHardwareTests() override; const char* getName() override { return "Client Display subsystem"; } + +private: + // std::vector currentGraphics; + graphic::graphic_abstract* graphics[10]; + uint8_t* numGraphics; + src::Drivers* drivers; + TurretSubsystem* turret; + graphic::graphic_circle currentGraphics; }; } // namespace subsystems::control \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/command_client_display.cpp b/ut-robomaster/src/control/client-display/command_client_display.cpp index 3e0c3dd4..a05cf574 100644 --- a/ut-robomaster/src/control/client-display/command_client_display.cpp +++ b/ut-robomaster/src/control/client-display/command_client_display.cpp @@ -6,45 +6,65 @@ namespace commands void CommandClientDisplay::initialize() { tap::buzzer::playNote(&drivers->pwm, 440); - restart(); + // restart(); - RefSerialTransmitter::configGraphicGenerics( - &msg.graphicData, - graphicId, - RefSerialData::Tx::GRAPHIC_ADD, - 0, - RefSerialData::Tx::GraphicColor::PINK); + // RefSerialTransmitter::configGraphicGenerics( + // &msg.graphicData, + // graphicId, + // RefSerialData::Tx::GRAPHIC_ADD, + // 0, + // RefSerialData::Tx::GraphicColor::PINK); - // RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY - RefSerialTransmitter::configCircle(10, 1920 / 2, 1080 / 2, 100, &msg.graphicData); + // // RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY + // RefSerialTransmitter::configCircle(10, 1920 / 2, 1080 / 2, 100, &msg.graphicData); + // std::vector currentGraphics = client->getGraphics(); + // for (graphic::graphic_abstract* graphic : currentGraphics) + // { + // graphic->initialize(); + // } + + graphic = client->getGraphics(); + graphic->initialize(); } void CommandClientDisplay::execute() { run(); } -void CommandClientDisplay::end(bool) { tap::buzzer::silenceBuzzer(&drivers->pwm); } +void CommandClientDisplay::end(bool) +{ + tap::buzzer::silenceBuzzer(&drivers->pwm); +} bool CommandClientDisplay::isFinished() const { return false; } bool CommandClientDisplay::run() { - float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 4.0f) * 0.5f + 0.5f; + // float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 4.0f) * 0.5f + 0.5f; + // graphic = client->getGraphics(); PT_BEGIN(); - PT_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); + // PT_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); + + // // setup new graphic (GRAPHIC_ADD operation) + // PT_CALL(refSerialTransmitter.sendGraphic(&msg)); - // setup new graphic (GRAPHIC_ADD operation) - PT_CALL(refSerialTransmitter.sendGraphic(&msg)); + // while (true) + // { + // msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; + // msg.graphicData.lineWidth = 5.0f + 25.0f * t; + // msg.graphicData.radius = 100.0f + 300.0f * t; - while (true) - { - msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; - msg.graphicData.lineWidth = 5.0f + 25.0f * t; - msg.graphicData.radius = 100.0f + 300.0f * t; + // // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) + // PT_CALL(refSerialTransmitter.sendGraphic(&msg)); + // } - // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) - PT_CALL(refSerialTransmitter.sendGraphic(&msg)); - } + // PT_END(); + // std::vector currentGraphics = client->getGraphics(); + // for (graphic::graphic_abstract* graphic : currentGraphics) + // { + // graphic->run(); + // } + PT_CALL(graphic->run()); PT_END(); } diff --git a/ut-robomaster/src/control/client-display/command_client_display.hpp b/ut-robomaster/src/control/client-display/command_client_display.hpp index c6593f59..c50dd38d 100644 --- a/ut-robomaster/src/control/client-display/command_client_display.hpp +++ b/ut-robomaster/src/control/client-display/command_client_display.hpp @@ -1,11 +1,14 @@ #pragma once +#include #include "tap/communication/sensors/buzzer/buzzer.hpp" #include "tap/communication/serial/ref_serial_data.hpp" #include "tap/communication/serial/ref_serial_transmitter.hpp" #include "tap/control/command.hpp" #include "control/client-display/client_display_subsystem.hpp" +#include "control/client-display/graphics/graphic_abstract.hpp" + #include "modm/processing/protothread.hpp" #include "modm/processing/resumable.hpp" #include "subsystems/flywheel/flywheel_subsystem.hpp" @@ -23,12 +26,13 @@ namespace commands class CommandClientDisplay : public Command, modm::pt::Protothread { public: - CommandClientDisplay(src::Drivers *drivers, FlywheelSubsystem *flywheel) + CommandClientDisplay(src::Drivers *drivers, ClientDisplaySubsystem* client) : Command(), drivers(drivers), - refSerialTransmitter(drivers) + // refSerialTransmitter(drivers), + client(client) { - addSubsystemRequirement(flywheel); + addSubsystemRequirement(client); } bool run(); @@ -39,10 +43,29 @@ class CommandClientDisplay : public Command, modm::pt::Protothread bool isFinished() const override; const char *getName() const override { return "client display"; } + //Plan to make a new class, called graphic + //in it, there contains virtual functions + //initialize, run (PT threads) + //within each of the derived classes, there would be a refSerialTransmitter + //also the corresponding subsystem to get the proper infomation + + //then only one command to call on the list of derived graphics, initialize all of them, run all of them + //I think it should be a vector of classes? + + //1. Make Graphic class, derived class + //2. Create a vector of these classes within the subsystem initialize (not command), revert this command into subsystem with client_display() + //3. Within this command, it should now have complete vector of the graphics, and corresponding calls the initalize, and run functions (execute) + + //Possibility to create a command to hide graphics? + private: + src::Drivers *drivers; - RefSerialTransmitter refSerialTransmitter; - const uint8_t graphicId[3] = {0, 0, 1}; // 3 byte identifier for this graphic element - RefSerialData::Tx::Graphic1Message msg; + ClientDisplaySubsystem* client; + graphic::graphic_abstract* graphic; + // RefSerialTransmitter refSerialTransmitter; + // const uint8_t graphicId[3] = {0, 0, 1}; // 3 byte identifier for this graphic element + // RefSerialData::Tx::Graphic1Message msg; + }; } // namespace commands \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp new file mode 100644 index 00000000..82052659 --- /dev/null +++ b/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp @@ -0,0 +1,41 @@ +#pragma once +#include "tap/communication/serial/ref_serial_data.hpp" +#include "tap/communication/serial/ref_serial_transmitter.hpp" +#include "tap/control/command.hpp" + +#include "modm/processing/protothread.hpp" +#include "modm/processing/resumable.hpp" + +#include "drivers.hpp" + +using namespace tap::communication::serial; +using modm::NestedResumable; +using modm::ResumableResult; + +namespace graphic +{ + +class graphic_abstract : protected NestedResumable<2> +{ +public: + graphic_abstract(src::Drivers* drivers, uint8_t id) + : drivers(drivers), + refSerialTransmitter(drivers) + { + graphicId[0] = id & 0x01; + graphicId[1] = id & 0x02; + graphicId[2] = id & 0x04; + }; + virtual void initialize() = 0; + virtual ResumableResult run() = 0; + + // virtual ~graphic_abstract(); + +protected: + src::Drivers* drivers; + RefSerialTransmitter refSerialTransmitter; + uint8_t graphicId[3]; // 3 byte identifier for this graphic element + RefSerialData::Tx::Graphic1Message msg; +}; + +} // namespace graphic \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_circle.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_circle.hpp new file mode 100644 index 00000000..d5d1988c --- /dev/null +++ b/ut-robomaster/src/control/client-display/graphics/graphic_circle.hpp @@ -0,0 +1,49 @@ +#pragma once +#include "graphic_abstract.hpp" + +namespace graphic +{ + +class graphic_circle : public graphic_abstract +{ +public: + graphic_circle(src::Drivers *drivers) : graphic_abstract(drivers, 1) {}; + void initialize() override + { + // restart(); + RefSerialTransmitter::configGraphicGenerics( + &msg.graphicData, + graphicId, + RefSerialData::Tx::GRAPHIC_ADD, + 0, + RefSerialData::Tx::GraphicColor::PINK); + + RefSerialTransmitter::configCircle(10, 1920 / 2, 1080 / 2, 100, &msg.graphicData); + }; + + modm::ResumableResult run() override + { + float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 4.0f) * 0.5f + 0.5f; + RF_BEGIN(); + + RF_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); + // // setup new graphic (GRAPHIC_ADD operation) + RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + while (true) + { + msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; + msg.graphicData.lineWidth = 5.0f + 25.0f * t; + msg.graphicData.radius = 100.0f + 300.0f * t; + + // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) + RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + } + + RF_END_RETURN(true); + }; + +private: + float t = 10.0; +}; + +} // namespace graphic \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_flywheel_on.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_flywheel_on.hpp new file mode 100644 index 00000000..ded34dfb --- /dev/null +++ b/ut-robomaster/src/control/client-display/graphics/graphic_flywheel_on.hpp @@ -0,0 +1,64 @@ +#pragma once + +#include "graphic_abstract.hpp" +#include "subsystems/flywheel/flywheel_subsystem.hpp" + +using subsystems::flywheel::FlywheelSubsystem; +using tap::communication::serial::RefSerialData; +namespace graphic +{ + +class graphic_flywheel_on : public graphic_abstract +{ +public: + graphic_flywheel_on(src::Drivers *drivers, FlywheelSubsystem *flywheel) + : graphic_abstract(drivers, 2), flywheel(flywheel) {}; + void initialize() override + { + // restart(); + + RefSerialTransmitter::configGraphicGenerics( + &word_msg.graphicData, + graphicId, + RefSerialData::Tx::GRAPHIC_ADD, + 0, + RefSerialData::Tx::GraphicColor::CYAN); + + // RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY + // RefSerialTransmitter::configCircle(10, CENTER_X, CENTER_Y, CIRCLE_SIZE, &msg.graphicData); + + RefSerialTransmitter::configCharacterMsg(100, 10, CENTER_X, CENTER_Y, "Flywheel on", &word_msg); + }; + + modm::ResumableResult run() override + { + RF_BEGIN(); + + RF_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); + + // setup new graphic (GRAPHIC_ADD operation) + RF_CALL(refSerialTransmitter.sendGraphic(&word_msg)); + + while (true) + { + // msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; + // msg.graphicData.lineWidth = 5.0f + 25.0f * t; + // msg.graphicData.radius = 100.0f + 300.0f * t; + // DROP_DISTANCE = this.turret.getBulletDropReticle(); + // msg.graphicData.startY = CENTER_Y - turret->getBulletDropReticle(); + ; // startY is centerY + + // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) + // RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + } + RF_END_RETURN(true); + }; + +private: + static constexpr uint16_t CENTER_X = 1920 / 4; + static constexpr uint16_t CENTER_Y = 1080 / 4; + RefSerialData::Tx::GraphicCharacterMessage word_msg; + FlywheelSubsystem* flywheel; +}; + +} // namespace graphic \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp new file mode 100644 index 00000000..f8d34130 --- /dev/null +++ b/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp @@ -0,0 +1,62 @@ +#pragma once + +#include "graphic_abstract.hpp" +#include "subsystems/turret/turret_subsystem.hpp" + +using subsystems::turret::TurretSubsystem; +namespace graphic +{ + +class graphic_reticle : public graphic_abstract +{ +public: + graphic_reticle(src::Drivers *drivers, TurretSubsystem *turret) + : graphic_abstract(drivers, 2), + turret(turret) {}; + void initialize() override + { + // restart(); + + RefSerialTransmitter::configGraphicGenerics( + &msg.graphicData, + graphicId, + RefSerialData::Tx::GRAPHIC_ADD, + 0, + RefSerialData::Tx::GraphicColor::PINK); + + // RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY + RefSerialTransmitter::configCircle(10, CENTER_X, CENTER_Y, CIRCLE_SIZE, &msg.graphicData); + }; + + modm::ResumableResult run() override + { + RF_BEGIN(); + + RF_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); + + // setup new graphic (GRAPHIC_ADD operation) + RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + + while (true) + { + // msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; + // msg.graphicData.lineWidth = 5.0f + 25.0f * t; + // msg.graphicData.radius = 100.0f + 300.0f * t; + // DROP_DISTANCE = this.turret.getBulletDropReticle(); + msg.graphicData.startY = CENTER_Y - turret->getBulletDropReticle(); + ; // startY is centerY + + // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) + RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + } + RF_END_RETURN(true); + }; + +private: + static constexpr uint16_t CENTER_X = 1920 / 2; + static constexpr uint16_t CENTER_Y = 1080 / 2; + static constexpr uint16_t CIRCLE_SIZE = 10; + TurretSubsystem *turret; +}; + +} // namespace graphic \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/reticle_display.hpp b/ut-robomaster/src/control/client-display/reticle_display.hpp index 89214438..6464445b 100644 --- a/ut-robomaster/src/control/client-display/reticle_display.hpp +++ b/ut-robomaster/src/control/client-display/reticle_display.hpp @@ -36,8 +36,8 @@ class reticle_display : public Command, modm::pt::Protothread private: src::Drivers *drivers; - TurretSubsystem *turret; RefSerialTransmitter refSerialTransmitter; + TurretSubsystem *turret; const uint8_t graphicId[3] = {1, 0, 1}; // 3 byte identifier for this graphic element RefSerialData::Tx::Graphic1Message msg; diff --git a/ut-robomaster/src/robots/standard/standard_control.hpp b/ut-robomaster/src/robots/standard/standard_control.hpp index 02d43400..39c9d1c4 100644 --- a/ut-robomaster/src/robots/standard/standard_control.hpp +++ b/ut-robomaster/src/robots/standard/standard_control.hpp @@ -13,6 +13,7 @@ class StandardControl : CommonControlManual agitator.initialize(); drivers->commandScheduler.registerSubsystem(&agitator); + drivers->commandScheduler.registerSubsystem(&client); drivers->commandMapper.addMap(&leftMouseDown); drivers->commandMapper.addMap(&leftSwitchUp); @@ -23,6 +24,7 @@ class StandardControl : CommonControlManual private: // Subsystems AgitatorSubsystem agitator{drivers, &flywheel, AGITATOR}; + ClientDisplaySubsystem client{drivers, &turret}; // Commands CommandAgitatorContinuous rotateAgitator_LeftMouse{drivers, &agitator, BarrelId::STANDARD1}; @@ -32,7 +34,7 @@ class StandardControl : CommonControlManual BarrelId::STANDARD1, true}; - commands::CommandClientDisplay hudTest{drivers, &flywheel}; + commands::CommandClientDisplay hudTest{drivers, &client}; // Mappings HoldCommandMapping leftMouseDown{ diff --git a/ut-robomaster/taproot/src/tap/control/command.hpp b/ut-robomaster/taproot/src/tap/control/command.hpp index c8b84055..34e3b18a 100644 --- a/ut-robomaster/taproot/src/tap/control/command.hpp +++ b/ut-robomaster/taproot/src/tap/control/command.hpp @@ -1,3 +1,4 @@ +#include /*****************************************************************************/ /********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/ /*****************************************************************************/ From 234cc6766da1d1103ab44bc26905e003f95b3ef7 Mon Sep 17 00:00:00 2001 From: vinle0 Date: Fri, 7 Mar 2025 23:15:28 +0000 Subject: [PATCH 07/13] Attempt to modular the reticle and flywheel on graphic --- .../client_display_subsystem.cpp | 15 +++--- .../client_display_subsystem.hpp | 21 +++++--- .../client-display/command_client_display.cpp | 53 ++++--------------- .../client-display/command_client_display.hpp | 23 ++------ .../graphics/graphic_abstract.hpp | 4 +- .../graphics/graphic_circle.hpp | 3 +- .../graphics/graphic_flywheel_on.hpp | 34 ++++++++---- .../graphics/graphic_reticle.hpp | 27 ++++++---- .../src/robots/standard/standard_control.hpp | 2 +- 9 files changed, 79 insertions(+), 103 deletions(-) diff --git a/ut-robomaster/src/control/client-display/client_display_subsystem.cpp b/ut-robomaster/src/control/client-display/client_display_subsystem.cpp index 3ad57f7c..49476f46 100644 --- a/ut-robomaster/src/control/client-display/client_display_subsystem.cpp +++ b/ut-robomaster/src/control/client-display/client_display_subsystem.cpp @@ -4,23 +4,20 @@ namespace subsystems::control { -ClientDisplaySubsystem::ClientDisplaySubsystem(src::Drivers* drivers, TurretSubsystem* turret) +ClientDisplaySubsystem::ClientDisplaySubsystem(src::Drivers* drivers, TurretSubsystem* turret, FlywheelSubsystem* flywheel) : Subsystem(drivers), drivers(drivers), turret(turret), - currentGraphics(drivers) + flywheel(flywheel), + circle(drivers), + reticle(drivers, ClientDisplaySubsystem::turret), + flywheel_on(drivers, ClientDisplaySubsystem::flywheel) { } void ClientDisplaySubsystem::initialize() { - // graphic::graphic_circle circle2(drivers); - // graphic::graphic_circle* circle = new graphic::graphic_circle(drivers); - // graphic::graphic_reticle* reticle = new graphic::graphic_reticle(drivers, turret); - // currentGraphics.emplace_back(circle); - // currentGraphics = circle2; - // currentGraphics = reticle; - *numGraphics = 2; + *numGraphics = 3; } void ClientDisplaySubsystem::refresh() {} diff --git a/ut-robomaster/src/control/client-display/client_display_subsystem.hpp b/ut-robomaster/src/control/client-display/client_display_subsystem.hpp index fc9e0605..3f67d361 100644 --- a/ut-robomaster/src/control/client-display/client_display_subsystem.hpp +++ b/ut-robomaster/src/control/client-display/client_display_subsystem.hpp @@ -9,38 +9,45 @@ #include "control/client-display/graphics/graphic_abstract.hpp" #include "control/client-display/graphics/graphic_circle.hpp" #include "control/client-display/graphics/graphic_reticle.hpp" +#include "control/client-display/graphics/graphic_flywheel_on.hpp" + + #include "subsystems/turret/turret_subsystem.hpp" +#include "subsystems/flywheel/flywheel_subsystem.hpp" #include "drivers.hpp" using subsystems::turret::TurretSubsystem; +using subsystems::flywheel::FlywheelSubsystem; namespace subsystems::control { class ClientDisplaySubsystem : public tap::control::Subsystem { public: - ClientDisplaySubsystem(src::Drivers*, TurretSubsystem* turret); + ClientDisplaySubsystem(src::Drivers*, TurretSubsystem* turret, FlywheelSubsystem* flywheel); // add graphics desired here void initialize() override; void refresh() override; - // function to get the vector of graphics - // std::vector getGraphics() {return currentGraphics;}; - graphic::graphic_abstract* getGraphics() { return ¤tGraphics; }; + graphic::graphic_abstract* getCircle() { return &circle; }; + graphic::graphic_abstract* getReticle() { return &reticle; }; + graphic::graphic_abstract* getFlywheelOn() { return &flywheel_on; }; void runHardwareTests() override; const char* getName() override { return "Client Display subsystem"; } private: - // std::vector currentGraphics; - graphic::graphic_abstract* graphics[10]; uint8_t* numGraphics; src::Drivers* drivers; TurretSubsystem* turret; - graphic::graphic_circle currentGraphics; + FlywheelSubsystem* flywheel; + + graphic::graphic_circle circle; + graphic::graphic_reticle reticle; + graphic::graphic_flywheel_on flywheel_on; }; } // namespace subsystems::control \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/command_client_display.cpp b/ut-robomaster/src/control/client-display/command_client_display.cpp index a05cf574..2567d5a5 100644 --- a/ut-robomaster/src/control/client-display/command_client_display.cpp +++ b/ut-robomaster/src/control/client-display/command_client_display.cpp @@ -6,25 +6,14 @@ namespace commands void CommandClientDisplay::initialize() { tap::buzzer::playNote(&drivers->pwm, 440); - // restart(); - // RefSerialTransmitter::configGraphicGenerics( - // &msg.graphicData, - // graphicId, - // RefSerialData::Tx::GRAPHIC_ADD, - // 0, - // RefSerialData::Tx::GraphicColor::PINK); - - // // RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY - // RefSerialTransmitter::configCircle(10, 1920 / 2, 1080 / 2, 100, &msg.graphicData); - // std::vector currentGraphics = client->getGraphics(); - // for (graphic::graphic_abstract* graphic : currentGraphics) - // { - // graphic->initialize(); - // } - - graphic = client->getGraphics(); - graphic->initialize(); + circle = client->getCircle(); + reticle = client->getReticle(); + flywheel_on = client->getFlywheelOn(); + + circle->initialize(); + reticle->initialize(); + flywheel_on->initialize(); } void CommandClientDisplay::execute() { run(); } @@ -38,33 +27,11 @@ bool CommandClientDisplay::isFinished() const { return false; } bool CommandClientDisplay::run() { - // float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 4.0f) * 0.5f + 0.5f; - // graphic = client->getGraphics(); - PT_BEGIN(); - // PT_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); - - // // setup new graphic (GRAPHIC_ADD operation) - // PT_CALL(refSerialTransmitter.sendGraphic(&msg)); - - // while (true) - // { - // msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; - // msg.graphicData.lineWidth = 5.0f + 25.0f * t; - // msg.graphicData.radius = 100.0f + 300.0f * t; - - // // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) - // PT_CALL(refSerialTransmitter.sendGraphic(&msg)); - // } - - // PT_END(); - // std::vector currentGraphics = client->getGraphics(); - // for (graphic::graphic_abstract* graphic : currentGraphics) - // { - // graphic->run(); - // } - PT_CALL(graphic->run()); + // PT_CALL(circle->run()); + PT_CALL(reticle->run()); + PT_CALL(flywheel_on->run()); PT_END(); } diff --git a/ut-robomaster/src/control/client-display/command_client_display.hpp b/ut-robomaster/src/control/client-display/command_client_display.hpp index c50dd38d..ba481a45 100644 --- a/ut-robomaster/src/control/client-display/command_client_display.hpp +++ b/ut-robomaster/src/control/client-display/command_client_display.hpp @@ -29,7 +29,6 @@ class CommandClientDisplay : public Command, modm::pt::Protothread CommandClientDisplay(src::Drivers *drivers, ClientDisplaySubsystem* client) : Command(), drivers(drivers), - // refSerialTransmitter(drivers), client(client) { addSubsystemRequirement(client); @@ -43,29 +42,13 @@ class CommandClientDisplay : public Command, modm::pt::Protothread bool isFinished() const override; const char *getName() const override { return "client display"; } - //Plan to make a new class, called graphic - //in it, there contains virtual functions - //initialize, run (PT threads) - //within each of the derived classes, there would be a refSerialTransmitter - //also the corresponding subsystem to get the proper infomation - - //then only one command to call on the list of derived graphics, initialize all of them, run all of them - //I think it should be a vector of classes? - - //1. Make Graphic class, derived class - //2. Create a vector of these classes within the subsystem initialize (not command), revert this command into subsystem with client_display() - //3. Within this command, it should now have complete vector of the graphics, and corresponding calls the initalize, and run functions (execute) - - //Possibility to create a command to hide graphics? - private: src::Drivers *drivers; ClientDisplaySubsystem* client; - graphic::graphic_abstract* graphic; - // RefSerialTransmitter refSerialTransmitter; - // const uint8_t graphicId[3] = {0, 0, 1}; // 3 byte identifier for this graphic element - // RefSerialData::Tx::Graphic1Message msg; + graphic::graphic_abstract* circle; + graphic::graphic_abstract* reticle; + graphic::graphic_abstract* flywheel_on; }; } // namespace commands \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp index 82052659..61112de1 100644 --- a/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp +++ b/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp @@ -15,7 +15,7 @@ using modm::ResumableResult; namespace graphic { -class graphic_abstract : protected NestedResumable<2> +class graphic_abstract : protected NestedResumable<3> { public: graphic_abstract(src::Drivers* drivers, uint8_t id) @@ -36,6 +36,8 @@ class graphic_abstract : protected NestedResumable<2> RefSerialTransmitter refSerialTransmitter; uint8_t graphicId[3]; // 3 byte identifier for this graphic element RefSerialData::Tx::Graphic1Message msg; + RefSerialData::Tx::GraphicCharacterMessage word_msg; + }; } // namespace graphic \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_circle.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_circle.hpp index d5d1988c..794a824d 100644 --- a/ut-robomaster/src/control/client-display/graphics/graphic_circle.hpp +++ b/ut-robomaster/src/control/client-display/graphics/graphic_circle.hpp @@ -7,7 +7,8 @@ namespace graphic class graphic_circle : public graphic_abstract { public: - graphic_circle(src::Drivers *drivers) : graphic_abstract(drivers, 1) {}; + graphic_circle(src::Drivers *drivers) : + graphic_abstract(drivers, 1) {}; void initialize() override { // restart(); diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_flywheel_on.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_flywheel_on.hpp index ded34dfb..c48668cd 100644 --- a/ut-robomaster/src/control/client-display/graphics/graphic_flywheel_on.hpp +++ b/ut-robomaster/src/control/client-display/graphics/graphic_flywheel_on.hpp @@ -12,7 +12,8 @@ class graphic_flywheel_on : public graphic_abstract { public: graphic_flywheel_on(src::Drivers *drivers, FlywheelSubsystem *flywheel) - : graphic_abstract(drivers, 2), flywheel(flywheel) {}; + : graphic_abstract(drivers, 3), + flywheel(flywheel) {}; void initialize() override { // restart(); @@ -21,13 +22,12 @@ class graphic_flywheel_on : public graphic_abstract &word_msg.graphicData, graphicId, RefSerialData::Tx::GRAPHIC_ADD, - 0, - RefSerialData::Tx::GraphicColor::CYAN); + 2, + RefSerialData::Tx::GraphicColor::ORANGE); // RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY - // RefSerialTransmitter::configCircle(10, CENTER_X, CENTER_Y, CIRCLE_SIZE, &msg.graphicData); - - RefSerialTransmitter::configCharacterMsg(100, 10, CENTER_X, CENTER_Y, "Flywheel on", &word_msg); + const char* message = "Flywheel on"; + RefSerialTransmitter::configCharacterMsg(50, 10, CENTER_X, CENTER_Y, message, &word_msg); }; modm::ResumableResult run() override @@ -41,12 +41,25 @@ class graphic_flywheel_on : public graphic_abstract while (true) { - // msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; // msg.graphicData.lineWidth = 5.0f + 25.0f * t; // msg.graphicData.radius = 100.0f + 300.0f * t; // DROP_DISTANCE = this.turret.getBulletDropReticle(); // msg.graphicData.startY = CENTER_Y - turret->getBulletDropReticle(); - ; // startY is centerY + // startY is centerY + + word_msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; + RF_CALL(refSerialTransmitter.sendGraphic(&word_msg)); + + // if(flywheel->isActive()) + // { + // RF_CALL(refSerialTransmitter.sendGraphic(&word_msg)); + // } + // else + // { + // word_msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_DELETE; + // RF_CALL(refSerialTransmitter.sendGraphic(&word_msg)); + // } + // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) // RF_CALL(refSerialTransmitter.sendGraphic(&msg)); @@ -55,9 +68,8 @@ class graphic_flywheel_on : public graphic_abstract }; private: - static constexpr uint16_t CENTER_X = 1920 / 4; - static constexpr uint16_t CENTER_Y = 1080 / 4; - RefSerialData::Tx::GraphicCharacterMessage word_msg; + static constexpr uint16_t CENTER_X = 1920 / 3; + static constexpr uint16_t CENTER_Y = 1080 / 3; FlywheelSubsystem* flywheel; }; diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp index f8d34130..aac99270 100644 --- a/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp +++ b/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp @@ -15,14 +15,12 @@ class graphic_reticle : public graphic_abstract turret(turret) {}; void initialize() override { - // restart(); - RefSerialTransmitter::configGraphicGenerics( &msg.graphicData, graphicId, RefSerialData::Tx::GRAPHIC_ADD, - 0, - RefSerialData::Tx::GraphicColor::PINK); + 1, //1st layer + RefSerialData::Tx::GraphicColor::CYAN); // RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY RefSerialTransmitter::configCircle(10, CENTER_X, CENTER_Y, CIRCLE_SIZE, &msg.graphicData); @@ -30,6 +28,7 @@ class graphic_reticle : public graphic_abstract modm::ResumableResult run() override { + float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 4.0f) * 0.5f + 0.5f; RF_BEGIN(); RF_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); @@ -40,11 +39,19 @@ class graphic_reticle : public graphic_abstract while (true) { // msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; - // msg.graphicData.lineWidth = 5.0f + 25.0f * t; - // msg.graphicData.radius = 100.0f + 300.0f * t; - // DROP_DISTANCE = this.turret.getBulletDropReticle(); - msg.graphicData.startY = CENTER_Y - turret->getBulletDropReticle(); - ; // startY is centerY + // // msg.graphicData.lineWidth = 5.0f + 25.0f * t; + // // msg.graphicData.radius = 100.0f + 300.0f * t; + // // DROP_DISTANCE = this.turret.getBulletDropReticle(); + // msg.graphicData.startY = CENTER_Y - turret->getBulletDropReticle(); + // // startY is centerY + + // // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) + // RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + + + msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; + msg.graphicData.lineWidth = 5.0f + 25.0f * t; + msg.graphicData.radius = 100.0f + 300.0f * t; // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) RF_CALL(refSerialTransmitter.sendGraphic(&msg)); @@ -55,7 +62,7 @@ class graphic_reticle : public graphic_abstract private: static constexpr uint16_t CENTER_X = 1920 / 2; static constexpr uint16_t CENTER_Y = 1080 / 2; - static constexpr uint16_t CIRCLE_SIZE = 10; + static constexpr uint16_t CIRCLE_SIZE = 100; TurretSubsystem *turret; }; diff --git a/ut-robomaster/src/robots/standard/standard_control.hpp b/ut-robomaster/src/robots/standard/standard_control.hpp index 39c9d1c4..2930efba 100644 --- a/ut-robomaster/src/robots/standard/standard_control.hpp +++ b/ut-robomaster/src/robots/standard/standard_control.hpp @@ -24,7 +24,7 @@ class StandardControl : CommonControlManual private: // Subsystems AgitatorSubsystem agitator{drivers, &flywheel, AGITATOR}; - ClientDisplaySubsystem client{drivers, &turret}; + ClientDisplaySubsystem client{drivers, &turret, &flywheel}; // Commands CommandAgitatorContinuous rotateAgitator_LeftMouse{drivers, &agitator, BarrelId::STANDARD1}; From 25fb4a950a8f2407b8e7029771bf9fc9d8d6f13c Mon Sep 17 00:00:00 2001 From: Caleb Chalmers Date: Sat, 8 Mar 2025 01:40:23 +0000 Subject: [PATCH 08/13] Reorganized to enable multiple HUD elements --- .../client_display_subsystem.hpp | 14 ++-- .../client-display/command_client_display.cpp | 28 ++++--- .../client-display/command_client_display.hpp | 11 ++- .../graphics/graphic_abstract.hpp | 12 +-- .../graphics/graphic_circle.hpp | 30 ++++---- .../graphics/graphic_flywheel_on.hpp | 75 ++++++++++--------- .../graphics/graphic_reticle.hpp | 54 ++++++------- 7 files changed, 113 insertions(+), 111 deletions(-) diff --git a/ut-robomaster/src/control/client-display/client_display_subsystem.hpp b/ut-robomaster/src/control/client-display/client_display_subsystem.hpp index 3f67d361..d2d91993 100644 --- a/ut-robomaster/src/control/client-display/client_display_subsystem.hpp +++ b/ut-robomaster/src/control/client-display/client_display_subsystem.hpp @@ -8,17 +8,15 @@ #include "control/client-display/graphics/graphic_abstract.hpp" #include "control/client-display/graphics/graphic_circle.hpp" -#include "control/client-display/graphics/graphic_reticle.hpp" #include "control/client-display/graphics/graphic_flywheel_on.hpp" - - -#include "subsystems/turret/turret_subsystem.hpp" +#include "control/client-display/graphics/graphic_reticle.hpp" #include "subsystems/flywheel/flywheel_subsystem.hpp" +#include "subsystems/turret/turret_subsystem.hpp" #include "drivers.hpp" -using subsystems::turret::TurretSubsystem; using subsystems::flywheel::FlywheelSubsystem; +using subsystems::turret::TurretSubsystem; namespace subsystems::control { @@ -46,8 +44,8 @@ class ClientDisplaySubsystem : public tap::control::Subsystem TurretSubsystem* turret; FlywheelSubsystem* flywheel; - graphic::graphic_circle circle; - graphic::graphic_reticle reticle; - graphic::graphic_flywheel_on flywheel_on; + graphic::graphic_circle circle{drivers}; + graphic::graphic_reticle reticle{drivers, turret}; + graphic::graphic_flywheel_on flywheel_on{drivers, flywheel}; }; } // namespace subsystems::control \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/command_client_display.cpp b/ut-robomaster/src/control/client-display/command_client_display.cpp index 2567d5a5..17eb7ebf 100644 --- a/ut-robomaster/src/control/client-display/command_client_display.cpp +++ b/ut-robomaster/src/control/client-display/command_client_display.cpp @@ -10,18 +10,11 @@ void CommandClientDisplay::initialize() circle = client->getCircle(); reticle = client->getReticle(); flywheel_on = client->getFlywheelOn(); - - circle->initialize(); - reticle->initialize(); - flywheel_on->initialize(); } void CommandClientDisplay::execute() { run(); } -void CommandClientDisplay::end(bool) -{ - tap::buzzer::silenceBuzzer(&drivers->pwm); -} +void CommandClientDisplay::end(bool) { tap::buzzer::silenceBuzzer(&drivers->pwm); } bool CommandClientDisplay::isFinished() const { return false; } @@ -29,9 +22,22 @@ bool CommandClientDisplay::run() { PT_BEGIN(); - // PT_CALL(circle->run()); - PT_CALL(reticle->run()); - PT_CALL(flywheel_on->run()); + // Initialize + PT_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); + PT_CALL(circle->initialize()); + PT_CALL(reticle->initialize()); + PT_CALL(flywheel_on->initialize()); + + // Update + while (true) + { + PT_CALL(reticle->run()); + PT_WAIT_UNTIL(hudTimer.execute()); + PT_CALL(circle->run()); + PT_WAIT_UNTIL(hudTimer.execute()); + PT_CALL(flywheel_on->run()); + PT_WAIT_UNTIL(hudTimer.execute()); + } PT_END(); } diff --git a/ut-robomaster/src/control/client-display/command_client_display.hpp b/ut-robomaster/src/control/client-display/command_client_display.hpp index ba481a45..052b268f 100644 --- a/ut-robomaster/src/control/client-display/command_client_display.hpp +++ b/ut-robomaster/src/control/client-display/command_client_display.hpp @@ -1,6 +1,7 @@ #pragma once #include + #include "tap/communication/sensors/buzzer/buzzer.hpp" #include "tap/communication/serial/ref_serial_data.hpp" #include "tap/communication/serial/ref_serial_transmitter.hpp" @@ -8,7 +9,6 @@ #include "control/client-display/client_display_subsystem.hpp" #include "control/client-display/graphics/graphic_abstract.hpp" - #include "modm/processing/protothread.hpp" #include "modm/processing/resumable.hpp" #include "subsystems/flywheel/flywheel_subsystem.hpp" @@ -26,7 +26,7 @@ namespace commands class CommandClientDisplay : public Command, modm::pt::Protothread { public: - CommandClientDisplay(src::Drivers *drivers, ClientDisplaySubsystem* client) + CommandClientDisplay(src::Drivers* drivers, ClientDisplaySubsystem* client) : Command(), drivers(drivers), client(client) @@ -40,15 +40,14 @@ class CommandClientDisplay : public Command, modm::pt::Protothread void execute() override; void end(bool) override; bool isFinished() const override; - const char *getName() const override { return "client display"; } + const char* getName() const override { return "client display"; } private: - - src::Drivers *drivers; + src::Drivers* drivers; ClientDisplaySubsystem* client; graphic::graphic_abstract* circle; graphic::graphic_abstract* reticle; graphic::graphic_abstract* flywheel_on; - + tap::arch::PeriodicMilliTimer hudTimer{50}; }; } // namespace commands \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp index 61112de1..12f53531 100644 --- a/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp +++ b/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp @@ -18,15 +18,8 @@ namespace graphic class graphic_abstract : protected NestedResumable<3> { public: - graphic_abstract(src::Drivers* drivers, uint8_t id) - : drivers(drivers), - refSerialTransmitter(drivers) - { - graphicId[0] = id & 0x01; - graphicId[1] = id & 0x02; - graphicId[2] = id & 0x04; - }; - virtual void initialize() = 0; + graphic_abstract(src::Drivers* drivers) : drivers(drivers), refSerialTransmitter(drivers) {}; + virtual ResumableResult initialize() = 0; virtual ResumableResult run() = 0; // virtual ~graphic_abstract(); @@ -37,7 +30,6 @@ class graphic_abstract : protected NestedResumable<3> uint8_t graphicId[3]; // 3 byte identifier for this graphic element RefSerialData::Tx::Graphic1Message msg; RefSerialData::Tx::GraphicCharacterMessage word_msg; - }; } // namespace graphic \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_circle.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_circle.hpp index 794a824d..f52f0028 100644 --- a/ut-robomaster/src/control/client-display/graphics/graphic_circle.hpp +++ b/ut-robomaster/src/control/client-display/graphics/graphic_circle.hpp @@ -7,11 +7,10 @@ namespace graphic class graphic_circle : public graphic_abstract { public: - graphic_circle(src::Drivers *drivers) : - graphic_abstract(drivers, 1) {}; - void initialize() override + graphic_circle(src::Drivers *drivers) : graphic_abstract(drivers) { - // restart(); + graphicId[0] = 0; + RefSerialTransmitter::configGraphicGenerics( &msg.graphicData, graphicId, @@ -22,23 +21,24 @@ class graphic_circle : public graphic_abstract RefSerialTransmitter::configCircle(10, 1920 / 2, 1080 / 2, 100, &msg.graphicData); }; + modm::ResumableResult initialize() override + { + RF_BEGIN(); + RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + RF_END_RETURN(); + }; + modm::ResumableResult run() override { float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 4.0f) * 0.5f + 0.5f; RF_BEGIN(); - RF_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); - // // setup new graphic (GRAPHIC_ADD operation) + msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; + msg.graphicData.lineWidth = 5.0f + 25.0f * t; + msg.graphicData.radius = 100.0f + 300.0f * t; + + // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) RF_CALL(refSerialTransmitter.sendGraphic(&msg)); - while (true) - { - msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; - msg.graphicData.lineWidth = 5.0f + 25.0f * t; - msg.graphicData.radius = 100.0f + 300.0f * t; - - // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) - RF_CALL(refSerialTransmitter.sendGraphic(&msg)); - } RF_END_RETURN(true); }; diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_flywheel_on.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_flywheel_on.hpp index c48668cd..06d31c9e 100644 --- a/ut-robomaster/src/control/client-display/graphics/graphic_flywheel_on.hpp +++ b/ut-robomaster/src/control/client-display/graphics/graphic_flywheel_on.hpp @@ -1,8 +1,9 @@ #pragma once -#include "graphic_abstract.hpp" #include "subsystems/flywheel/flywheel_subsystem.hpp" +#include "graphic_abstract.hpp" + using subsystems::flywheel::FlywheelSubsystem; using tap::communication::serial::RefSerialData; namespace graphic @@ -12,65 +13,71 @@ class graphic_flywheel_on : public graphic_abstract { public: graphic_flywheel_on(src::Drivers *drivers, FlywheelSubsystem *flywheel) - : graphic_abstract(drivers, 3), - flywheel(flywheel) {}; - void initialize() override + : graphic_abstract(drivers), + flywheel(flywheel) { - // restart(); + graphicId[0] = 2; RefSerialTransmitter::configGraphicGenerics( &word_msg.graphicData, graphicId, RefSerialData::Tx::GRAPHIC_ADD, - 2, + 0, RefSerialData::Tx::GraphicColor::ORANGE); // RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY - const char* message = "Flywheel on"; + const char *message = "Flywheel on"; RefSerialTransmitter::configCharacterMsg(50, 10, CENTER_X, CENTER_Y, message, &word_msg); }; - modm::ResumableResult run() override + modm::ResumableResult initialize() override { RF_BEGIN(); - - RF_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); - - // setup new graphic (GRAPHIC_ADD operation) RF_CALL(refSerialTransmitter.sendGraphic(&word_msg)); + RF_END_RETURN(); + }; - while (true) - { - // msg.graphicData.lineWidth = 5.0f + 25.0f * t; - // msg.graphicData.radius = 100.0f + 300.0f * t; - // DROP_DISTANCE = this.turret.getBulletDropReticle(); - // msg.graphicData.startY = CENTER_Y - turret->getBulletDropReticle(); - // startY is centerY - - word_msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; - RF_CALL(refSerialTransmitter.sendGraphic(&word_msg)); + modm::ResumableResult run() override + { + RF_BEGIN(); - // if(flywheel->isActive()) - // { - // RF_CALL(refSerialTransmitter.sendGraphic(&word_msg)); - // } - // else - // { - // word_msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_DELETE; - // RF_CALL(refSerialTransmitter.sendGraphic(&word_msg)); - // } + // msg.graphicData.lineWidth = 5.0f + 25.0f * t; + // msg.graphicData.radius = 100.0f + 300.0f * t; + // DROP_DISTANCE = this.turret.getBulletDropReticle(); + // msg.graphicData.startY = CENTER_Y - turret->getBulletDropReticle(); + // startY is centerY + word_msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; - // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) - // RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + if (flywheel->isActive()) + { + RefSerialTransmitter::configCharacterMsg( + 50, + 10, + CENTER_X, + CENTER_Y, + "Flywheel on", + &word_msg); } + else + { + RefSerialTransmitter::configCharacterMsg( + 50, + 10, + CENTER_X, + CENTER_Y, + "Flywheel off", + &word_msg); + } + + RF_CALL(refSerialTransmitter.sendGraphic(&word_msg)); RF_END_RETURN(true); }; private: static constexpr uint16_t CENTER_X = 1920 / 3; static constexpr uint16_t CENTER_Y = 1080 / 3; - FlywheelSubsystem* flywheel; + FlywheelSubsystem *flywheel; }; } // namespace graphic \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp index aac99270..d1896bfb 100644 --- a/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp +++ b/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp @@ -1,8 +1,9 @@ #pragma once -#include "graphic_abstract.hpp" #include "subsystems/turret/turret_subsystem.hpp" +#include "graphic_abstract.hpp" + using subsystems::turret::TurretSubsystem; namespace graphic { @@ -11,51 +12,50 @@ class graphic_reticle : public graphic_abstract { public: graphic_reticle(src::Drivers *drivers, TurretSubsystem *turret) - : graphic_abstract(drivers, 2), - turret(turret) {}; - void initialize() override + : graphic_abstract(drivers), + turret(turret) { + graphicId[0] = 1; + RefSerialTransmitter::configGraphicGenerics( &msg.graphicData, graphicId, RefSerialData::Tx::GRAPHIC_ADD, - 1, //1st layer + 0, RefSerialData::Tx::GraphicColor::CYAN); // RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY RefSerialTransmitter::configCircle(10, CENTER_X, CENTER_Y, CIRCLE_SIZE, &msg.graphicData); }; - modm::ResumableResult run() override + modm::ResumableResult initialize() override { - float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 4.0f) * 0.5f + 0.5f; RF_BEGIN(); - - RF_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); - - // setup new graphic (GRAPHIC_ADD operation) RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + RF_END_RETURN(); + }; - while (true) - { - // msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; - // // msg.graphicData.lineWidth = 5.0f + 25.0f * t; - // // msg.graphicData.radius = 100.0f + 300.0f * t; - // // DROP_DISTANCE = this.turret.getBulletDropReticle(); - // msg.graphicData.startY = CENTER_Y - turret->getBulletDropReticle(); - // // startY is centerY + modm::ResumableResult run() override + { + float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 3.0f) * 0.5f + 0.5f; + RF_BEGIN(); - // // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) - // RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + // msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; + // // msg.graphicData.lineWidth = 5.0f + 25.0f * t; + // // msg.graphicData.radius = 100.0f + 300.0f * t; + // // DROP_DISTANCE = this.turret.getBulletDropReticle(); + // msg.graphicData.startY = CENTER_Y - turret->getBulletDropReticle(); + // // startY is centerY + // // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) + // RF_CALL(refSerialTransmitter.sendGraphic(&msg)); - msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; - msg.graphicData.lineWidth = 5.0f + 25.0f * t; - msg.graphicData.radius = 100.0f + 300.0f * t; + msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; + msg.graphicData.lineWidth = 5.0f + 25.0f * t; + msg.graphicData.radius = 100.0f + 300.0f * t; - // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) - RF_CALL(refSerialTransmitter.sendGraphic(&msg)); - } + // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) + RF_CALL(refSerialTransmitter.sendGraphic(&msg)); RF_END_RETURN(true); }; From 258164ea5bba65f4f44f3f3afc90a738d3b075d4 Mon Sep 17 00:00:00 2001 From: vinle0 Date: Fri, 4 Apr 2025 22:31:59 +0000 Subject: [PATCH 09/13] Changes to orientation of chassis --- .../client_display_subsystem.cpp | 14 ++- .../client_display_subsystem.hpp | 3 + .../client-display/command_client_display.cpp | 9 +- .../client-display/command_client_display.hpp | 1 + .../graphics/graphic_abstract.hpp | 2 + .../graphics/graphic_orientation.hpp | 103 ++++++++++++++++++ .../graphics/graphic_reticle.hpp | 11 +- .../src/robots/standard/standard_control.hpp | 3 +- 8 files changed, 132 insertions(+), 14 deletions(-) create mode 100644 ut-robomaster/src/control/client-display/graphics/graphic_orientation.hpp diff --git a/ut-robomaster/src/control/client-display/client_display_subsystem.cpp b/ut-robomaster/src/control/client-display/client_display_subsystem.cpp index 49476f46..1ace7a9f 100644 --- a/ut-robomaster/src/control/client-display/client_display_subsystem.cpp +++ b/ut-robomaster/src/control/client-display/client_display_subsystem.cpp @@ -4,22 +4,24 @@ namespace subsystems::control { -ClientDisplaySubsystem::ClientDisplaySubsystem(src::Drivers* drivers, TurretSubsystem* turret, FlywheelSubsystem* flywheel) +ClientDisplaySubsystem::ClientDisplaySubsystem( + src::Drivers* drivers, + TurretSubsystem* turret, + FlywheelSubsystem* flywheel) : Subsystem(drivers), drivers(drivers), turret(turret), flywheel(flywheel), circle(drivers), reticle(drivers, ClientDisplaySubsystem::turret), - flywheel_on(drivers, ClientDisplaySubsystem::flywheel) -{ -} + flywheel_on(drivers, ClientDisplaySubsystem::flywheel), + orientation(drivers, ClientDisplaySubsystem::turret) -void ClientDisplaySubsystem::initialize() { - *numGraphics = 3; } +void ClientDisplaySubsystem::initialize() { *numGraphics = 4; } + void ClientDisplaySubsystem::refresh() {} void ClientDisplaySubsystem::runHardwareTests() {} diff --git a/ut-robomaster/src/control/client-display/client_display_subsystem.hpp b/ut-robomaster/src/control/client-display/client_display_subsystem.hpp index d2d91993..44a53459 100644 --- a/ut-robomaster/src/control/client-display/client_display_subsystem.hpp +++ b/ut-robomaster/src/control/client-display/client_display_subsystem.hpp @@ -9,6 +9,7 @@ #include "control/client-display/graphics/graphic_abstract.hpp" #include "control/client-display/graphics/graphic_circle.hpp" #include "control/client-display/graphics/graphic_flywheel_on.hpp" +#include "control/client-display/graphics/graphic_orientation.hpp" #include "control/client-display/graphics/graphic_reticle.hpp" #include "subsystems/flywheel/flywheel_subsystem.hpp" #include "subsystems/turret/turret_subsystem.hpp" @@ -33,6 +34,7 @@ class ClientDisplaySubsystem : public tap::control::Subsystem graphic::graphic_abstract* getCircle() { return &circle; }; graphic::graphic_abstract* getReticle() { return &reticle; }; graphic::graphic_abstract* getFlywheelOn() { return &flywheel_on; }; + graphic::graphic_abstract* getOrientation() { return &orientation; }; void runHardwareTests() override; @@ -47,5 +49,6 @@ class ClientDisplaySubsystem : public tap::control::Subsystem graphic::graphic_circle circle{drivers}; graphic::graphic_reticle reticle{drivers, turret}; graphic::graphic_flywheel_on flywheel_on{drivers, flywheel}; + graphic::graphic_orientation orientation{drivers, turret}; }; } // namespace subsystems::control \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/command_client_display.cpp b/ut-robomaster/src/control/client-display/command_client_display.cpp index 17eb7ebf..081ce790 100644 --- a/ut-robomaster/src/control/client-display/command_client_display.cpp +++ b/ut-robomaster/src/control/client-display/command_client_display.cpp @@ -5,16 +5,18 @@ namespace commands void CommandClientDisplay::initialize() { - tap::buzzer::playNote(&drivers->pwm, 440); + // tap::buzzer::playNote(&drivers->pwm, 440); circle = client->getCircle(); reticle = client->getReticle(); flywheel_on = client->getFlywheelOn(); + orientation = client->getOrientation(); + restart(); } void CommandClientDisplay::execute() { run(); } -void CommandClientDisplay::end(bool) { tap::buzzer::silenceBuzzer(&drivers->pwm); } +void CommandClientDisplay::end(bool) { /*tap::buzzer::silenceBuzzer(&drivers->pwm);*/ } bool CommandClientDisplay::isFinished() const { return false; } @@ -27,6 +29,7 @@ bool CommandClientDisplay::run() PT_CALL(circle->initialize()); PT_CALL(reticle->initialize()); PT_CALL(flywheel_on->initialize()); + PT_CALL(orientation->initialize()); // Update while (true) @@ -37,6 +40,8 @@ bool CommandClientDisplay::run() PT_WAIT_UNTIL(hudTimer.execute()); PT_CALL(flywheel_on->run()); PT_WAIT_UNTIL(hudTimer.execute()); + PT_CALL(orientation->run()); + PT_WAIT_UNTIL(hudTimer.execute()); } PT_END(); diff --git a/ut-robomaster/src/control/client-display/command_client_display.hpp b/ut-robomaster/src/control/client-display/command_client_display.hpp index 052b268f..33a4251c 100644 --- a/ut-robomaster/src/control/client-display/command_client_display.hpp +++ b/ut-robomaster/src/control/client-display/command_client_display.hpp @@ -48,6 +48,7 @@ class CommandClientDisplay : public Command, modm::pt::Protothread graphic::graphic_abstract* circle; graphic::graphic_abstract* reticle; graphic::graphic_abstract* flywheel_on; + graphic::graphic_abstract* orientation; tap::arch::PeriodicMilliTimer hudTimer{50}; }; } // namespace commands \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp index 12f53531..7f6e234a 100644 --- a/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp +++ b/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp @@ -25,10 +25,12 @@ class graphic_abstract : protected NestedResumable<3> // virtual ~graphic_abstract(); protected: + //bottom left is (0, 0) top right is (1920, 1080) src::Drivers* drivers; RefSerialTransmitter refSerialTransmitter; uint8_t graphicId[3]; // 3 byte identifier for this graphic element RefSerialData::Tx::Graphic1Message msg; + RefSerialData::Tx::Graphic5Message multiMsg; RefSerialData::Tx::GraphicCharacterMessage word_msg; }; diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_orientation.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_orientation.hpp new file mode 100644 index 00000000..d457e2ec --- /dev/null +++ b/ut-robomaster/src/control/client-display/graphics/graphic_orientation.hpp @@ -0,0 +1,103 @@ +#pragma once +#include "subsystems/turret/turret_subsystem.hpp" + +#include "graphic_abstract.hpp" +using subsystems::turret::TurretSubsystem; + +namespace graphic +{ + +class graphic_orientation : public graphic_abstract +{ +public: + graphic_orientation(src::Drivers *drivers, TurretSubsystem *turret) + : graphic_abstract(drivers), + turret(turret) + { + graphicId[0] = 4; + + RefSerialTransmitter::configGraphicGenerics( + &multiMsg.graphicData[0], + graphicId, + RefSerialData::Tx::GRAPHIC_ADD, + 0, + RefSerialData::Tx::GraphicColor::GREEN); + + RefSerialTransmitter::configFloatingNumber( + 100, + 3, + 10, + 700, + 400, + turret->getChassisYaw(), + &multiMsg.graphicData[0]); + + graphicId[0] = 5; + + RefSerialTransmitter::configGraphicGenerics( + &multiMsg.graphicData[1], + graphicId, + RefSerialData::Tx::GRAPHIC_ADD, + 0, + RefSerialData::Tx::GraphicColor::GREEN); + + RefSerialTransmitter::configFloatingNumber( + 100, + 3, + 10, + 700, + 700, + turret->getCurrentLocalYaw(), + &multiMsg.graphicData[1]); + + + RefSerialTransmitter::configGraphicGenerics( + &multiMsg.graphicData[2], + graphicId, + RefSerialData::Tx::GRAPHIC_ADD, + 0, + RefSerialData::Tx::GraphicColor::GREEN); + + RefSerialTransmitter::configLine( + 100, + 3, + 10, + 700, + 700, + &multiMsg.graphicData[2]); + + + // RefSerialTransmitter::configLine(10, 0, 0, 1920, 1080, &msg.graphicData); + }; + + modm::ResumableResult initialize() override + { + RF_BEGIN(); + RF_CALL(refSerialTransmitter.sendGraphic(&multiMsg)); + RF_END_RETURN(); + }; + + modm::ResumableResult run() override + { + RF_BEGIN(); + + multiMsg.graphicData[0].operation = RefSerialData::Tx::GRAPHIC_MODIFY; + multiMsg.graphicData[1].operation = RefSerialData::Tx::GRAPHIC_MODIFY; + + multiMsg.graphicData[0].value = turret->getChassisYaw() * 1000; + multiMsg.graphicData[1].value = turret->getCurrentLocalYaw() * 1000 + PI; //turret yaw + + + + + // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) + RF_CALL(refSerialTransmitter.sendGraphic(&multiMsg)); + + RF_END_RETURN(true); + }; + +private: + TurretSubsystem *turret; +}; + +} // namespace graphic \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp index d1896bfb..26b253dd 100644 --- a/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp +++ b/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp @@ -37,10 +37,9 @@ class graphic_reticle : public graphic_abstract modm::ResumableResult run() override { - float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 3.0f) * 0.5f + 0.5f; + // float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 3.0f) * 0.5f + 0.5f; RF_BEGIN(); - // msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; // // msg.graphicData.lineWidth = 5.0f + 25.0f * t; // // msg.graphicData.radius = 100.0f + 300.0f * t; // // DROP_DISTANCE = this.turret.getBulletDropReticle(); @@ -50,9 +49,13 @@ class graphic_reticle : public graphic_abstract // // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) // RF_CALL(refSerialTransmitter.sendGraphic(&msg)); + // msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; + // msg.graphicData.lineWidth = 5.0f + 25.0f * t; + // msg.graphicData.radius = 100.0f + 300.0f * t; + msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; - msg.graphicData.lineWidth = 5.0f + 25.0f * t; - msg.graphicData.radius = 100.0f + 300.0f * t; + msg.graphicData.startY = turret->getBulletDropReticle(); + // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) RF_CALL(refSerialTransmitter.sendGraphic(&msg)); diff --git a/ut-robomaster/src/robots/standard/standard_control.hpp b/ut-robomaster/src/robots/standard/standard_control.hpp index 2930efba..4768146b 100644 --- a/ut-robomaster/src/robots/standard/standard_control.hpp +++ b/ut-robomaster/src/robots/standard/standard_control.hpp @@ -14,11 +14,10 @@ class StandardControl : CommonControlManual agitator.initialize(); drivers->commandScheduler.registerSubsystem(&agitator); drivers->commandScheduler.registerSubsystem(&client); + client.setDefaultCommand(&hudTest); drivers->commandMapper.addMap(&leftMouseDown); drivers->commandMapper.addMap(&leftSwitchUp); - - drivers->commandMapper.addMap(&hudTestKey); } private: From 7ba8ecdcd8ba8fe09bfc0fb03cefa4dcd02fa43f Mon Sep 17 00:00:00 2001 From: Caleb Chalmers Date: Sat, 5 Apr 2025 00:08:08 +0000 Subject: [PATCH 10/13] Setup square orientation indicator --- .../client-display/command_client_display.cpp | 6 +- .../graphics/graphic_abstract.hpp | 3 +- .../graphics/graphic_orientation.hpp | 70 ++++++++++--------- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/ut-robomaster/src/control/client-display/command_client_display.cpp b/ut-robomaster/src/control/client-display/command_client_display.cpp index 081ce790..f0eca023 100644 --- a/ut-robomaster/src/control/client-display/command_client_display.cpp +++ b/ut-robomaster/src/control/client-display/command_client_display.cpp @@ -26,16 +26,16 @@ bool CommandClientDisplay::run() // Initialize PT_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); + // PT_CALL(reticle->initialize()); PT_CALL(circle->initialize()); - PT_CALL(reticle->initialize()); PT_CALL(flywheel_on->initialize()); PT_CALL(orientation->initialize()); // Update while (true) { - PT_CALL(reticle->run()); - PT_WAIT_UNTIL(hudTimer.execute()); + // PT_CALL(reticle->run()); + // PT_WAIT_UNTIL(hudTimer.execute()); PT_CALL(circle->run()); PT_WAIT_UNTIL(hudTimer.execute()); PT_CALL(flywheel_on->run()); diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp index 7f6e234a..6b058099 100644 --- a/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp +++ b/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp @@ -25,12 +25,11 @@ class graphic_abstract : protected NestedResumable<3> // virtual ~graphic_abstract(); protected: - //bottom left is (0, 0) top right is (1920, 1080) + // bottom left is (0, 0) top right is (1920, 1080) src::Drivers* drivers; RefSerialTransmitter refSerialTransmitter; uint8_t graphicId[3]; // 3 byte identifier for this graphic element RefSerialData::Tx::Graphic1Message msg; - RefSerialData::Tx::Graphic5Message multiMsg; RefSerialData::Tx::GraphicCharacterMessage word_msg; }; diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_orientation.hpp b/ut-robomaster/src/control/client-display/graphics/graphic_orientation.hpp index d457e2ec..998680fa 100644 --- a/ut-robomaster/src/control/client-display/graphics/graphic_orientation.hpp +++ b/ut-robomaster/src/control/client-display/graphics/graphic_orientation.hpp @@ -21,16 +21,7 @@ class graphic_orientation : public graphic_abstract graphicId, RefSerialData::Tx::GRAPHIC_ADD, 0, - RefSerialData::Tx::GraphicColor::GREEN); - - RefSerialTransmitter::configFloatingNumber( - 100, - 3, - 10, - 700, - 400, - turret->getChassisYaw(), - &multiMsg.graphicData[0]); + RefSerialData::Tx::GraphicColor::ORANGE); graphicId[0] = 5; @@ -41,33 +32,28 @@ class graphic_orientation : public graphic_abstract 0, RefSerialData::Tx::GraphicColor::GREEN); - RefSerialTransmitter::configFloatingNumber( - 100, - 3, - 10, - 700, - 700, - turret->getCurrentLocalYaw(), - &multiMsg.graphicData[1]); - + graphicId[0] = 6; RefSerialTransmitter::configGraphicGenerics( &multiMsg.graphicData[2], graphicId, RefSerialData::Tx::GRAPHIC_ADD, 0, - RefSerialData::Tx::GraphicColor::GREEN); + RefSerialData::Tx::GraphicColor::ORANGE); - RefSerialTransmitter::configLine( - 100, - 3, - 10, - 700, - 700, - &multiMsg.graphicData[2]); + graphicId[0] = 7; + RefSerialTransmitter::configGraphicGenerics( + &multiMsg.graphicData[3], + graphicId, + RefSerialData::Tx::GRAPHIC_ADD, + 0, + RefSerialData::Tx::GraphicColor::ORANGE); - // RefSerialTransmitter::configLine(10, 0, 0, 1920, 1080, &msg.graphicData); + RefSerialTransmitter::configLine(10, 0, 0, 1920, 1080, &multiMsg.graphicData[0]); + RefSerialTransmitter::configLine(10, 0, 0, 1920, 1080, &multiMsg.graphicData[1]); + RefSerialTransmitter::configLine(10, 0, 0, 1920, 1080, &multiMsg.graphicData[2]); + RefSerialTransmitter::configLine(10, 0, 0, 1920, 1080, &multiMsg.graphicData[3]); }; modm::ResumableResult initialize() override @@ -79,16 +65,35 @@ class graphic_orientation : public graphic_abstract modm::ResumableResult run() override { + float a = -turret->getCurrentLocalYaw(); + float r = 100.0f; + + float mx = 1920.0f / 2.0f; + float my = 1080.0f / 2.0f; + + float ax = mx + cosf(a - M_PI_4) * r; + float ay = my + sinf(a - M_PI_4) * r; + float bx = mx + cosf(a + M_PI_4) * r; + float by = my + sinf(a + M_PI_4) * r; + float cx = mx + cosf(a - M_PI_4 + M_PI) * r; + float cy = my + sinf(a - M_PI_4 + M_PI) * r; + float dx = mx + cosf(a + M_PI_4 + M_PI) * r; + float dy = my + sinf(a + M_PI_4 + M_PI) * r; + RF_BEGIN(); multiMsg.graphicData[0].operation = RefSerialData::Tx::GRAPHIC_MODIFY; multiMsg.graphicData[1].operation = RefSerialData::Tx::GRAPHIC_MODIFY; + multiMsg.graphicData[2].operation = RefSerialData::Tx::GRAPHIC_MODIFY; + multiMsg.graphicData[3].operation = RefSerialData::Tx::GRAPHIC_MODIFY; - multiMsg.graphicData[0].value = turret->getChassisYaw() * 1000; - multiMsg.graphicData[1].value = turret->getCurrentLocalYaw() * 1000 + PI; //turret yaw - - + RefSerialTransmitter::configLine(10, ax, ay, bx, by, &multiMsg.graphicData[0]); + RefSerialTransmitter::configLine(10, bx, by, cx, cy, &multiMsg.graphicData[1]); + RefSerialTransmitter::configLine(10, cx, cy, dx, dy, &multiMsg.graphicData[2]); + RefSerialTransmitter::configLine(10, dx, dy, ax, ay, &multiMsg.graphicData[3]); + // msg.graphicData[0].value = turret->getChassisYaw() * 1000; + // msg.graphicData[1].value = turret->getCurrentLocalYaw() * 1000 + PI; // turret yaw // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) RF_CALL(refSerialTransmitter.sendGraphic(&multiMsg)); @@ -98,6 +103,7 @@ class graphic_orientation : public graphic_abstract private: TurretSubsystem *turret; + RefSerialData::Tx::Graphic5Message multiMsg; }; } // namespace graphic \ No newline at end of file From b183154c198bfb8de2adea6a52d562fcceaf57c1 Mon Sep 17 00:00:00 2001 From: Caleb Chalmers Date: Fri, 11 Apr 2025 22:37:48 +0000 Subject: [PATCH 11/13] Move HUD code into subsystem folder --- .../client-display/reticle_display.cpp | 56 ------------------- .../client-display/reticle_display.hpp | 53 ------------------ .../src/robots/standard/standard_control.hpp | 6 +- .../hud}/client_display_subsystem.cpp | 4 +- .../hud}/client_display_subsystem.hpp | 14 ++--- .../hud}/command_client_display.cpp | 0 .../hud}/command_client_display.hpp | 6 +- .../hud}/graphics/graphic_abstract.hpp | 0 .../hud}/graphics/graphic_circle.hpp | 0 .../hud}/graphics/graphic_flywheel_on.hpp | 0 .../hud}/graphics/graphic_orientation.hpp | 0 .../hud}/graphics/graphic_reticle.hpp | 0 12 files changed, 17 insertions(+), 122 deletions(-) delete mode 100644 ut-robomaster/src/control/client-display/reticle_display.cpp delete mode 100644 ut-robomaster/src/control/client-display/reticle_display.hpp rename ut-robomaster/src/{control/client-display => subsystems/hud}/client_display_subsystem.cpp (91%) rename ut-robomaster/src/{control/client-display => subsystems/hud}/client_display_subsystem.hpp (78%) rename ut-robomaster/src/{control/client-display => subsystems/hud}/command_client_display.cpp (100%) rename ut-robomaster/src/{control/client-display => subsystems/hud}/command_client_display.hpp (88%) rename ut-robomaster/src/{control/client-display => subsystems/hud}/graphics/graphic_abstract.hpp (100%) rename ut-robomaster/src/{control/client-display => subsystems/hud}/graphics/graphic_circle.hpp (100%) rename ut-robomaster/src/{control/client-display => subsystems/hud}/graphics/graphic_flywheel_on.hpp (100%) rename ut-robomaster/src/{control/client-display => subsystems/hud}/graphics/graphic_orientation.hpp (100%) rename ut-robomaster/src/{control/client-display => subsystems/hud}/graphics/graphic_reticle.hpp (100%) diff --git a/ut-robomaster/src/control/client-display/reticle_display.cpp b/ut-robomaster/src/control/client-display/reticle_display.cpp deleted file mode 100644 index 0c41afe1..00000000 --- a/ut-robomaster/src/control/client-display/reticle_display.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "reticle_display.hpp" - -namespace commands -{ - -void reticle_display::initialize() -{ - restart(); - - RefSerialTransmitter::configGraphicGenerics( - &msg.graphicData, - graphicId, - RefSerialData::Tx::GRAPHIC_ADD, - 0, - RefSerialData::Tx::GraphicColor::PINK); - - // RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY - RefSerialTransmitter::configCircle( - 10, CENTER_X, - CENTER_Y, - CIRCLE_SIZE, - &msg.graphicData); -} - -void reticle_display::execute() { run(); } - -void reticle_display::end(bool) { }//tap::buzzer::silenceBuzzer(&drivers->pwm); } - -bool reticle_display::isFinished() const { return false; } - -bool reticle_display::run() -{ - //float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 4.0f) * 0.5f + 0.5f; - - PT_BEGIN(); - - PT_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData()); - - // setup new graphic (GRAPHIC_ADD operation) - PT_CALL(refSerialTransmitter.sendGraphic(&msg)); - - while (true) - { - // msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; - // msg.graphicData.lineWidth = 5.0f + 25.0f * t; - // msg.graphicData.radius = 100.0f + 300.0f * t; - // DROP_DISTANCE = this.turret.getBulletDropReticle(); - msg.graphicData.startY = CENTER_Y-turret->getBulletDropReticle();; //startY is centerY - - // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) - PT_CALL(refSerialTransmitter.sendGraphic(&msg)); - } - - PT_END(); -} -} // namespace commands \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/reticle_display.hpp b/ut-robomaster/src/control/client-display/reticle_display.hpp deleted file mode 100644 index 6464445b..00000000 --- a/ut-robomaster/src/control/client-display/reticle_display.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "tap/communication/referee/state_hud_indicator.hpp" -#include "tap/communication/serial/ref_serial.hpp" -#include "tap/control/command.hpp" -#include "modm/processing/resumable.hpp" -#include "subsystems/turret/turret_subsystem.hpp" - -#include "client_display_subsystem.hpp" - -using namespace tap::control; -using namespace tap::communication::serial; - -using subsystems::control::ClientDisplaySubsystem; -using subsystems::turret::TurretSubsystem; - -namespace commands -{ -class reticle_display : public Command, modm::pt::Protothread -{ -public: - reticle_display(src::Drivers *drivers, TurretSubsystem *turret) - : Command(), - drivers(drivers), - refSerialTransmitter(drivers), - turret(turret) - { - addSubsystemRequirement(turret); - } - - bool run(); - - void initialize() override; - void execute() override; - void end(bool) override; - bool isFinished() const override; - const char *getName() const override { return "client display"; } - -private: - src::Drivers *drivers; - RefSerialTransmitter refSerialTransmitter; - TurretSubsystem *turret; - const uint8_t graphicId[3] = {1, 0, 1}; // 3 byte identifier for this graphic element - RefSerialData::Tx::Graphic1Message msg; - - static constexpr uint16_t CENTER_X = 1920 / 2; - static constexpr uint16_t CENTER_Y = 1080 / 2; - static constexpr uint16_t CIRCLE_SIZE = 10; - - // static int DROP_DISTANCE = 0; - - -}; - -} \ No newline at end of file diff --git a/ut-robomaster/src/robots/standard/standard_control.hpp b/ut-robomaster/src/robots/standard/standard_control.hpp index 4768146b..3f22f2e2 100644 --- a/ut-robomaster/src/robots/standard/standard_control.hpp +++ b/ut-robomaster/src/robots/standard/standard_control.hpp @@ -1,6 +1,10 @@ -#include "control/client-display/command_client_display.hpp" #include "robots/common/common_control_manual.hpp" #include "subsystems/agitator/command_agitator_continuous.hpp" +#include "subsystems/hud/client_display_subsystem.hpp" +#include "subsystems/hud/command_client_display.hpp" + +using commands::CommandClientDisplay; +using subsystems::hud::ClientDisplaySubsystem; class StandardControl : CommonControlManual { diff --git a/ut-robomaster/src/control/client-display/client_display_subsystem.cpp b/ut-robomaster/src/subsystems/hud/client_display_subsystem.cpp similarity index 91% rename from ut-robomaster/src/control/client-display/client_display_subsystem.cpp rename to ut-robomaster/src/subsystems/hud/client_display_subsystem.cpp index 1ace7a9f..0b001ed0 100644 --- a/ut-robomaster/src/control/client-display/client_display_subsystem.cpp +++ b/ut-robomaster/src/subsystems/hud/client_display_subsystem.cpp @@ -2,7 +2,7 @@ #include "tap/communication/sensors/buzzer/buzzer.hpp" -namespace subsystems::control +namespace subsystems::hud { ClientDisplaySubsystem::ClientDisplaySubsystem( src::Drivers* drivers, @@ -26,4 +26,4 @@ void ClientDisplaySubsystem::refresh() {} void ClientDisplaySubsystem::runHardwareTests() {} -} // namespace subsystems::control \ No newline at end of file +} // namespace subsystems::hud \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/client_display_subsystem.hpp b/ut-robomaster/src/subsystems/hud/client_display_subsystem.hpp similarity index 78% rename from ut-robomaster/src/control/client-display/client_display_subsystem.hpp rename to ut-robomaster/src/subsystems/hud/client_display_subsystem.hpp index 44a53459..5eed8c31 100644 --- a/ut-robomaster/src/control/client-display/client_display_subsystem.hpp +++ b/ut-robomaster/src/subsystems/hud/client_display_subsystem.hpp @@ -6,11 +6,11 @@ #include "tap/control/command.hpp" #include "tap/control/subsystem.hpp" -#include "control/client-display/graphics/graphic_abstract.hpp" -#include "control/client-display/graphics/graphic_circle.hpp" -#include "control/client-display/graphics/graphic_flywheel_on.hpp" -#include "control/client-display/graphics/graphic_orientation.hpp" -#include "control/client-display/graphics/graphic_reticle.hpp" +#include "graphics/graphic_abstract.hpp" +#include "graphics/graphic_circle.hpp" +#include "graphics/graphic_flywheel_on.hpp" +#include "graphics/graphic_orientation.hpp" +#include "graphics/graphic_reticle.hpp" #include "subsystems/flywheel/flywheel_subsystem.hpp" #include "subsystems/turret/turret_subsystem.hpp" @@ -19,7 +19,7 @@ using subsystems::flywheel::FlywheelSubsystem; using subsystems::turret::TurretSubsystem; -namespace subsystems::control +namespace subsystems::hud { class ClientDisplaySubsystem : public tap::control::Subsystem { @@ -51,4 +51,4 @@ class ClientDisplaySubsystem : public tap::control::Subsystem graphic::graphic_flywheel_on flywheel_on{drivers, flywheel}; graphic::graphic_orientation orientation{drivers, turret}; }; -} // namespace subsystems::control \ No newline at end of file +} // namespace subsystems::hud \ No newline at end of file diff --git a/ut-robomaster/src/control/client-display/command_client_display.cpp b/ut-robomaster/src/subsystems/hud/command_client_display.cpp similarity index 100% rename from ut-robomaster/src/control/client-display/command_client_display.cpp rename to ut-robomaster/src/subsystems/hud/command_client_display.cpp diff --git a/ut-robomaster/src/control/client-display/command_client_display.hpp b/ut-robomaster/src/subsystems/hud/command_client_display.hpp similarity index 88% rename from ut-robomaster/src/control/client-display/command_client_display.hpp rename to ut-robomaster/src/subsystems/hud/command_client_display.hpp index 33a4251c..f9e569ea 100644 --- a/ut-robomaster/src/control/client-display/command_client_display.hpp +++ b/ut-robomaster/src/subsystems/hud/command_client_display.hpp @@ -7,19 +7,19 @@ #include "tap/communication/serial/ref_serial_transmitter.hpp" #include "tap/control/command.hpp" -#include "control/client-display/client_display_subsystem.hpp" -#include "control/client-display/graphics/graphic_abstract.hpp" +#include "graphics/graphic_abstract.hpp" #include "modm/processing/protothread.hpp" #include "modm/processing/resumable.hpp" #include "subsystems/flywheel/flywheel_subsystem.hpp" +#include "client_display_subsystem.hpp" #include "drivers.hpp" using namespace tap::control; using namespace tap::communication::serial; -using subsystems::control::ClientDisplaySubsystem; using subsystems::flywheel::FlywheelSubsystem; +using subsystems::hud::ClientDisplaySubsystem; namespace commands { diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp b/ut-robomaster/src/subsystems/hud/graphics/graphic_abstract.hpp similarity index 100% rename from ut-robomaster/src/control/client-display/graphics/graphic_abstract.hpp rename to ut-robomaster/src/subsystems/hud/graphics/graphic_abstract.hpp diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_circle.hpp b/ut-robomaster/src/subsystems/hud/graphics/graphic_circle.hpp similarity index 100% rename from ut-robomaster/src/control/client-display/graphics/graphic_circle.hpp rename to ut-robomaster/src/subsystems/hud/graphics/graphic_circle.hpp diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_flywheel_on.hpp b/ut-robomaster/src/subsystems/hud/graphics/graphic_flywheel_on.hpp similarity index 100% rename from ut-robomaster/src/control/client-display/graphics/graphic_flywheel_on.hpp rename to ut-robomaster/src/subsystems/hud/graphics/graphic_flywheel_on.hpp diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_orientation.hpp b/ut-robomaster/src/subsystems/hud/graphics/graphic_orientation.hpp similarity index 100% rename from ut-robomaster/src/control/client-display/graphics/graphic_orientation.hpp rename to ut-robomaster/src/subsystems/hud/graphics/graphic_orientation.hpp diff --git a/ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp b/ut-robomaster/src/subsystems/hud/graphics/graphic_reticle.hpp similarity index 100% rename from ut-robomaster/src/control/client-display/graphics/graphic_reticle.hpp rename to ut-robomaster/src/subsystems/hud/graphics/graphic_reticle.hpp From 726f0839d65c6c9797493a44cca5ae887f71e05d Mon Sep 17 00:00:00 2001 From: Caleb Chalmers Date: Sat, 12 Apr 2025 00:13:10 +0000 Subject: [PATCH 12/13] Clean up and move HUG graphics --- .../hud/graphics/graphic_abstract.hpp | 2 -- .../hud/graphics/graphic_circle.hpp | 1 + .../hud/graphics/graphic_flywheel_on.hpp | 24 +++++++++++++------ .../hud/graphics/graphic_orientation.hpp | 4 ++-- .../hud/graphics/graphic_reticle.hpp | 2 +- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/ut-robomaster/src/subsystems/hud/graphics/graphic_abstract.hpp b/ut-robomaster/src/subsystems/hud/graphics/graphic_abstract.hpp index 6b058099..aaae5d6b 100644 --- a/ut-robomaster/src/subsystems/hud/graphics/graphic_abstract.hpp +++ b/ut-robomaster/src/subsystems/hud/graphics/graphic_abstract.hpp @@ -29,8 +29,6 @@ class graphic_abstract : protected NestedResumable<3> src::Drivers* drivers; RefSerialTransmitter refSerialTransmitter; uint8_t graphicId[3]; // 3 byte identifier for this graphic element - RefSerialData::Tx::Graphic1Message msg; - RefSerialData::Tx::GraphicCharacterMessage word_msg; }; } // namespace graphic \ No newline at end of file diff --git a/ut-robomaster/src/subsystems/hud/graphics/graphic_circle.hpp b/ut-robomaster/src/subsystems/hud/graphics/graphic_circle.hpp index f52f0028..9b4aaa5f 100644 --- a/ut-robomaster/src/subsystems/hud/graphics/graphic_circle.hpp +++ b/ut-robomaster/src/subsystems/hud/graphics/graphic_circle.hpp @@ -44,6 +44,7 @@ class graphic_circle : public graphic_abstract }; private: + RefSerialData::Tx::Graphic1Message msg; float t = 10.0; }; diff --git a/ut-robomaster/src/subsystems/hud/graphics/graphic_flywheel_on.hpp b/ut-robomaster/src/subsystems/hud/graphics/graphic_flywheel_on.hpp index 06d31c9e..51029e81 100644 --- a/ut-robomaster/src/subsystems/hud/graphics/graphic_flywheel_on.hpp +++ b/ut-robomaster/src/subsystems/hud/graphics/graphic_flywheel_on.hpp @@ -27,7 +27,13 @@ class graphic_flywheel_on : public graphic_abstract // RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY const char *message = "Flywheel on"; - RefSerialTransmitter::configCharacterMsg(50, 10, CENTER_X, CENTER_Y, message, &word_msg); + RefSerialTransmitter::configCharacterMsg( + FONT_SIZE, + WIDTH, + CENTER_X, + CENTER_Y, + message, + &word_msg); }; modm::ResumableResult initialize() override @@ -52,8 +58,8 @@ class graphic_flywheel_on : public graphic_abstract if (flywheel->isActive()) { RefSerialTransmitter::configCharacterMsg( - 50, - 10, + FONT_SIZE, + WIDTH, CENTER_X, CENTER_Y, "Flywheel on", @@ -62,8 +68,8 @@ class graphic_flywheel_on : public graphic_abstract else { RefSerialTransmitter::configCharacterMsg( - 50, - 10, + FONT_SIZE, + WIDTH, CENTER_X, CENTER_Y, "Flywheel off", @@ -75,8 +81,12 @@ class graphic_flywheel_on : public graphic_abstract }; private: - static constexpr uint16_t CENTER_X = 1920 / 3; - static constexpr uint16_t CENTER_Y = 1080 / 3; + RefSerialData::Tx::GraphicCharacterMessage word_msg; + + static constexpr uint16_t FONT_SIZE = 30; + static constexpr uint16_t WIDTH = 3; + static constexpr uint16_t CENTER_X = 50; + static constexpr uint16_t CENTER_Y = 850; FlywheelSubsystem *flywheel; }; diff --git a/ut-robomaster/src/subsystems/hud/graphics/graphic_orientation.hpp b/ut-robomaster/src/subsystems/hud/graphics/graphic_orientation.hpp index 998680fa..64cef3b2 100644 --- a/ut-robomaster/src/subsystems/hud/graphics/graphic_orientation.hpp +++ b/ut-robomaster/src/subsystems/hud/graphics/graphic_orientation.hpp @@ -68,8 +68,8 @@ class graphic_orientation : public graphic_abstract float a = -turret->getCurrentLocalYaw(); float r = 100.0f; - float mx = 1920.0f / 2.0f; - float my = 1080.0f / 2.0f; + float mx = 150.0f; + float my = 700.0f; float ax = mx + cosf(a - M_PI_4) * r; float ay = my + sinf(a - M_PI_4) * r; diff --git a/ut-robomaster/src/subsystems/hud/graphics/graphic_reticle.hpp b/ut-robomaster/src/subsystems/hud/graphics/graphic_reticle.hpp index 26b253dd..2d46d0fc 100644 --- a/ut-robomaster/src/subsystems/hud/graphics/graphic_reticle.hpp +++ b/ut-robomaster/src/subsystems/hud/graphics/graphic_reticle.hpp @@ -56,13 +56,13 @@ class graphic_reticle : public graphic_abstract msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY; msg.graphicData.startY = turret->getBulletDropReticle(); - // modify existing graphic based on the ID (GRAPHIC_MODIFY operation) RF_CALL(refSerialTransmitter.sendGraphic(&msg)); RF_END_RETURN(true); }; private: + RefSerialData::Tx::Graphic1Message msg; static constexpr uint16_t CENTER_X = 1920 / 2; static constexpr uint16_t CENTER_Y = 1080 / 2; static constexpr uint16_t CIRCLE_SIZE = 100; From b1d3c8e1b6823e4982027e25501b39b09422f56b Mon Sep 17 00:00:00 2001 From: Caleb Chalmers Date: Sat, 12 Apr 2025 00:15:48 +0000 Subject: [PATCH 13/13] Add HUD reset coommand --- .../src/robots/standard/standard_control.hpp | 10 ++++-- .../hud/command_client_display_reset.cpp | 14 ++++++++ .../hud/command_client_display_reset.hpp | 36 +++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 ut-robomaster/src/subsystems/hud/command_client_display_reset.cpp create mode 100644 ut-robomaster/src/subsystems/hud/command_client_display_reset.hpp diff --git a/ut-robomaster/src/robots/standard/standard_control.hpp b/ut-robomaster/src/robots/standard/standard_control.hpp index 3f22f2e2..1b79210a 100644 --- a/ut-robomaster/src/robots/standard/standard_control.hpp +++ b/ut-robomaster/src/robots/standard/standard_control.hpp @@ -2,8 +2,10 @@ #include "subsystems/agitator/command_agitator_continuous.hpp" #include "subsystems/hud/client_display_subsystem.hpp" #include "subsystems/hud/command_client_display.hpp" +#include "subsystems/hud/command_client_display_reset.hpp" using commands::CommandClientDisplay; +using commands::CommandClientDisplayReset; using subsystems::hud::ClientDisplaySubsystem; class StandardControl : CommonControlManual @@ -18,10 +20,11 @@ class StandardControl : CommonControlManual agitator.initialize(); drivers->commandScheduler.registerSubsystem(&agitator); drivers->commandScheduler.registerSubsystem(&client); - client.setDefaultCommand(&hudTest); + client.setDefaultCommand(&hudDisplay); drivers->commandMapper.addMap(&leftMouseDown); drivers->commandMapper.addMap(&leftSwitchUp); + drivers->commandMapper.addMap(&hudResetKey); } private: @@ -37,7 +40,8 @@ class StandardControl : CommonControlManual BarrelId::STANDARD1, true}; - commands::CommandClientDisplay hudTest{drivers, &client}; + commands::CommandClientDisplay hudDisplay{drivers, &client}; + commands::CommandClientDisplayReset hudReset{drivers, &client}; // Mappings HoldCommandMapping leftMouseDown{ @@ -50,5 +54,5 @@ class StandardControl : CommonControlManual {&rotateAgitator_SwitchUp, &rotateFlywheel_SwitchMid}, RemoteMapState(Remote::Switch::LEFT_SWITCH, Remote::SwitchState::UP)}; - HoldCommandMapping hudTestKey{drivers, {&hudTest}, RemoteMapState({Remote::Key::Z})}; + ToggleCommandMapping hudResetKey{drivers, {&hudReset}, RemoteMapState({Remote::Key::Z})}; }; \ No newline at end of file diff --git a/ut-robomaster/src/subsystems/hud/command_client_display_reset.cpp b/ut-robomaster/src/subsystems/hud/command_client_display_reset.cpp new file mode 100644 index 00000000..e988e95c --- /dev/null +++ b/ut-robomaster/src/subsystems/hud/command_client_display_reset.cpp @@ -0,0 +1,14 @@ +#include "command_client_display_reset.hpp" + +#include "tap/communication/sensors/buzzer/buzzer.hpp" + +namespace commands +{ +void CommandClientDisplayReset::initialize() { tap::buzzer::playNote(&drivers->pwm, 440); } + +void CommandClientDisplayReset::execute() {} + +void CommandClientDisplayReset::end(bool) { tap::buzzer::silenceBuzzer(&drivers->pwm); } + +bool CommandClientDisplayReset::isFinished() const { return false; } +} // namespace commands \ No newline at end of file diff --git a/ut-robomaster/src/subsystems/hud/command_client_display_reset.hpp b/ut-robomaster/src/subsystems/hud/command_client_display_reset.hpp new file mode 100644 index 00000000..0235622c --- /dev/null +++ b/ut-robomaster/src/subsystems/hud/command_client_display_reset.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include "tap/control/command.hpp" + +#include "client_display_subsystem.hpp" +#include "drivers.hpp" + +using namespace tap::control; +using namespace tap::communication::serial; + +using subsystems::hud::ClientDisplaySubsystem; + +namespace commands +{ +class CommandClientDisplayReset : public Command +{ +public: + CommandClientDisplayReset(src::Drivers* drivers, ClientDisplaySubsystem* client) + : Command(), + drivers(drivers), + client(client) + { + addSubsystemRequirement(client); + } + + void initialize() override; + void execute() override; + void end(bool) override; + bool isFinished() const override; + const char* getName() const override { return "client display reset"; } + +private: + src::Drivers* drivers; + ClientDisplaySubsystem* client; +}; +} // namespace commands \ No newline at end of file