2 Commits
Author SHA1 Message Date
pgsocks 463fe60a1b Increment major version
The low level API needed to change to accomodate the hight level API,
which is a major revision.
2023-02-21 14:25:48 -06:00
pgsocks d883385d8c Implement simple SDK API 2023-02-21 14:25:48 -06:00
12 changed files with 15 additions and 215 deletions
-59
View File
@@ -1,59 +0,0 @@
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
-2
View File
@@ -15,10 +15,8 @@ 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
-20
View File
@@ -1,20 +0,0 @@
#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 );
-26
View File
@@ -168,30 +168,6 @@ 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;
@@ -260,7 +236,6 @@ union Request {
struct SetRobotModeReq mvmode;
struct SubNodeResetReq subnodereset;
struct SubscribeAddNodeReq subnodeadd;
struct GimbalCtrlSpeedReq gimbspeed;
};
union Response {
struct Header header;
@@ -274,7 +249,6 @@ union Response {
struct SetRobotModeResp mvmode;
struct SubNodeResetResp subnodereset;
struct SubscribeAddNodeResp subnodeadd;
struct GimbalCtrlSpeedResp gimbspeed;
};
union Message {
struct Header header;
+2 -13
View File
@@ -1,8 +1,8 @@
#pragma once
// Handle for the high level robot interface
struct RobotImp;
typedef struct RobotImp* Robot;
struct Robot;
typedef struct Robot* Robot;
/*
* Return a handle to the high level robot interface, or NULL on error.
@@ -29,17 +29,6 @@ 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.
-1
View File
@@ -7,7 +7,6 @@ typedef struct Client* Client;
#include "message.h"
#include "chassis.h"
#include "sdk.h"
#include "gimbal.h"
Client client_new();
void client_connect(Client client);
-4
View File
@@ -35,8 +35,6 @@ 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;
}
@@ -58,8 +56,6 @@ 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;
}
+2 -2
View File
@@ -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, ack, req);
req_finalize(seq, SET_WHEEL_SPEED_CMD, false, 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, ack, req);
req_finalize(seq, CHASSIS_SPEED_MODE_CMD, false, req);
}
-18
View File
@@ -1,18 +0,0 @@
#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
View File
@@ -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, ack, req);
req_finalize(seq, SET_SDK_CONNECTION_CMD, true, req);
}
void
@@ -27,7 +27,7 @@ set_sdk_mode(
bool ack,
bool enable ) {
req->sdkmode.enable = enable;
req_finalize(seq, SET_SDK_MODE_CMD, ack, req);
req_finalize(seq, SET_SDK_MODE_CMD, true, req);
}
void
@@ -35,7 +35,7 @@ sdk_heartbeat(
union Request* req,
uint16_t seq,
bool ack ) {
req_finalize(seq, SDK_HEARTBEAT_CMD, ack, req);
req_finalize(seq, SDK_HEARTBEAT_CMD, false, 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, ack, req);
req_finalize(seq, SET_ROBOT_MODE_CMD, true, 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, ack, req);
req_finalize(seq, SUBNODE_RESET_CMD, true, 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, ack, req);
req_finalize(seq, SUBSCRIBE_ADD_NODE_CMD, true, req);
}
void
@@ -93,6 +93,6 @@ set_system_led (
req->led.t1 = t1;
req->led.t2 = t2;
req_finalize(seq, SET_SYSTEM_LED_CMD, ack, req);
req_finalize(seq, SET_SYSTEM_LED_CMD, true, req);
}
+3 -23
View File
@@ -5,7 +5,7 @@
#include <string.h>
#include <stdlib.h>
struct RobotImp {
struct Robot {
struct Client* client;
uint16_t seq;
@@ -16,9 +16,6 @@ struct RobotImp {
uint8_t colors[3];
bool dirty_colors;
int16_t gimbal[2];
bool dirty_gimbal;
bool sdk_mode;
enum {
@@ -49,14 +46,6 @@ 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;
@@ -162,15 +151,6 @@ 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,
@@ -249,8 +229,8 @@ robot_work(Robot robot) {
}
Robot robot_new() {
struct RobotImp* robot = malloc(sizeof(struct RobotImp));
memset(robot, 0, sizeof(struct RobotImp));
struct Robot* robot = malloc(sizeof(struct Robot));
memset(robot, 0, sizeof(struct Robot));
return robot;
}
+1 -40
View File
@@ -16,11 +16,9 @@ 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) {
@@ -29,15 +27,10 @@ static Uint32 heartbeat_timer_handler(Uint32 interval, void* param) {
}
int main(int argc, char* argv[]) {
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 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,
@@ -54,9 +47,6 @@ 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)) {
@@ -89,36 +79,8 @@ 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:
@@ -128,7 +90,6 @@ int main(int argc, char* argv[]) {
}
}
SDL_JoystickClose(joystick);
SDL_Quit();
return 0;
}