Add blaster fire message

master
PgSocks 2 years ago
parent f2918b441d
commit 90552382db

@ -16,6 +16,7 @@ add_library(robomaster
src/modules/sdk.c
src/modules/chassis.c
src/modules/gimbal.c
src/modules/blaster.c
src/connection.c
src/robomaster.c
src/robo.c

@ -0,0 +1,33 @@
#pragma once
#include "message.h"
#include <stdbool.h>
#include <stdint.h>
static const uint8_t BLASTER_HOST = 23;
static const uint8_t BLASTER_INDEX = 0;
#define BLASTER_FIRE_CMD 0x513F
enum FIRETYPE {
FIRETYPE_WATER = 0,
FIRETYPE_INFRARED = 1
};
enum FIRETIMES {
ONE = 1,
TWO = 2,
THREE = 3,
FOUR = 4,
FIVE = 5
};
void
blaster_fire (
union Request* req,
uint16_t seq,
bool ack,
enum FIRETYPE type,
enum FIRETIMES times );

@ -248,6 +248,21 @@ struct PACKED SetSdkConnectionResp {
struct Footer footer;
};
struct PACKED BlasterFireReq {
struct Header header;
struct {
uint8_t type : 4;
uint8_t times : 4;
};
struct Footer footer;
};
struct PACKED BlasterFireResp {
struct Header header;
uint8_t retcode;
struct Footer footer;
};
union Request {
struct Header header;
struct SetSdkConnectionReq sdkconn;
@ -261,6 +276,7 @@ union Request {
struct SubNodeResetReq subnodereset;
struct SubscribeAddNodeReq subnodeadd;
struct GimbalCtrlSpeedReq gimbspeed;
struct BlasterFireReq blaster;
};
union Response {
struct Header header;
@ -275,6 +291,7 @@ union Response {
struct SubNodeResetResp subnodereset;
struct SubscribeAddNodeResp subnodeadd;
struct GimbalCtrlSpeedResp gimbspeed;
struct BlasterFireResp blaster;
};
union Message {
struct Header header;

@ -65,6 +65,8 @@ int robot_drive(Robot, float x, float y, float r);
*/
int robot_led(Robot, unsigned char r, unsigned char g, unsigned char b);
int robot_blast(Robot);
/*
* If the robot is in ready mode, this makes the robot send a heartbeat in
* the next tick of the work function. The work function will not do anything

@ -8,6 +8,7 @@ typedef struct Client* Client;
#include "chassis.h"
#include "sdk.h"
#include "gimbal.h"
#include "blaster.h"
Client client_new();
void client_connect(Client client);

@ -37,6 +37,8 @@ message_length(int cmd) {
return sizeof(struct ChassisSpeedModeReq);
case GIMBAL_CTRL_SPEED_CMD:
return sizeof(struct GimbalCtrlSpeedReq);
case BLASTER_FIRE_CMD:
return sizeof(struct BlasterFireReq);
default:
return 0;
}
@ -60,6 +62,8 @@ message_module(int cmd) {
return host2byte(CHASSIS_HOST, CHASSIS_INDEX);
case GIMBAL_CTRL_SPEED_CMD:
return host2byte(GIMBAL_HOST, GIMBAL_INDEX);
case BLASTER_FIRE_CMD:
return host2byte(BLASTER_HOST, BLASTER_INDEX);
default:
return 0;
}

@ -0,0 +1,16 @@
#include "message.h"
#include "connection.h"
#include "robomaster.h"
void
blaster_fire (
union Request* req,
uint16_t seq,
bool ack,
enum FIRETYPE type,
enum FIRETIMES times ) {
req->blaster.type = type;
req->blaster.times = times;
req_finalize(seq, BLASTER_FIRE_CMD, ack, req);
}

@ -5,6 +5,8 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
struct RobotImp {
struct Client* client;
@ -19,6 +21,8 @@ struct RobotImp {
int16_t gimbal[2];
bool dirty_gimbal;
bool dirty_blaster;
bool sdk_mode;
enum {
@ -37,6 +41,12 @@ struct RobotImp {
};
int
robot_blast(Robot robot) {
robot->dirty_blaster = true;
return 1;
}
int
robot_drive(Robot robot, float x, float y, float r) {
// TODO: move individual wheel speed calculation to work function
@ -185,6 +195,15 @@ robot_work(Robot robot) {
req_send(robot->client->dev_conn, &req);
robot->dirty_colors = false;
}
if(robot->dirty_blaster) {
blaster_fire (
&req, robot->seq++, false,
FIRETYPE_INFRARED,
ONE
);
req_send(robot->client->dev_conn, &req);
robot->dirty_blaster = false;
}
break;
}

@ -90,6 +90,9 @@ int main(int argc, char* argv[]) {
robot_led(robot, colors[color].r, colors[color].g, colors[color].b);
color = (color + 1) % 3;
break;
case SDL_SCANCODE_RETURN:
robot_blast(robot);
break;
default: break;
}
break;

Loading…
Cancel
Save