Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
507ec8ba59 | ||
|
|
f2918b441d | ||
|
|
150c450210 | ||
|
|
19993ced8e | ||
|
|
2c42352c85 | ||
|
|
0b238ce048 | ||
|
|
2258812fc2 | ||
|
|
31d7e57125 |
@@ -0,0 +1,59 @@
|
||||
name: Bug Report
|
||||
about: File a bug report
|
||||
title: "[Bug]: "
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this bug report!
|
||||
- type: input
|
||||
id: contact
|
||||
attributes:
|
||||
label: Contact Details
|
||||
description: How can we get in touch with you if we need more info?
|
||||
placeholder: ex. email@example.com
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: what-happened
|
||||
attributes:
|
||||
label: What happened?
|
||||
description: Also tell us, what did you expect to happen?
|
||||
placeholder: Tell us what you see!
|
||||
value: "A bug happened!"
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: version
|
||||
attributes:
|
||||
label: Version
|
||||
description: What version of our software are you running?
|
||||
options:
|
||||
- 1.0.2 (Default)
|
||||
- 1.0.3 (Edge)
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: browsers
|
||||
attributes:
|
||||
label: What browsers are you seeing the problem on?
|
||||
multiple: true
|
||||
options:
|
||||
- Firefox
|
||||
- Chrome
|
||||
- Safari
|
||||
- Microsoft Edge
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: Relevant log output
|
||||
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
|
||||
render: shell
|
||||
- type: checkboxes
|
||||
id: terms
|
||||
attributes:
|
||||
label: Code of Conduct
|
||||
description: By submitting this issue, you agree to follow our [Code of Conduct](https://example.com)
|
||||
options:
|
||||
- label: I agree to follow this project's Code of Conduct
|
||||
required: true
|
||||
@@ -15,8 +15,10 @@ add_library(robomaster
|
||||
src/message.c
|
||||
src/modules/sdk.c
|
||||
src/modules/chassis.c
|
||||
src/modules/gimbal.c
|
||||
src/connection.c
|
||||
src/robomaster.c
|
||||
src/robo.c
|
||||
)
|
||||
|
||||
target_include_directories(robomaster
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "message.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint8_t GIMBAL_HOST = 4;
|
||||
static const uint8_t GIMBAL_INDEX = 0;
|
||||
|
||||
#define GIMBAL_CTRL_SPEED_CMD 0x0C04
|
||||
|
||||
void
|
||||
gimbal_ctrl_speed (
|
||||
union Request* req,
|
||||
uint16_t seq,
|
||||
bool ack,
|
||||
int16_t p,
|
||||
int16_t y,
|
||||
int16_t r );
|
||||
@@ -168,6 +168,30 @@ struct PACKED SetChassisWheelSpeedResp
|
||||
struct Footer footer;
|
||||
};
|
||||
|
||||
struct PACKED GimbalCtrlSpeedReq
|
||||
{
|
||||
struct Header header;
|
||||
// Values between -360 and 360
|
||||
union {
|
||||
int16_t yrp[3];
|
||||
struct {
|
||||
int16_t yaw;
|
||||
int16_t roll;
|
||||
int16_t pitch;
|
||||
};
|
||||
};
|
||||
// Always 0xDC
|
||||
uint8_t ctrl;
|
||||
struct Footer footer;
|
||||
};
|
||||
|
||||
struct PACKED GimbalCtrlSpeedResp
|
||||
{
|
||||
struct Header header;
|
||||
int8_t retcode;
|
||||
struct Footer footer;
|
||||
};
|
||||
|
||||
struct PACKED SetWheelSpeedReq
|
||||
{
|
||||
struct Header header;
|
||||
@@ -236,6 +260,7 @@ union Request {
|
||||
struct SetRobotModeReq mvmode;
|
||||
struct SubNodeResetReq subnodereset;
|
||||
struct SubscribeAddNodeReq subnodeadd;
|
||||
struct GimbalCtrlSpeedReq gimbspeed;
|
||||
};
|
||||
union Response {
|
||||
struct Header header;
|
||||
@@ -249,6 +274,7 @@ union Response {
|
||||
struct SetRobotModeResp mvmode;
|
||||
struct SubNodeResetResp subnodereset;
|
||||
struct SubscribeAddNodeResp subnodeadd;
|
||||
struct GimbalCtrlSpeedResp gimbspeed;
|
||||
};
|
||||
union Message {
|
||||
struct Header header;
|
||||
|
||||
+13
-2
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
// Handle for the high level robot interface
|
||||
struct Robot;
|
||||
typedef struct Robot* Robot;
|
||||
struct RobotImp;
|
||||
typedef struct RobotImp* Robot;
|
||||
|
||||
/*
|
||||
* Return a handle to the high level robot interface, or NULL on error.
|
||||
@@ -29,6 +29,17 @@ int robot_init(Robot robot);
|
||||
*/
|
||||
int robot_stop(Robot robot);
|
||||
|
||||
/*
|
||||
* Set the gimble speed. A packet will be sent to the robot on
|
||||
* the next ready tick of the work function.
|
||||
*
|
||||
* robot: The robot to set the velocity of
|
||||
* p: pitch speed
|
||||
* y: yaw speed
|
||||
* returns: 0 on success, non-zero on failure
|
||||
*/
|
||||
int robot_aim(Robot, float p, float y);
|
||||
|
||||
/*
|
||||
* Set the velocity of the robot chassis. A packet will be sent to the robot on
|
||||
* the next ready tick of the work function.
|
||||
|
||||
@@ -7,6 +7,7 @@ typedef struct Client* Client;
|
||||
#include "message.h"
|
||||
#include "chassis.h"
|
||||
#include "sdk.h"
|
||||
#include "gimbal.h"
|
||||
|
||||
Client client_new();
|
||||
void client_connect(Client client);
|
||||
|
||||
@@ -35,6 +35,8 @@ message_length(int cmd) {
|
||||
return sizeof(struct SetWheelSpeedReq);
|
||||
case CHASSIS_SPEED_MODE_CMD:
|
||||
return sizeof(struct ChassisSpeedModeReq);
|
||||
case GIMBAL_CTRL_SPEED_CMD:
|
||||
return sizeof(struct GimbalCtrlSpeedReq);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@@ -56,6 +58,8 @@ message_module(int cmd) {
|
||||
case SET_WHEEL_SPEED_CMD:
|
||||
case CHASSIS_SPEED_MODE_CMD:
|
||||
return host2byte(CHASSIS_HOST, CHASSIS_INDEX);
|
||||
case GIMBAL_CTRL_SPEED_CMD:
|
||||
return host2byte(GIMBAL_HOST, GIMBAL_INDEX);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ set_wheel_speed (
|
||||
req->wheel.wheel_speed[1] = w2;
|
||||
req->wheel.wheel_speed[2] = w3;
|
||||
req->wheel.wheel_speed[3] = w4;
|
||||
req_finalize(seq, SET_WHEEL_SPEED_CMD, false, req);
|
||||
req_finalize(seq, SET_WHEEL_SPEED_CMD, ack, req);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -29,5 +29,5 @@ chassis_speed_mode (
|
||||
req->chsspeed.speed[0] = x;
|
||||
req->chsspeed.speed[1] = y;
|
||||
req->chsspeed.speed[2] = z;
|
||||
req_finalize(seq, CHASSIS_SPEED_MODE_CMD, false, req);
|
||||
req_finalize(seq, CHASSIS_SPEED_MODE_CMD, ack, req);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "message.h"
|
||||
#include "connection.h"
|
||||
#include "robomaster.h"
|
||||
|
||||
void
|
||||
gimbal_ctrl_speed (
|
||||
union Request* req,
|
||||
uint16_t seq,
|
||||
bool ack,
|
||||
int16_t p,
|
||||
int16_t y,
|
||||
int16_t r ) {
|
||||
req->gimbspeed.yaw = y;
|
||||
req->gimbspeed.roll = r;
|
||||
req->gimbspeed.pitch = p;
|
||||
req->gimbspeed.ctrl = 0xDC;
|
||||
req_finalize(seq, GIMBAL_CTRL_SPEED_CMD, ack, req);
|
||||
}
|
||||
+7
-7
@@ -17,7 +17,7 @@ set_sdk_connection(
|
||||
req->sdkconn.protocol = 0;
|
||||
req->sdkconn.ip_address = ip_address;
|
||||
req->sdkconn.port = port;
|
||||
req_finalize(seq, SET_SDK_CONNECTION_CMD, true, req);
|
||||
req_finalize(seq, SET_SDK_CONNECTION_CMD, ack, req);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -27,7 +27,7 @@ set_sdk_mode(
|
||||
bool ack,
|
||||
bool enable ) {
|
||||
req->sdkmode.enable = enable;
|
||||
req_finalize(seq, SET_SDK_MODE_CMD, true, req);
|
||||
req_finalize(seq, SET_SDK_MODE_CMD, ack, req);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -35,7 +35,7 @@ sdk_heartbeat(
|
||||
union Request* req,
|
||||
uint16_t seq,
|
||||
bool ack ) {
|
||||
req_finalize(seq, SDK_HEARTBEAT_CMD, false, req);
|
||||
req_finalize(seq, SDK_HEARTBEAT_CMD, ack, req);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -45,7 +45,7 @@ set_robot_mode (
|
||||
bool ack,
|
||||
enum MOVEMENTMODE mode ) {
|
||||
req->mvmode.mode = mode;
|
||||
req_finalize(seq, SET_ROBOT_MODE_CMD, true, req);
|
||||
req_finalize(seq, SET_ROBOT_MODE_CMD, ack, req);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -54,7 +54,7 @@ subnode_reset (
|
||||
uint16_t seq,
|
||||
bool ack ) {
|
||||
req->subnodereset.hostbyte = host2byte(CLIENT_HOST, CLIENT_INDEX);
|
||||
req_finalize(seq, SUBNODE_RESET_CMD, true, req);
|
||||
req_finalize(seq, SUBNODE_RESET_CMD, ack, req);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -64,7 +64,7 @@ subscribe_add_node (
|
||||
bool ack ) {
|
||||
req->subnodeadd.hostbyte = host2byte(CLIENT_HOST, CLIENT_INDEX);
|
||||
req->subnodeadd.sub_vision = 0x03000000;
|
||||
req_finalize(seq, SUBSCRIBE_ADD_NODE_CMD, true, req);
|
||||
req_finalize(seq, SUBSCRIBE_ADD_NODE_CMD, ack, req);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -93,6 +93,6 @@ set_system_led (
|
||||
req->led.t1 = t1;
|
||||
req->led.t2 = t2;
|
||||
|
||||
req_finalize(seq, SET_SYSTEM_LED_CMD, true, req);
|
||||
req_finalize(seq, SET_SYSTEM_LED_CMD, ack, req);
|
||||
|
||||
}
|
||||
|
||||
+23
-3
@@ -5,7 +5,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct Robot {
|
||||
struct RobotImp {
|
||||
|
||||
struct Client* client;
|
||||
uint16_t seq;
|
||||
@@ -16,6 +16,9 @@ struct Robot {
|
||||
uint8_t colors[3];
|
||||
bool dirty_colors;
|
||||
|
||||
int16_t gimbal[2];
|
||||
bool dirty_gimbal;
|
||||
|
||||
bool sdk_mode;
|
||||
|
||||
enum {
|
||||
@@ -46,6 +49,14 @@ robot_drive(Robot robot, float x, float y, float r) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
robot_aim(Robot robot, float p, float y) {
|
||||
robot->gimbal[0] = p * 360;
|
||||
robot->gimbal[1] = y * 360;
|
||||
robot->dirty_gimbal = true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
robot_led(Robot robot, unsigned char r, unsigned char g, unsigned char b) {
|
||||
robot->colors[0] = r;
|
||||
@@ -151,6 +162,15 @@ robot_work(Robot robot) {
|
||||
req_send(robot->client->dev_conn, &req);
|
||||
robot->dirty_wheels = false;
|
||||
}
|
||||
if(robot->dirty_gimbal) {
|
||||
gimbal_ctrl_speed (
|
||||
&req, robot->seq++, false,
|
||||
robot->gimbal[0],
|
||||
robot->gimbal[1],
|
||||
0 );
|
||||
req_send(robot->client->dev_conn, &req);
|
||||
robot->dirty_gimbal = false;
|
||||
}
|
||||
if(robot->dirty_colors) {
|
||||
set_system_led (
|
||||
&req, robot->seq++, false,
|
||||
@@ -229,8 +249,8 @@ robot_work(Robot robot) {
|
||||
}
|
||||
|
||||
Robot robot_new() {
|
||||
struct Robot* robot = malloc(sizeof(struct Robot));
|
||||
memset(robot, 0, sizeof(struct Robot));
|
||||
struct RobotImp* robot = malloc(sizeof(struct RobotImp));
|
||||
memset(robot, 0, sizeof(struct RobotImp));
|
||||
return robot;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,11 @@ struct {
|
||||
};
|
||||
int color = 0;
|
||||
|
||||
float pitch = 0, yaw = 0;
|
||||
float x = 0, y = 0, z = 0;
|
||||
static Uint32 drive_timer_handler(Uint32 interval, void* param) {
|
||||
robot_drive((Robot)param, x, y, z);
|
||||
robot_aim((Robot)param, pitch, yaw);
|
||||
return 75;
|
||||
}
|
||||
static Uint32 heartbeat_timer_handler(Uint32 interval, void* param) {
|
||||
@@ -27,10 +29,15 @@ static Uint32 heartbeat_timer_handler(Uint32 interval, void* param) {
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) {
|
||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
|
||||
fprintf(stderr, "%s", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
printf("Detected %d joysticks\n", SDL_NumJoysticks());
|
||||
SDL_Joystick* joystick = NULL;
|
||||
if(SDL_NumJoysticks() > 0) {
|
||||
joystick = SDL_JoystickOpen(0);
|
||||
}
|
||||
SDL_Window* win = SDL_CreateWindow(
|
||||
"Robomaster",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
@@ -47,6 +54,9 @@ int main(int argc, char* argv[]) {
|
||||
SDL_AddTimer(75, drive_timer_handler, robot);
|
||||
SDL_AddTimer(1000, heartbeat_timer_handler, robot);
|
||||
|
||||
int h, w;
|
||||
SDL_GetWindowSize(win, &w, &h);
|
||||
|
||||
while(robot_work(robot)) {
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event)) {
|
||||
@@ -79,8 +89,36 @@ int main(int argc, char* argv[]) {
|
||||
case SDL_SCANCODE_SPACE:
|
||||
robot_led(robot, colors[color].r, colors[color].g, colors[color].b);
|
||||
color = (color + 1) % 3;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
yaw = (float)event.motion.xrel;
|
||||
pitch = (float)event.motion.yrel;
|
||||
break;
|
||||
case SDL_JOYAXISMOTION:
|
||||
switch(event.jaxis.axis) {
|
||||
case 0:
|
||||
x = (float)event.jaxis.value / 32767;
|
||||
break;
|
||||
case 1:
|
||||
y = (float)event.jaxis.value / 32767;
|
||||
break;
|
||||
case 4:
|
||||
z = (float)event.jaxis.value / 32767 / 2;
|
||||
break;
|
||||
case 2:
|
||||
yaw = (float)event.jaxis.value / 32767;
|
||||
break;
|
||||
case 3:
|
||||
pitch = (float)event.jaxis.value / 32767;
|
||||
break;
|
||||
default:
|
||||
printf("axis: %d\n", event.jaxis.axis);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
if(event.window.event != SDL_WINDOWEVENT_CLOSE) break;
|
||||
case SDL_QUIT:
|
||||
@@ -90,6 +128,7 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
SDL_JoystickClose(joystick);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user