Skip to content

Commit 4bad9ec

Browse files
committed
finish
1 parent 5849705 commit 4bad9ec

File tree

6 files changed

+84
-20
lines changed

6 files changed

+84
-20
lines changed

ut-robomaster/src/communication/cv_board.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ void CVBoard::messageReceiveCallback(const ReceivedSerialMessage& message)
2626
break;
2727
// case CV_MESSAGE_TYPE_ECHO:
2828
// echoData(message);
29+
case CV_MESSAGE_TYPE_POSITION_REQUEST:
30+
decodePositionRequest(message);
31+
break;
2932
default:
3033
break;
3134
}
@@ -37,7 +40,7 @@ void CVBoard::sendMessage()
3740
sendColorData();
3841
}
3942

40-
// void CVBoard::echoData(const ReceivedSerialMessage& message)
43+
// void CVBoard::echoData(const ReceivedSerialMessage& message)
4144
// {
4245
// std::string data_string;
4346
// memcpy(&data_string, &message.data, sizeof(message.header.dataLength));
@@ -95,6 +98,17 @@ bool CVBoard::decodeTurretData(const ReceivedSerialMessage& message)
9598
return false;
9699
}
97100

101+
bool CVBoard::decodePositionRequest(const ReceivedSerialMessage& message)
102+
{
103+
if (message.header.dataLength == sizeof(lastPositionRequest))
104+
{
105+
memcpy(&lastPositionRequest, &message.data, sizeof(lastPositionRequest));
106+
return true;
107+
}
108+
return false;
109+
}
110+
98111
bool CVBoard::isOnline() const { return !offlineTimeout.isExpired(); }
99112
const TurretData& CVBoard::getTurretData() const { return lastTurretData; }
113+
const PositionRequest& CVBoard::getPositionRequest() const { return lastPositionRequest; }
100114
} // namespace communication

ut-robomaster/src/communication/cv_board.hpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CVBoard : public tap::communication::serial::DJISerial
4646
/**
4747
* Echo the message sent by the CV board to the CV board
4848
*/
49-
// void echoData(const ReceivedSerialMessage& message);
49+
void echoData(const ReceivedSerialMessage& message);
5050

5151
/**
5252
* Sends odometry data to the CV board
@@ -66,6 +66,18 @@ class CVBoard : public tap::communication::serial::DJISerial
6666
*/
6767
bool decodeTurretData(const ReceivedSerialMessage& message);
6868

69+
/**
70+
* Decode a request to move to a position.
71+
* @param message message from CV board
72+
* @return true if valid, false otherwise
73+
*/
74+
bool decodePositionRequest(const ReceivedSerialMessage& message);
75+
76+
/**
77+
* Fetch the position request from the CV board
78+
*/
79+
const PositionRequest& getPositionRequest() const;
80+
6981
/**
7082
* @return true if a message has been received within the last OFFLINE_TIMEOUT_MS milliseconds,
7183
* false if otherwise
@@ -89,6 +101,11 @@ class CVBoard : public tap::communication::serial::DJISerial
89101
/** Last turret aiming data received from the CV board */
90102
TurretData lastTurretData;
91103

104+
PositionRequest lastPositionRequest = {
105+
.x_requested = -999.9f,
106+
.y_requested = -999.9f,
107+
.time_sent = 0xdeadbeef};
108+
92109
/** UART port used to communicate with the CV board */
93110
static constexpr Uart::UartPort UART_PORT = Uart::Uart1;
94111

ut-robomaster/src/communication/cv_message.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ enum MessageTypes : uint8_t
1212
CV_MESSAGE_TYPE_TURRET_AIM = 2,
1313
CV_MESSAGE_TYPE_COLOR_DATA = 3,
1414
CV_MESSAGE_TYPE_ECHO = 4,
15+
CV_MESSAGE_TYPE_POSITION_REQUEST = 5,
1516
};
1617

1718
enum ColorTypes : uint8_t
@@ -38,6 +39,13 @@ struct TurretData
3839
bool hasTarget;
3940
} modm_packed;
4041

42+
struct PositionRequest
43+
{
44+
float x_requested;
45+
float y_requested;
46+
uint64_t time_sent;
47+
} modm_packed;
48+
4149
struct OdometryData
4250
{
4351
float xPos;

ut-robomaster/src/subsystems/chassis/command_sentry_position.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
namespace commands
44
{
55

6+
using namespace communication;
67
// old ard code
7-
// void CommandSentryPosition::initialize() { moveTimer.stop(); }
8+
void CommandSentryPosition::initialize() { moveTimer.stop(); }
89

9-
void CommandSentryPosition::initialize() { keyboardInputMove = Vector2f(0.0f); }
10+
// void CommandSentryPosition::initialize() { keyboardInputMove = Vector2f(0.0f); }
1011

1112
void CommandSentryPosition::execute()
1213
{
@@ -56,18 +57,22 @@ void CommandSentryPosition::execute()
5657

5758
// chassis->input(inputMove, inputSpin);
5859

59-
// if (drivers->isGameActive() && moveTimer.isStopped())
60-
// {
61-
// moveTimer.restart(10'000); // 10s
62-
// }
60+
if (drivers->isGameActive() && moveTimer.isStopped())
61+
{
62+
moveTimer.restart(5'000); // 5 secs
63+
}
6364

64-
// if (!moveTimer.isExpired())
65-
// {
66-
// chassis->input(Vector2f(0.0f), 0.0f);
67-
// return;
68-
// }
65+
if (!moveTimer.isExpired())
66+
{
67+
chassis->input(Vector2f(0.0f), 1.0f); // spin!
68+
return;
69+
}
70+
71+
PositionRequest pos = drivers->cvBoard.getPositionRequest();
72+
drivers->rtt << "x_pos = " << pos.x_requested << ", y_pos = " << pos.y_requested
73+
<< ", time_sent = " << (float)pos.time_sent;
6974

70-
// // speen
75+
// speen
7176
chassis->input(Vector2f(0.0f), 1.0f);
7277
}
7378

ut-robomaster/src/subsystems/chassis/command_sentry_position.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#pragma once
22

3-
//#include "tap/architecture/timeout.hpp"
3+
// #include "tap/architecture/timeout.hpp"
44
#include "tap/control/command.hpp"
55

6-
76
#include "robots/robot_constants.hpp"
8-
//this is older sentry code dont know why it had chopped path
9-
//#include "chassis_subsystem.hpp"
7+
// this is older sentry code dont know why it had chopped path
8+
// #include "chassis_subsystem.hpp"
109
#include "subsystems/chassis/chassis_subsystem.hpp"
1110
#include "subsystems/turret/turret_subsystem.hpp"
1211
#include "utils/chassis_auto_align.hpp"
@@ -18,8 +17,8 @@ namespace commands
1817
using namespace tap::communication::serial;
1918
using namespace modm;
2019
using subsystems::chassis::ChassisSubsystem;
21-
// using tap::arch::MilliTimeout;
2220
using subsystems::turret::TurretSubsystem;
21+
using tap::arch::MilliTimeout;
2322

2423
class CommandSentryPosition : public tap::control::Command
2524
{
@@ -52,7 +51,7 @@ class CommandSentryPosition : public tap::control::Command
5251
private:
5352
src::Drivers *drivers;
5453
ChassisSubsystem *chassis;
55-
//MilliTimeout moveTimer;
54+
MilliTimeout moveTimer;
5655
TurretSubsystem *turret;
5756

5857
Vector2f keyboardInputMove = Vector2f(0.0f);

ut-robomaster/src/subsystems/turret/command_sentry_aim.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ void CommandSentryAim::initialize() {}
77
void CommandSentryAim::execute()
88
{
99
// turret->setTargetWorldAngles(turret->getChassisYaw(), 0.0f);
10+
if (turret->getTargetLocalYaw() <= -55.0f)
11+
{
12+
turret->setTargetWorldAngles(50.0f, 10.0f);
13+
}
14+
else
15+
{
16+
turret->setTargetWorldAngles(-50.0f, -10.0f);
17+
}
18+
19+
/*
20+
PLAN (for suhas):
21+
- see if setTargetWorldAngles() works as intended
22+
- create targetWorldYaw/pitch variables
23+
- twYaw should switch between -200 and 200 depending on what its set to
24+
- if the angle is -200 set it to 200
25+
- if the angle is 200 set it to -200
26+
- else, keep current targetWorldAngle
27+
- time how long it takes for pitch motor to oscillate
28+
- use a timer to oscillate pitch to move ~10 deg to scan, or if that doesn't work, use the
29+
- same logic to scan
30+
*/
1031
}
1132

1233
void CommandSentryAim::end(bool) {}

0 commit comments

Comments
 (0)