Skip to content

Commit

Permalink
Added the capra_micro_comm_py package as a 'dependency' (I'll talk ab…
Browse files Browse the repository at this point in the history
…out it in the pull request)
  • Loading branch information
IliTheButterfly committed Apr 14, 2024
1 parent 2ab9a42 commit 5897cff
Show file tree
Hide file tree
Showing 7 changed files with 387 additions and 542 deletions.
101 changes: 80 additions & 21 deletions src/rove_control_board/api/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
/* This was generated by capra_micro_comm.
* DO NOT EDIT
*/

#include <capra_comm.h>

// --- ENUMS ---

// --- STRUCTS ---
struct Void
{
euint8_t pad0;
};
static_assert(sizeof(Void) == 1);

struct Bool
struct Bool_
{
eboolean_t b;
};
static_assert(sizeof(Bool) == 1);
static_assert(sizeof(Bool_) == 1);

struct Byte
{
Expand Down Expand Up @@ -73,37 +74,95 @@ struct Vector2D
};
static_assert(sizeof(Vector2D) == 8);

struct State
struct Status
{
eboolean_t state;
euint16_t statusCode;
};
static_assert(sizeof(State) == 1);
static_assert(sizeof(Status) == 2);

struct Status
struct RGB
{
euint8_t statusCode;
euint8_t r;
euint8_t g;
euint8_t b;
};
static_assert(sizeof(Status) == 1);
static_assert(sizeof(RGB) == 3);

struct RGB
struct LED
{
efloat_t r;
efloat_t g;
efloat_t b;
euint16_t i;
RGB c;
euint8_t pad0;
};
static_assert(sizeof(RGB) == 12);
static_assert(sizeof(LED) == 6);

struct Report
{
Vector2D pos;
Status status;
euint8_t pad0;
euint8_t pad1;
};
static_assert(sizeof(Report) == 12);

struct Bounds
{
efloat_t lower;
efloat_t upper;
};
static_assert(sizeof(Bounds) == 8);

struct PIDConfig
{
efloat_t p;
efloat_t i;
efloat_t d;
Bounds bounds;
};
static_assert(sizeof(PIDConfig) == 20);

struct Config
{
PIDConfig horizPID;
PIDConfig vertiPID;
};
static_assert(sizeof(Config) == 40);

// --- COMMANDS ---
Void ledOn(Void);
Bool_ setLedColor(LED);
static_assert((sizeof(LED)+1) == 7);

Bool_ setFrontLedState(Bool_);
static_assert((sizeof(Bool_)+1) == 2);

Bool_ setBackLedState(Bool_);
static_assert((sizeof(Bool_)+1) == 2);

Bool_ setTPVPosition(Vector2D);
static_assert((sizeof(Vector2D)+1) == 9);

Vector2D getTPVPosition(Void);
static_assert((sizeof(Void)+1) == 2);

Void ledOff(Void);
Bool_ setTPVSpeed(Vector2D);
static_assert((sizeof(Vector2D)+1) == 9);

Report getReport(Void);
static_assert((sizeof(Void)+1) == 2);

Bool_ setConfig(Config);
static_assert((sizeof(Config)+1) == 41);

BaseFunction_ptr commands[] = {
new Function<Void, Void>(&ledOn),
new Function<Void, Void>(&ledOff),
new Function<Bool_, LED>(&setLedColor),
new Function<Bool_, Bool_>(&setFrontLedState),
new Function<Bool_, Bool_>(&setBackLedState),
new Function<Bool_, Vector2D>(&setTPVPosition),
new Function<Vector2D, Void>(&getTPVPosition),
new Function<Bool_, Vector2D>(&setTPVSpeed),
new Function<Report, Void>(&getReport),
new Function<Bool_, Config>(&setConfig),
};
#define COMMANDS_COUNT 2
#define MAX_DECODED_SIZE 13
#define MAX_ENCODED_SIZE 21
#define COMMANDS_COUNT 8
#define MAX_DECODED_SIZE 41
#define MAX_ENCODED_SIZE 57
108 changes: 108 additions & 0 deletions src/rove_control_board/api/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#pragma once

#include <inttypes.h>

#ifndef CMD_BUFF_SIZE
#define CMD_BUFF_SIZE 64
#endif // CMD_BUFF_SIZE

// Define types with known lengths for encoding
#ifdef ARDUINO
using euint8_t = uint8_t;
using eint8_t = int8_t;
using euint16_t = uint16_t;
using eint16_t = int16_t;
using euint32_t = uint32_t;
using eint32_t = int32_t;
using euint64_t = uint64_t;
using eint64_t = int64_t;
using efloat_t = float;
using eboolean_t = bool;

#include <Arduino.h>

class EmptyStream : public Stream
{
public:
int available() override { return 0; }
int read() override { return 0; }
int peek() override { return 0; }
void flush() override { }
size_t write(uint8_t) override { return 0; }
void begin(int) {};
operator bool() {return true;}
};

#ifndef SAM
extern EmptyStream debug = EmptyStream();
extern Serial_& comm = Serial
#else
extern Serial_& debug;
extern UARTClass& comm;
#endif

#define DebugVar(var) { debug.print(#var); debug.print(": "); debug.print(var); }
#define DebugVarln(var) { debug.print(#var); debug.print(": "); debug.println(var); }
#define Debug(...) debug.print(__VA_ARGS__)
#define Debugln(...) debug.println(__VA_ARGS__)


inline void debugByte(uint8_t b)
{
debug.print(b, 2);
debug.print('|');
}

inline void debugBytes(uint8_t* b, size_t count)
{
for (uint8_t* bb = b; bb < b + count; ++bb)
{
debug.print(*bb, 2);
debug.print('|');
}
debug.println();
for (uint8_t* bb = b; bb < b + count; ++bb)
{
debug.print(*bb, 16);
debug.print('|');
}
debug.println();
}
#else
using euint8_t = uint8_t;
using eint8_t = int8_t;
using euint16_t = uint16_t;
using eint16_t = int16_t;
using euint32_t = uint32_t;
using eint32_t = int32_t;
using euint64_t = uint64_t;
using eint64_t = int64_t;
using efloat_t = float;
using eboolean_t = bool;


#define DebugVar(var)
#define DebugVarln(var)
#define Debug(...)
#define Debugln(...)
#define debugByte(b)
#define debugBytes(b, c)
#endif // ARDUINO



// Verify type lengths
static_assert(sizeof(uint8_t) == 1);

static_assert(sizeof(euint8_t) == 1);
static_assert(sizeof(eint8_t) == 1);
static_assert(sizeof(euint16_t) == 2);
static_assert(sizeof(eint16_t) == 2);
static_assert(sizeof(euint32_t) == 4);
static_assert(sizeof(eint32_t) == 4);
static_assert(sizeof(euint64_t) == 8);
static_assert(sizeof(eint64_t) == 8);
static_assert(sizeof(efloat_t) == 4);
static_assert(sizeof(eboolean_t) == 1);


102 changes: 79 additions & 23 deletions src/rove_control_board/rove_control_board/api.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,95 @@
from rove_control_board.capra_micro_comm import BinaryData, SerialCommandManager, Void, CommandManager
from typing import NoReturn
import capra_micro_comm_py as comm

manager = SerialCommandManager()
manager = comm.SerialCommandManager()

@manager.struct('ff')
class Vector2D(BinaryData):
class Vector2D(comm.BinaryData):
def __init__(self, x:float=0, y:float=0):
super().__init__(x=x, y=y)
self.x:float
self.y:float

@manager.struct('?')
class State(BinaryData):
def __init__(self, state:bool=False):
super().__init__(state=state)
self.state:bool

@manager.struct('B')
class Status(BinaryData):
@manager.struct('H')
class Status(comm.BinaryData):
def __init__(self, statusCode:int = 0):
super().__init__(statusCode=statusCode)
self.statusCode:int

@manager.struct('fff')
class RGB(BinaryData):
def __init__(self, r:float=0,g:float=0,b:float=0):
@manager.struct('BBB')
class RGB(comm.BinaryData):
def __init__(self, r:int=0,g:int=0,b:int=0):
super().__init__(r=r,g=g,b=b)
self.r:float
self.g:float
self.b:float
self.r:int
self.g:int
self.b:int

@manager.struct('H_x')
class LED(comm.BinaryData):
def __init__(self, i:int=0, c:RGB=RGB(0,0,0)):
super().__init__(i=i, c=c)


@manager.struct('__xx')
class Report(comm.BinaryData):
def __init__(self, pos:Vector2D=Vector2D(), status:Status=Status()):
super().__init__(pos=pos, status=status)
self.pos:Vector2D
self.status:Status

@manager.struct('ff')
class Bounds(comm.BinaryData):
def __init__(self, lower:float=0, upper:float=0):
super().__init__(lower=lower, upper=upper)
self.lower:float
self.upper:float

@manager.struct('fff_')
class PIDConfig(comm.BinaryData):
def __init__(self, p:float=1, i:float=0, d:float=0, bounds:Bounds=Bounds()):
super().__init__(p=p,i=i,d=d, bounds=bounds)
self.p:float
self.i:float
self.d:float
self.bounds:Bounds

@manager.struct('__')
class Config(comm.BinaryData):
def __init__(self, horizPID:PIDConfig=PIDConfig(),vertiPID:PIDConfig=PIDConfig()):
super().__init__(horizPID=horizPID, vertiPID=vertiPID)
self.horizPID:PIDConfig
self.vertiPID:PIDConfig

@manager.command(LED, comm.Bool_)
def setLedColor(led:LED) -> comm.Bool_:
pass

@manager.command(comm.Bool_, comm.Bool_)
def setFrontLedState(state:comm.Bool_) -> comm.Bool_:
pass

@manager.command(comm.Bool_, comm.Bool_)
def setBackLedState(state:comm.Bool_) -> comm.Bool_:
pass

@manager.command(Vector2D, comm.Bool_)
def setTPVPosition(pos:Vector2D) -> comm.Bool_:
pass

@manager.command(comm.Void, Vector2D)
def getTPVPosition() -> Vector2D:
pass

@manager.command(Vector2D, comm.Bool_)
def setTPVSpeed(speed:Vector2D) -> comm.Bool_:
pass

@manager.command(comm.Void, Report)
def getReport() -> Report:
pass

@manager.command(Void, Void)
def ledOn():
print("on")
@manager.command(Config, comm.Bool_)
def setConfig(config:Config) -> comm.Bool_:
pass

@manager.command(Void, Void)
def ledOff():
print("off")

Loading

0 comments on commit 5897cff

Please sign in to comment.