Skip to content

Commit

Permalink
a lot of scrutineering
Browse files Browse the repository at this point in the history
  • Loading branch information
andtsa committed Jul 10, 2024
1 parent e270a77 commit 5a721fc
Show file tree
Hide file tree
Showing 26 changed files with 358 additions and 107 deletions.
10 changes: 8 additions & 2 deletions app/src/core/communication/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ pub async fn can_receiving_handler(
// frame.header().format();
let id = id_as_value(frame.id());
#[cfg(debug_assertions)]
data_sender.send(Datapoint::new(Datatype::ReceivedCan, id as u64, bytes_to_u64(frame.data()))).await;
data_sender
.send(Datapoint::new(
Datatype::ReceivedCan,
id as u64,
bytes_to_u64(frame.data()),
))
.await;
#[cfg(debug_assertions)]
info!("[CAN ({})] received frame: id={:?} data={:?}", bus_nr, id, frame.data());
if DATA_IDS.contains(&id) {
Expand Down Expand Up @@ -90,7 +96,7 @@ pub async fn can_receiving_handler(
timestamp.as_ticks(),
)
.await;
} else if gfd_counter > 2 && frame.data()[2] == 0xFE{
} else if gfd_counter > 2 && frame.data()[2] == 0xFE {
gfd_counter = 0;
can_sender
.send(
Expand Down
20 changes: 20 additions & 0 deletions app/src/core/communication/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use embassy_net::Stack;
use embassy_stm32::eth::generic_smi::GenericSMI;
use embassy_stm32::eth::Ethernet;
use embassy_stm32::peripherals::ETH;
use embassy_time::Instant;
use embassy_time::Timer;
use embedded_io_async::Write;
use heapless::Deque;
Expand All @@ -15,9 +16,13 @@ use crate::core::communication::Datapoint;
use crate::pconfig::embassy_socket_from_config;
use crate::Command;
use crate::DataReceiver;
use crate::DataSender;
use crate::Datatype;
use crate::Event;
use crate::EventSender;
use crate::COMMAND_HASH;
use crate::DATA_HASH;
use crate::EVENTS_HASH;
use crate::GS_IP_ADDRESS;
use crate::IP_TIMEOUT;
use crate::NETWORK_BUFFER_SIZE;
Expand All @@ -32,6 +37,7 @@ pub async fn tcp_connection_handler(
stack: &'static Stack<Ethernet<'static, ETH, GenericSMI>>,
event_sender: EventSender,
data_receiver: DataReceiver,
data_sender: DataSender,
) -> ! {
let mut last_valid_timestamp = embassy_time::Instant::now().as_millis();
// info!("------------------------------------------------ TCP Connection Handler Started! ------------------------------------------");
Expand Down Expand Up @@ -69,6 +75,15 @@ pub async fn tcp_connection_handler(
},
}
event_sender.send(Event::ConnectionEstablishedEvent).await;
data_sender
.send(Datapoint::new(Datatype::CommandHash, COMMAND_HASH, Instant::now().as_ticks()))
.await;
data_sender
.send(Datapoint::new(Datatype::DataHash, DATA_HASH, Instant::now().as_ticks()))
.await;
data_sender
.send(Datapoint::new(Datatype::EventsHash, EVENTS_HASH, Instant::now().as_ticks()))
.await;
// let mut connection = client.connect(gs_addr).await.unwrap();
// info!("----------------------------------------------------------------Connected to ground station==========================");

Expand Down Expand Up @@ -203,6 +218,11 @@ pub async fn tcp_connection_handler(
info!("[tcp] Start Run command received");
event_sender.send(Event::RunStarting).await;
},
Command::ContinueRun(_) => {
#[cfg(debug_assertions)]
info!("[tcp] Start Run command received");
event_sender.send(Event::ContinueRunEvent).await;
},
Command::Shutdown(_) => {
#[cfg(debug_assertions)]
info!("[tcp] Shutdown command received");
Expand Down
7 changes: 6 additions & 1 deletion app/src/core/controllers/ethernet_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use static_cell::StaticCell;
use crate::core::communication::tcp::tcp_connection_handler;
use crate::try_spawn;
use crate::DataReceiver;
use crate::DataSender;
use crate::EventSender;
use crate::Irqs;
use crate::POD_MAC_ADDRESS;
Expand Down Expand Up @@ -47,6 +48,7 @@ impl EthernetController {
x: Spawner,
sender: EventSender,
receiver: DataReceiver,
data_sender: DataSender,
pins: EthernetPins,
) -> Self {
let mut rng = Rng::new(pins.p_rng, Irqs);
Expand Down Expand Up @@ -100,7 +102,10 @@ impl EthernetController {

try_spawn!(sender, x.spawn(net_task(stack)));

try_spawn!(sender, x.spawn(tcp_connection_handler(x, stack, sender, receiver)));
try_spawn!(
sender,
x.spawn(tcp_connection_handler(x, stack, sender, receiver, data_sender))
);
// unwrap!(x.spawn(udp_connection_handler(stack)));

ethernet_controller
Expand Down
5 changes: 4 additions & 1 deletion app/src/core/controllers/finite_state_machine_peripherals.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use defmt::debug;
use embassy_executor::Spawner;
use embassy_stm32::adc::Adc;
use embassy_stm32::gpio::{Input, Level, Pull};
use embassy_stm32::gpio::Input;
use embassy_stm32::gpio::Level;
use embassy_stm32::gpio::Output;
use embassy_stm32::gpio::Pull;
use embassy_stm32::gpio::Speed;
use embassy_stm32::Peripherals;

Expand Down Expand Up @@ -65,6 +67,7 @@ impl FSMPeripherals {
*x,
i.event_sender,
i.data_receiver,
i.data_sender,
EthernetPins {
p_rng: p.RNG,
eth_pin: p.ETH,
Expand Down
11 changes: 3 additions & 8 deletions app/src/core/data/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ pub enum Subsystems {
Levitation,
}

pub const GROUND_STATION_DATA: [Datatype; 1] = [
Datatype::ResponseHeartbeat,
];
pub const GROUND_STATION_DATA: [Datatype; 1] = [Datatype::ResponseHeartbeat];

pub const SENSOR_HUB_DATA: [Datatype; 9] = [
Datatype::Acceleration,
Expand All @@ -24,11 +22,8 @@ pub const SENSOR_HUB_DATA: [Datatype; 9] = [
Datatype::GyroscopeZ,
];

pub const PROPULSION_DATA: [Datatype; 3] = [
Datatype::PropulsionSpeed,
Datatype::PropulsionVoltage,
Datatype::PropulsionCurrent,
];
pub const PROPULSION_DATA: [Datatype; 3] =
[Datatype::PropulsionSpeed, Datatype::PropulsionVoltage, Datatype::PropulsionCurrent];

pub const HV_BMS_DATA: [Datatype; 3] = [
Datatype::BatteryBalanceHigh,
Expand Down
95 changes: 88 additions & 7 deletions app/src/core/finite_state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use embassy_time::Instant;

use crate::core::communication::Datapoint;
use crate::core::controllers::finite_state_machine_peripherals::FSMPeripherals;
use crate::core::fsm_status::Location;
use crate::core::fsm_status::Route;
use crate::core::fsm_status::RouteUse;
use crate::core::fsm_status::Status;
use crate::DataSender;
use crate::Datatype;
Expand Down Expand Up @@ -115,11 +117,56 @@ impl Fsm {
State::RunConfig => self.entry_run_config(),
State::HVOn => self.entry_hv_on(),
State::Levitating => self.entry_levitating(),
State::MovingST => self.entry_mv_st(),
State::MovingLSST => self.entry_ls_st(),
State::MovingLSCV => self.entry_ls_cv(),
State::EndST => self.entry_end_st(),
State::EndLS => self.entry_end_ls(),
State::MovingST => {
self.data_queue
.send(Datapoint::new(
Datatype::RoutePlan,
self.route.positions.into(),
self.route.current_position as u64,
))
.await;
self.entry_mv_st()
},
State::MovingLSST => {
self.data_queue
.send(Datapoint::new(
Datatype::RoutePlan,
self.route.positions.into(),
self.route.current_position as u64,
))
.await;
self.entry_ls_st()
},
State::MovingLSCV => {
self.data_queue
.send(Datapoint::new(
Datatype::RoutePlan,
self.route.positions.into(),
self.route.current_position as u64,
))
.await;
self.entry_ls_cv()
},
State::EndST => {
self.data_queue
.send(Datapoint::new(
Datatype::RoutePlan,
self.route.positions.into(),
self.route.current_position as u64,
))
.await;
self.entry_end_st()
},
State::EndLS => {
self.data_queue
.send(Datapoint::new(
Datatype::RoutePlan,
self.route.positions.into(),
self.route.current_position as u64,
))
.await;
self.entry_end_ls()
},
State::EmergencyBraking => {
self.entry_emergency_braking();
self.pod_safe().await;
Expand Down Expand Up @@ -169,16 +216,50 @@ impl Fsm {

Event::DcOn => {
self.peripherals.hv_peripherals.dc_dc.set_high();
}
},

Event::DcOff => {
self.peripherals.hv_peripherals.dc_dc.set_low();
}
},

///////////////////
// Debugging events
Event::SetOverrides(overrides) => self.status.overrides.set(overrides),

Event::ContinueRunEvent => {
match self.route.next_position() {
Location::ForwardA | Location::BackwardsA => {
transit!(self, State::MovingST);
},
Location::ForwardB | Location::BackwardsB => {
transit!(self, State::EndST);
},
Location::ForwardC | Location::BackwardsC => {
transit!(self, State::EndLS);
},
Location::LaneSwitchStraight => {
transit!(self, State::MovingLSST);
},
Location::LaneSwitchCurved => {
transit!(self, State::MovingLSCV);
},
Location::StopAndWait => {
transit!(self, State::Levitating);
},
Location::BrakeHere => {
transit!(self, State::Exit);
},
}
self.data_queue
.send(Datapoint::new(
Datatype::RoutePlan,
self.route.positions.into(),
self.route.current_position as u64,
))
.await;
return;
},

// Override enabling or disabling propulsion GPIO
Event::DisablePropulsionCommand => {
self.peripherals.propulsion_controller.disable();
Expand Down
2 changes: 1 addition & 1 deletion app/src/core/fsm_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Overrides {
/// Enable or disable braking from a falling edge of the braking communication signal
pub fn prevent_braking_communication(&self) -> bool { self.values & 0b10 != 0 }

/// Allow HV ON without brakes armed
/// Allow HV ON without brakes armed
pub fn hv_without_brakes_armed(&self) -> bool { self.values & 0b100 != 0 }
}

Expand Down
4 changes: 4 additions & 0 deletions config/commands.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ id = 0xff
name = "StartRun"
id = 0x5d

[[Command]]
name = "ContinueRun"
id = 0x5e

[[Command]]
name = "StartHV"
id = 0x60
Expand Down
22 changes: 21 additions & 1 deletion config/datatypes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ id = 0x225
name = "Temp_EMS_4"
id = 0x226


[[Datatype]]
name = "SingleCellVoltageHigh_1"
id = 0x3C0
Expand Down Expand Up @@ -807,3 +806,24 @@ id = 0x163
name = "SendingCANEvent"
id = 0x164

[[Datatype]]
name = "RoutePlan"
id = 0x165

[[Datatype]]
name = "CurrentPosition"
id = 0x166

[[Datatype]]
name = "CommandHash"
id = 0x167

[[Datatype]]
name = "EventsHash"
id = 0x168

[[Datatype]]
name = "DataHash"
id = 0x169


5 changes: 5 additions & 0 deletions config/events.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ name = "RunStarting"
id = 0xb9
priority = 1

[[Event]]
name = "ContinueRunEvent"
id = 0xbd
priority = 1

[[Event]]
name = "SystemResetCommand"
id = 0xbE
Expand Down
21 changes: 21 additions & 0 deletions config/procedures/State Machine States.procedure
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Full Pushed-Run State Machine Demonstration

Id:
DH08.PROC.SC.SM

People:
1 Embedded Software Engineer as Ground Station Operator and Procedure lead
1 Safety Officer at the end of track
1 Person in the track to push the pod

Items:
Ground Station setup

Procedures:
<guus power on procedure>
<ground station power on procedure>
Ensure localisation is enabled and sends reasonable readings
Bring the pod to ForwardA section of the track
...


16 changes: 15 additions & 1 deletion gs/src/lib/components/FSM.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,21 @@
let interval: NodeJS.Timeout;
onMount(() => {
all_states = [boot_state, est_con_state, idle_state, run_conf_state, exit_state, hv_on_state, emerg_brake_state, levi_state, moving_st, moving_ls_cv, moving_ls_end, moving_st_end, moving_ls_st];
all_states = [
boot_state,
est_con_state,
run_conf_state,
idle_state,
hv_on_state,
levi_state,
moving_st,
moving_ls_st,
moving_ls_cv,
moving_st_end,
moving_ls_end,
emerg_brake_state,
exit_state
];
interval = setInterval(() => {
turn_off_all(all_states);
Expand Down
Loading

0 comments on commit 5a721fc

Please sign in to comment.