Skip to content

Commit

Permalink
Implementing Rocket Commanding
Browse files Browse the repository at this point in the history
  • Loading branch information
bwz5 committed Nov 18, 2024
1 parent d6eb215 commit bb24fbb
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 32 deletions.
6 changes: 1 addition & 5 deletions fill/actuators/sol_valve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ SolValve::SolValve(){

SolValve::~SolValve(){}



void SolValve::open(){
pinMode(SV_SIGNAL, OUTPUT);
digitalWrite(SV_SIGNAL, HIGH);
Expand All @@ -37,6 +35,4 @@ void SolValve::close(){
pinMode(SV_SIGNAL, OUTPUT);
digitalWrite(SV_SIGNAL, LOW);
isOpen=false;
}


}
12 changes: 3 additions & 9 deletions fill/fill_station.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,9 @@ class CommanderServiceImpl final : public Commander::Service
sv1.close();
}
}
if (request->sv2_close()){
// send TCP command to rocket_controller
}
if (request->mav_open()){
// send TCP command to rocket_controller
}
if (request->fire()){
// send TCP command to rocket_controller
}

protoBuild.sendCommand(request);

return Status::OK;
}
};
Expand Down
55 changes: 41 additions & 14 deletions fill/umbilical/proto_build.cc
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
#include "proto_build.h"
#include <iostream>

RocketTelemetryProtoBuilder::RocketTelemetryProtoBuilder(): serial_data(usb_port, std::ios::binary){}
RocketTelemetryProtoBuilder::RocketTelemetryProtoBuilder(): serial_data(usb_port, std::ios::in | std::ios::out | std::ios::binary){}

RocketTelemetryProtoBuilder::~RocketTelemetryProtoBuilder(){
serial_data.close();
}

void RocketTelemetryProtoBuilder::sendCommand(const Command* com) {
if (com->has_sv2_close()){
if (com->sv2_close()) {
serial_data << (uint8_t)CLOSE_SV << std::flush;
} else {
serial_data << (uint8_t)OPEN_SV << std::flush;
}
}

if (com->has_mav_open()){
if (com->mav_open()){
serial_data << (uint8_t)OPEN_MAV << std::flush;
} else {
serial_data << (uint8_t)CLOSE_MAV << std::flush;
}
}

if (com->launch()){
serial_data << (uint8_t)LAUNCH << std::flush;
}
// if (com->clear_sd()){
// serial_data << (uint8_t)CLEAR_SD << std::flush;
// }
}

RocketTelemetry RocketTelemetryProtoBuilder::buildProto(){
RocketTelemetry rocketTelemetry;

if (!serial_data){
if (serial_data.is_open()){
RocketUmbTelemetry* rocketUmbTelemetry = rocketTelemetry.mutable_umb_telem();
RocketMetadata* rocketMetadata = rocketUmbTelemetry->mutable_metadata();
Events* events = rocketUmbTelemetry->mutable_events();


uint16_t metadata;
uint32_t ms_since_boot;
Expand All @@ -27,17 +51,20 @@ RocketTelemetry RocketTelemetryProtoBuilder::buildProto(){
float pt4;
float temp;

serial_data.read(reinterpret_cast<char*>(&metadata), sizeof(metadata));
serial_data.read(reinterpret_cast<char*>(&ms_since_boot), sizeof(ms_since_boot));
serial_data.read(reinterpret_cast<char*>(&events_val), sizeof(events_val));
char packet[28];
serial_data.getline(packet, UMB_PACKET_SIZE);

memcpy(&metadata, packet, sizeof(metadata));
memcpy(&ms_since_boot, packet + 2, sizeof(ms_since_boot));
memcpy(&events_val, packet + 6, sizeof(events_val));

serial_data.read(reinterpret_cast<char*>(&radio_state), sizeof(radio_state));
serial_data.read(reinterpret_cast<char*>(&transmit_state), sizeof(transmit_state));
memcpy(&radio_state, packet + 10, sizeof(radio_state));
memcpy(&transmit_state, packet + 11, sizeof(transmit_state));

serial_data.read(reinterpret_cast<char*>(&voltage), sizeof(voltage));
serial_data.read(reinterpret_cast<char*>(&pt3), sizeof(pt3));
serial_data.read(reinterpret_cast<char*>(&pt4), sizeof(pt4));
serial_data.read(reinterpret_cast<char*>(&temp), sizeof(temp));
memcpy(&voltage, packet + 12, sizeof(voltage));
memcpy(&pt3, packet + 16, sizeof(pt3));
memcpy(&pt4, packet + 20, sizeof(pt4));
memcpy(&temp, packet + 24, sizeof(temp));

rocketMetadata->set_alt_armed(static_cast<bool>(metadata & 0x1));
rocketMetadata->set_alt_valid(static_cast<bool>((metadata & 0x2) >> 1));
Expand Down Expand Up @@ -109,7 +136,7 @@ RocketTelemetry RocketTelemetryProtoBuilder::buildProto(){
rocketUmbTelemetry->set_rtd_temp(temp);

} else {
printf("Serial port is not open.");
std::cout << "Serial port is not open.\n";
}
return rocketTelemetry;
}
16 changes: 14 additions & 2 deletions fill/umbilical/proto_build.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#ifndef PROTO_BUILD_H
#define PROTO_BUILD_H

#define LAUNCH '0'
#define OPEN_MAV '1'
#define CLOSE_MAV '2'
#define OPEN_SV '3'
#define CLOSE_SV '4'
#define CLEAR_SD '5'

#define UMB_PACKET_SIZE 28

#include <fstream>
#include "protos/command.grpc.pb.h"
#include <iostream>
Expand All @@ -10,17 +19,20 @@ using command::RocketMetadata;
using command::Events;
using command::FlightMode;
using command::RocketUmbTelemetry;
using command::Command;

class RocketTelemetryProtoBuilder {
private:
const char* usb_port = "/dev/ttyACM0";
const char* usb_port = "/dev/rocket";

std::ifstream serial_data;
std::fstream serial_data;
public:
// Establish serial connection
RocketTelemetryProtoBuilder();
~RocketTelemetryProtoBuilder();

void sendCommand(const Command* com);

RocketTelemetry buildProto();
};

Expand Down
2 changes: 1 addition & 1 deletion go-proxies/proxy_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ pushd ..
docker build -t ghcr.io/cornellrocketryteam/fill-telem-proxy:latest -f go-proxies/fill-telem-proxy/Dockerfile . &
docker build -t ghcr.io/cornellrocketryteam/rocket-telem-proxy:latest -f go-proxies/rocket-telem-proxy/Dockerfile . &
docker build -t ghcr.io/cornellrocketryteam/websocket-proxy:latest -f go-proxies/websocket-proxy/Dockerfile .
popd
popd
3 changes: 2 additions & 1 deletion protos/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ message Command {
optional bool ignite = 5;
optional bool sv2_close = 6;
optional bool mav_open = 7;
optional bool fire = 8;
optional bool launch = 8;
// optional bool clear_sd = 9;
}

// The response message containing an ack
Expand Down

0 comments on commit bb24fbb

Please sign in to comment.