Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new features to HUD #147

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "client_display_subsystem.hpp"

#include "tap/communication/sensors/buzzer/buzzer.hpp"

namespace subsystems::control
{
ClientDisplaySubsystem::ClientDisplaySubsystem(tap::Drivers *drivers) : Subsystem(drivers) {}

void ClientDisplaySubsystem::initialize() {}

void ClientDisplaySubsystem::refresh() {}

void ClientDisplaySubsystem::runHardwareTests() {}

} // namespace subsystems::control
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "tap/communication/sensors/buzzer/buzzer.hpp"
#include "tap/control/command.hpp"
#include "tap/control/subsystem.hpp"

#include "drivers.hpp"

namespace subsystems::control
{
class ClientDisplaySubsystem : public tap::control::Subsystem
{
public:
ClientDisplaySubsystem(tap::Drivers*);

void initialize() override;

void refresh() override;

void runHardwareTests() override;

const char* getName() override { return "Client Display subsystem"; }
};
} // namespace subsystems::control
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "command_client_display.hpp"

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);
}

void CommandClientDisplay::execute() { run(); }

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;

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();
}
} // namespace commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#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 "subsystems/flywheel/flywheel_subsystem.hpp"

#include "drivers.hpp"

using namespace tap::control;
using namespace tap::communication::serial;

using subsystems::control::ClientDisplaySubsystem;
using subsystems::flywheel::FlywheelSubsystem;

namespace commands
{
class CommandClientDisplay : public Command, modm::pt::Protothread
{
public:
CommandClientDisplay(src::Drivers *drivers, FlywheelSubsystem *flywheel)
: Command(),
drivers(drivers),
refSerialTransmitter(drivers)
{
addSubsystemRequirement(flywheel);
}

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;
const uint8_t graphicId[3] = {0, 0, 1}; // 3 byte identifier for this graphic element
RefSerialData::Tx::Graphic1Message msg;
};
} // namespace commands
7 changes: 7 additions & 0 deletions ut-robomaster/src/robots/standard/standard_control.hpp
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -15,6 +16,8 @@ class StandardControl : CommonControlManual

drivers->commandMapper.addMap(&leftMouseDown);
drivers->commandMapper.addMap(&leftSwitchUp);

drivers->commandMapper.addMap(&hudTestKey);
}

private:
Expand All @@ -29,6 +32,8 @@ class StandardControl : CommonControlManual
BarrelId::STANDARD1,
true};

commands::CommandClientDisplay hudTest{drivers, &flywheel};

// Mappings
HoldCommandMapping leftMouseDown{
drivers,
Expand All @@ -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::Z})};
};