Skip to content

Commit 8fb843e

Browse files
committed
update README.md, add initial support for VT03
1 parent e705279 commit 8fb843e

12 files changed

Lines changed: 250 additions & 9 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,17 @@ Simply run
6363
```Bash
6464
colcon build --symlink-install --cmake-args '-DCMAKE_EXPORT_COMPILE_COMMANDS=On'
6565
```
66+
67+
## Deploy
68+
Remove brltty first
69+
```Bash
70+
sudo apt purge brltty
71+
```
72+
Then install udev rules
73+
```Bash
74+
./Meta-ROS/tools/install.sh
75+
```
76+
Then plugin the peripheral board, and press
77+
```
78+
./Meta-ROS/tools/setupcan.sh
79+
```

decision/hero_vehicle/include/hero_vehicle/dbus_interpreter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "operation_interface/msg/dbus_control.hpp"
99
#include "operation_interface/msg/key_mouse.hpp"
10+
#include "operation_interface/msg/vt03.hpp"
1011
#include "behavior_interface/msg/move.hpp"
1112
#include "behavior_interface/msg/shoot.hpp"
1213
#include "behavior_interface/msg/aim.hpp"
@@ -18,6 +19,7 @@
1819

1920
using operation_interface::msg::DbusControl;
2021
using operation_interface::msg::KeyMouse;
22+
using operation_interface::msg::VT03;
2123
using behavior_interface::msg::Move;
2224
using behavior_interface::msg::Shoot;
2325
using behavior_interface::msg::Aim;
@@ -33,6 +35,8 @@ class DbusInterpreter
3335
void input_dbus(const DbusControl::SharedPtr msg);
3436

3537
void input_video_link(const KeyMouse::SharedPtr msg);
38+
39+
void input_video_link_vt03(const VT03::SharedPtr msg);
3640

3741
Move::SharedPtr get_move() const;
3842
geometry_msgs::msg::Twist get_move_ros2_control() const;

decision/hero_vehicle/src/dbus_interpreter.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,45 @@ void DbusInterpreter::input_video_link(const operation_interface::msg::KeyMouse:
7676
if(w_ || s_ || a_ || d_)
7777
last_video_link_recv_time = rclcpp::Clock().now();
7878
}
79+
void DbusInterpreter::input_video_link_vt03(const operation_interface::msg::VT03::SharedPtr msg)
80+
{
81+
// TODO remove keyboard_active_ since it is always true(from generator)
82+
keyboard_active_ = true;
83+
84+
w_ = msg->w;
85+
a_ = msg->a;
86+
s_ = msg->s;
87+
d_ = msg->d;
88+
shift_ = msg->shift;
89+
ctrl_ = msg->ctrl;
90+
q_ = msg->q;
91+
e_ = msg->e;
92+
r_ = msg->r;
93+
f_ = msg->f;
94+
g_ = msg->g;
95+
z_ = msg->z;
96+
x_ = msg->x;
97+
c_ = msg->c;
98+
v_ = msg->v;
99+
b_ = msg->b;
100+
left_button_ = msg->mouse_left;
101+
right_button_ = msg->mouse_right;
102+
// mouse_x_ = msg->mouse_x; TODO not convert to float yet
103+
// mouse_y_ = msg->mouse_y;
104+
// Video link will send packets even if no keys are pressed, except option panel(p) is active
105+
if(w_ || s_ || a_ || d_)
106+
last_video_link_recv_time = rclcpp::Clock().now();
107+
108+
// remote control
109+
ls_x = (msg->ch3-1024)/684.0; apply_deadzone(ls_x); // forward is positive
110+
ls_y = (msg->ch2-1024)/684.0; apply_deadzone(ls_y); // left is positive
111+
rs_x = (msg->ch0-1024)/684.0; apply_deadzone(rs_x); // up is positive
112+
rs_y = (msg->ch1-1024)/684.0; apply_deadzone(rs_y); // left is positive
113+
wheel = (msg->wheel-1024)/684.0; apply_deadzone(wheel);
114+
115+
if(msg->cns == 1) lsw = "MID";
116+
if(msg->cns == 0) lsw = ""; //rough shit
117+
}
79118

80119
void DbusInterpreter::update()
81120
{

decision/hero_vehicle/src/hero_vehicle.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class HeroVehicle : public rclcpp::Node
4343
key_sub_ = this->create_subscription<operation_interface::msg::KeyMouse>(
4444
"video_link_key_mouse", 10,
4545
std::bind(&HeroVehicle::key_callback, this, std::placeholders::_1));
46+
vt03_sub_ = this->create_subscription<operation_interface::msg::VT03>(
47+
"vt03_msg", 10,
48+
std::bind(&HeroVehicle::vt03_callback, this, std::placeholders::_1));
4649
}
4750

4851
// timer
@@ -57,6 +60,8 @@ class HeroVehicle : public rclcpp::Node
5760
private:
5861
rclcpp::Subscription<operation_interface::msg::DbusControl>::SharedPtr dbus_sub_;
5962
rclcpp::Subscription<operation_interface::msg::KeyMouse>::SharedPtr key_sub_;
63+
rclcpp::Subscription<operation_interface::msg::VT03>::SharedPtr vt03_sub_;
64+
6065
std::unique_ptr<DbusInterpreter> interpreter_;
6166
rclcpp::Publisher<behavior_interface::msg::Move>::SharedPtr move_pub_;
6267
rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr move_pub_ros2_control_;
@@ -76,6 +81,10 @@ class HeroVehicle : public rclcpp::Node
7681
{
7782
interpreter_->input_video_link(msg);
7883
}
84+
void vt03_callback(const operation_interface::msg::VT03::SharedPtr msg)
85+
{
86+
interpreter_->input_video_link_vt03(msg);
87+
}
7988

8089
void timer_callback()
8190
{

interfaces/operation_interface/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ rosidl_generate_interfaces(${PROJECT_NAME}
2020
"msg/WflyControl.msg"
2121
"msg/CustomController.msg"
2222
"msg/RobotState.msg"
23+
"msg/VT03.msg"
2324
)
2425
ament_export_dependencies(rosidl_default_runtime)
2526

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
uint16 ch0
2+
uint16 ch1
3+
uint16 ch2
4+
uint16 ch3
5+
uint8 cns
6+
uint8 pause
7+
bool left_btn
8+
bool right_btn
9+
uint16 wheel
10+
bool trigger
11+
uint16 mouse_x
12+
uint16 mouse_y
13+
uint16 mouse_z
14+
uint8 mouse_left
15+
uint8 mouse_right
16+
uint8 mouse_middle
17+
18+
bool w
19+
bool s
20+
bool a
21+
bool d
22+
bool shift
23+
bool ctrl
24+
bool q
25+
bool e
26+
bool r
27+
bool f
28+
bool g
29+
bool z
30+
bool x
31+
bool c
32+
bool v
33+
bool b

meta_bringup/config/hero.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ referee_serial:
130130
regular_link_port: "/dev/tty_REF"
131131
regular_link_baud: 115200
132132
video_link_port: "/dev/tty_VT02"
133-
video_link_baud: 115200
133+
video_link_baud: 921600
134134
isDebug: false
135-
debugUnhandledShown: false
135+
debugUnhandledShown: false
136+
warningShown: false

perception/referee_serial/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ add_library(referee_serial SHARED
3131
src/power_state.cpp
3232
src/custom_controller.cpp
3333
src/robot_state.cpp
34+
src/vt03_body.cpp
3435
src/crc.cpp)
3536

3637
target_include_directories(referee_serial PRIVATE

perception/referee_serial/include/referee_serial/referee_serial.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
#include "operation_interface/msg/power_state.hpp"
1717
#include "operation_interface/msg/custom_controller.hpp"
1818
#include "operation_interface/msg/robot_state.hpp"
19+
#include "operation_interface/msg/vt03.hpp"
1920

2021
#define REFEREE_SOF 0xA5
21-
#define VIDEO_LINK_REMOTECONTROL_SOF 0xA9
22+
#define VIDEO_LINK_REMOTECONTROL_LOWER_SOF 0xA9
23+
#define VIDEO_LINK_REMOTECONTROL_UPPER_SOF 0x53
2224

2325
using drivers::serial_driver::FlowControl;
2426
using drivers::serial_driver::Parity;
@@ -38,10 +40,12 @@ class RefereeSerial
3840
enum rx_status_t {
3941
WAIT_STARTING_BYTE, // receive bytes one by one, waiting for 0xA5
4042
WAIT_REMAINING_HEADER, // receive remaining header after SOF
41-
WAIT_CMD_ID_DATA_TAIL // receive cmd_id, data section and 2-byte CRC16 tailing
43+
WAIT_CMD_ID_DATA_TAIL, // receive cmd_id, data section and 2-byte CRC16 tailing
44+
VT03_REMAINING
4245
};
4346
enum {
44-
FRAME_HEADER_LENGTH=5
47+
FRAME_HEADER_LENGTH=5,
48+
FRAME_VT03_LENGTH=21
4549
};
4650
/**
4751
* @brief Constructor for the RefereeSerial class.
@@ -104,6 +108,7 @@ class RefereeSerial
104108
rclcpp::Publisher<operation_interface::msg::PowerState>::SharedPtr power_state_pub_;
105109
rclcpp::Publisher<operation_interface::msg::CustomController>::SharedPtr custom_controller_pub_;
106110
rclcpp::Publisher<operation_interface::msg::RobotState>::SharedPtr robot_state_pub_;
111+
rclcpp::Publisher<operation_interface::msg::VT03>::SharedPtr vt03_msg_pub_;
107112

108113
// Serial port
109114
std::unique_ptr<SerialDriver> regular_link_serial_driver_;
@@ -123,6 +128,7 @@ class RefereeSerial
123128

124129
bool isDebug = false;
125130
bool debugUnhandledShown = false;
131+
bool warningShown = false;
126132
};
127133

128134
#endif // REFEREE_SERIAL_HPP
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#ifndef VT03_BODY_HPP
2+
#define VT03_BODY_HPP
3+
#include "operation_interface/msg/vt03.hpp"
4+
class VT03_MSG
5+
{
6+
public:
7+
struct __attribute__((packed)) FrameType
8+
{
9+
uint16_t frame_header;
10+
11+
uint16_t ch0:11, ch1:11, ch2:11, ch3:11;
12+
uint8_t cns:2, pause:1, left_btn:1, right_btn:1;
13+
uint16_t wheel:11;
14+
uint8_t trigger:1, dummy_1:3;
15+
16+
int16_t mouse_x, mouse_y, mouse_z;
17+
uint8_t mouse_left:2, mouse_right:2, mouse_middle:2, dummy_2:2;
18+
19+
uint8_t w:1, s:1, a:1, d:1, shift:1, ctrl:1, q:1, e:1, r:1, f:1, g:1, z:1, x:1, c:1, v:1, b:1;
20+
21+
uint16_t crc16;
22+
23+
};
24+
25+
FrameType interpreted; /**< The interpreted frame */
26+
27+
/**
28+
* @brief Constructs a KeyMouse object from a frame.
29+
* This would interpret the frame by copying the data into the FrameType struct.
30+
* @param frame The frame to construct the KeyMouse object from.
31+
*/
32+
VT03_MSG(const std::vector<uint8_t> &frame);
33+
34+
/**
35+
* @brief Sets the message based on the current state.
36+
* This function copies the current state data into the message object.
37+
* @note Should be called before publishing the message.
38+
*/
39+
operation_interface::msg::VT03 msg();
40+
};
41+
#endif

0 commit comments

Comments
 (0)