-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the capra_micro_comm_py package as a 'dependency' (I'll talk ab…
…out it in the pull request)
- Loading branch information
1 parent
2ab9a42
commit 5897cff
Showing
7 changed files
with
387 additions
and
542 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|
Oops, something went wrong.