Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Chassis/Bot.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ namespace bot {
rightoutput = constrain(rightoutput,1000,2000);

// Invert the appropriate side
rightoutput = map(rightoutput,1000,2000,2000,1000);
// rightoutput = map(rightoutput,1000,2000,2000,1000);
leftoutput = map(leftoutput,1000,2000,2000,1000);

//Send out to the motors
motorLeft.writeMicroseconds(leftoutput);
Expand Down Expand Up @@ -166,7 +167,7 @@ int maxright=0;
// *10 // convert from volt to decivolt
// /1024 // Divide by ADC steps to get voltage
// ;
//TODO: Add board support to properly scale down 12V inputs to
//TODO: iAdd board support to properly scale down 12V inputs to
return 15;
}

Expand Down
28 changes: 17 additions & 11 deletions Chassis/Chassis.ino
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ void setup() {
Scheduler.startLoop(recieve_input);

//Informative tasks for debugging
// Scheduler.startLoop(print_status);
Scheduler.startLoop(print_status);
// Scheduler.startLoop(printControl);
Scheduler.startLoop(printTelemetry);
// Scheduler.startLoop(printTelemetry);
}

bool isEnabled=false;
Expand Down Expand Up @@ -172,7 +172,7 @@ void recieve_input(){
){
//valid data; Handle it appropriately
chassisControlData.data = radioBuffer.ccd;
// Serial.printf("[OK %2i%s] ",
// Serial.printf("\n[OK %2i%s] ",
// chassisControlData.data.metadata.heartbeat,
// chassisControlData.data.enable?"+":"-"
// );
Expand All @@ -181,17 +181,23 @@ void recieve_input(){
//pet the watchdog to keep the system alive
watchdog=0;
}
else if(
radiobufferlen==CANNON_CONTROL_SIZE_BYTES &&
radioBuffer.ccd.metadata.type==PacketType::CANNON_CONTROL
){
//Catch to avoid printing stuff
}
else{
//Some other packet type
//Print out info about it
// Serial.printf("?(%i) ",radiobufferlen);
// for(int i = 0; i < radiobufferlen; i++){
// for(int j = 0; j < 8; j++){
// Serial.print((radioBuffer.buffer[i]>>(7-j)) &1);
// }
// Serial.print(".");
// }
// Serial.println();
Serial.printf("\n?(%i) ",radiobufferlen);
for(int i = 0; i < radiobufferlen; i++){
for(int j = 0; j < 8; j++){
Serial.print((radioBuffer.buffer[i]>>(7-j)) &1);
}
Serial.print(".");
}
Serial.println();

}
}
Expand Down
2 changes: 1 addition & 1 deletion Controller/Buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace Buttons{
// normalizeAnalog(Buttons::leftX(),131,(543+500)/2 ,886,50)
JoystickAxesConfig configLeftY={
.min=163,
.max=684,
.max=886,
.idleMin=493,
.idleMax=535
};
Expand Down
58 changes: 57 additions & 1 deletion Controller/Controller.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <SPI.h>
#include <RH_RF95.h>
#include <Scheduler.h>
#include <Adafruit_SleepyDog.h>

#include "Buttons.h"
// #include "Pins.h"
Expand Down Expand Up @@ -34,6 +33,12 @@ union ChassisTelemetryData {
uint8_t buffer[CHASSIS_TELEMETRY_SIZE_BYTES];
} chassisTelemetryData;

union CannonControlData {
CannonControl data;
uint8_t buffer[CANNON_CONTROL_SIZE_BYTES];
} cannonControlData;


union RadioBuffer{
ChassisControl chassisControl;
ChassisTelemetry chassisTelemetry;
Expand Down Expand Up @@ -87,6 +92,10 @@ void setup() {
Scheduler.startLoop(printChassisControl);
Scheduler.startLoop(printChassisTelemetry);

Scheduler.startLoop(sendCannonControl);
// Scheduler.startLoop(printCannonControl);


//Helpful for debugging hardware
// Scheduler.startLoop(Buttons::printDebug);
// Scheduler.startLoop(print_status);
Expand All @@ -106,6 +115,7 @@ void loop() {

/** Monitor hardware + do the things. */
void updateControls(){

if(Buttons::home2() >1500 && chassisControlData.data.enable==false){
chassisControlData.data.enable=true;
}
Expand Down Expand Up @@ -148,6 +158,12 @@ void updateControls(){
stick.y*=-1; //Covert y from HID standard of negative-is-away to positive robot forward
chassisControlData.data.speed = Chassis::arcadeDrive( stick.y, stick.x*.25 );


cannonControlData.data.fire=Buttons::a();
cannonControlData.data.load=Buttons::x();
cannonControlData.data.enable=chassisControlData.data.enable;


delay(10);
}

Expand Down Expand Up @@ -175,6 +191,45 @@ void send_control() {
delay(sleepTime.chassisControl);
}

elapsedMillis cannontimer;
void sendCannonControl() {
//Observe the need of RX mode to reserve the radio;
//In such cases, just hang out until it passes control back
while (rf95.mode() == RHGenericDriver::RHModeRx) delay(1);

cannonControlData.data.metadata.type = PacketType::CANNON_CONTROL;
cannonControlData.data.metadata.heartbeat+=1;

bool sent = false;
sent = rf95.send(cannonControlData.buffer, CANNON_CONTROL_SIZE_BYTES);
bool done = rf95.waitPacketSent(200);
// Serial.println();
// Serial.print("#");
// Serial.print(sent ? ">>" : "--");
// Serial.print(done ? "++" : "--");
cctimer = 0;

delay(sleepTime.chassisControl);
}

void printCannonControl(){
Serial.println();

Serial.print(" <Cannon ");

Serial.printf(
"%2s ",cannonControlData.data.enable?"EN":"--."
);
Serial.printf(
"F%2s ",cannonControlData.data.fire?"!!":"--."
);
Serial.printf(
"L%2s ",cannonControlData.data.load?"!!":"--."
);

delay(200);
}


elapsedMillis cttimer;
void recieve_telemetry() {
Expand Down Expand Up @@ -269,6 +324,7 @@ void printChassisTelemetry(){
delay(200);
}


/** Print some very detailed information about the Control packets
* May be necessary to troubleshoot communication related issues
*/
Expand Down
42 changes: 26 additions & 16 deletions ModuleTShirtCannon/ModuleTShirtCannon.ino
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ void loop(){
//Heartbeat LED
if (cannonHeartbeat > 1000){
cannonHeartbeat=0;
digitalWrite(BUILT_IN_LED, !digitalRead(BUILT_IN_LED));
Serial.print("cannon ");
Serial.print(cannonControlData.data.metadata.heartbeat);
Serial.println("");

digitalWrite(BUILT_IN_LED, !digitalRead(BUILT_IN_LED) || cannonControlData.data.enable );
}

//Read the encoder from the subfile
Expand Down Expand Up @@ -190,8 +194,14 @@ void loop(){
elevationServo.writeMicroseconds(elevationMotorOutput);

//Run State Machine
cannonTrigger = millis()%3000 > 1500;
// cannonTrigger = millis()%3000 > 1500;
cannonTrigger = cannonControlData.data.fire && cannonControlData.data.enable;

if(cannonControlData.data.load){
manualReloadSwitch = ManualReloadSwitch::UNLOCKED;
}else{
manualReloadSwitch = ManualReloadSwitch::DONE;
}
run_state_machine(cannonTrigger,manualReloadSwitch);

delay(10);
Expand Down Expand Up @@ -226,15 +236,15 @@ void recieve_input(){
if (rf95.recv(radioBuffer.buffer, &radiobufferlen)) {

if(
radiobufferlen==CANNON_CONTROL_SIZE_BYTES &&
// radiobufferlen==CANNON_CONTROL_SIZE_BYTES &&
radioBuffer.ccd.metadata.type==PacketType::CANNON_CONTROL
){
//valid data; Handle it appropriately
cannonControlData.data = radioBuffer.ccd;
// Serial.printf("[OK %2i%s] ",
// chassisControlData.data.metadata.heartbeat,
// chassisControlData.data.enable?"+":"-"
// );
Serial.printf("[OK %2i%s] ",
cannonControlData.data.metadata.heartbeat,
cannonControlData.data.enable?"+":"-"
);


//pet the watchdog to keep the system alive
Expand All @@ -243,19 +253,19 @@ void recieve_input(){
else{
//Some other packet type
//Print out info about it
// Serial.printf("?(%i) ",radiobufferlen);
// for(int i = 0; i < radiobufferlen; i++){
// for(int j = 0; j < 8; j++){
// Serial.print((radioBuffer.buffer[i]>>(7-j)) &1);
// }
// Serial.print(".");
// }
// Serial.println();
Serial.printf("?(%i) ",radiobufferlen);
for(int i = 0; i < radiobufferlen; i++){
for(int j = 0; j < 8; j++){
Serial.print((radioBuffer.buffer[i]>>(7-j)) &1);
}
Serial.print(".");
}
Serial.println();

}
}
} else {
// Serial.print(".");
Serial.print(".");
}

//We want this to go as fast as possible; Effectively our default task
Expand Down
2 changes: 1 addition & 1 deletion libraries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module/usin

Using Arduino's library manager, you'll need to install a few additional libraries

- RadioHead (a library)
- Encoder by Paul Stroffregen
- elapsedMillis by Paul Stroffregen
- RadioHead by Mike Mccauley
- Scheduler by Arduino
- PCAL6416A-IO-Expander (Not available in the arduino library - acquire via sneakernet)