Skip to content

Commit

Permalink
[Milestone] Armed motors and savings (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
victoryforphil authored Nov 13, 2024
1 parent 00e4765 commit c763c0f
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 32 deletions.
Binary file added .lil/rpanion.local/.DS_Store
Binary file not shown.
Binary file added .lil/rpanion.local/logs/.DS_Store
Binary file not shown.
35 changes: 35 additions & 0 deletions ansible/playbooks/collect_lil_logs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
- name: Collect and clear .lil log folders from remote hosts
hosts: myhosts
become: yes

tasks:
- name: Create local .lil directory if it doesn't exist
become: no
delegate_to: localhost
file:
path: "{{ lookup('env','PWD') }}/.lil"
state: directory
mode: '0755'

- name: Copy remote .lil log folder to local machine
become: no
delegate_to: localhost
synchronize:
src: /lil-hopps/.lil/
dest: "{{ lookup('env','PWD') }}/.lil/{{ inventory_hostname }}/"
mode: pull
recursive: yes

- name: Remove contents of remote .lil log folder
file:
path: /lil-hopps/.lil/
state: absent

- name: Recreate remote .lil log folder
file:
path: /lil-hopps/.lil/
state: directory
mode: '0777'
owner: pi
group: pi
8 changes: 5 additions & 3 deletions ansible/playbooks/deploy_quad_idle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
[Service]
Type=simple
ExecStart=/lil-hopps/quad_idle
Restart=on-failure
Environment="LIL_DIR=."
WorkingDirectory=/lil-hopps
ExecStart=/lil-hopps/quad_idle -c serial:/dev/serial0:115200 --hz 15 -s 0.0.0.0:7777
Restart=always
User=root
[Install]
Expand All @@ -57,7 +59,7 @@
systemd:
name: quad_idle
enabled: yes
state: stopped
state: started
daemon_reload: yes
handlers:
- name: Reload systemd
Expand Down
22 changes: 12 additions & 10 deletions lil-gcs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ fn parse_message(message: &str) -> (String, Vec<String>) {

#[tokio::main]
async fn main() {
let (tcp_tx, _) = broadcast::channel(4);
let (ws_tx, mut ws_rx) = mpsc::channel(32);
let (tcp_tx, _) = broadcast::channel(512);
let (ws_tx, mut ws_rx) = mpsc::channel(512);

// Spawn WebSocket server task
tokio::spawn(webserver::websocket_server_task(tcp_tx.clone(), ws_tx));
Expand Down Expand Up @@ -303,22 +303,22 @@ async fn main() {
tokio::spawn(async move {
loop {
// thread::sleep(Duration::from_secs_f32(2.0));
tokio::time::sleep(Duration::from_millis(200)).await;
tokio::time::sleep(Duration::from_millis(250)).await;
{
let mut map = subscriber_handle_clone.lock().unwrap();

if !map.update.is_empty() {
let data = map
.update
let updates= map.update.clone();
map.update.clear();
drop(map);
if !updates.is_empty() {
let data = updates
.iter()
.map(|(topic, datapoint)| DataLine {
topic: topic.to_string(),
datapoint: datapoint.to_string(),
})
.collect::<Vec<DataLine>>();

map.update.clear();


let message = WebMessage {
timestamp: get_current_timestamp(),
data,
Expand All @@ -330,12 +330,14 @@ async fn main() {
warn!("Failed to MsgPack the DataStore Map")
}
}


}
}
});
let datastore = datastore.clone();
loop {
tokio::time::sleep(Duration::from_millis(100)).await;
tokio::time::sleep(Duration::from_millis(50)).await;
datastore.lock().unwrap().run_sync();
}
}
26 changes: 17 additions & 9 deletions lil-launcher/bin_tests/quad_idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use clap::Parser;
use victory_broker::adapters::tcp::TCPServerAdapter;
use victory_broker::adapters::tcp::TCPServerOptions;
use victory_commander::system::runner::BasherSysRunner;
use victory_data_store::database::retention::RetentionPolicy;
use victory_data_store::primitives::Primitives;
use victory_data_store::sync::adapters::tcp::tcp_server::TcpSyncServer;
use victory_data_store::sync::config::SyncConfig;
Expand All @@ -51,7 +52,6 @@ struct SILArgs {
)]
duration: f32,


#[clap(short, long, value_parser, help = "TCP Sync Server address")]
sync_server_address: String,

Expand All @@ -75,7 +75,7 @@ async fn main() {
.with_line_number(false)
.without_time()
.init();

let args = SILArgs::parse();
info!("Running 'quad_sil' with args: {:#?}", args);

Expand All @@ -84,17 +84,26 @@ async fn main() {
let server_handle = Arc::new(Mutex::new(server));

let topic_filter = TopicKey::from_str("cmd");

let sync_config = SyncConfig {
client_name: "Quad Idle".to_string(),
subscriptions: vec![topic_filter.display_name()],
};
runner.data_store
runner
.data_store
.lock()
.unwrap()
.setup_sync(sync_config, server_handle);

let retention_policy = RetentionPolicy {
max_age: Some(Timespan::new_secs(30.0)),
max_rows: Some(64),
};
runner.data_store.lock().unwrap().set_retention(retention_policy);

runner.dt = Timespan::new_hz(args.hz as f64);
runner.set_end_time(Timepoint::new_secs(60. * 15.));


runner.add_system(Arc::new(Mutex::new(
QuadlinkSystem::new_from_connection_string(args.connection_string.as_str()).unwrap(),
Expand All @@ -104,11 +113,10 @@ async fn main() {
check_ekf: Some(true),
}))));

/*
runner.add_system(Arc::new(Mutex::new(RerunSystem::new(
"quad_arm".to_string(),
))));
*/
runner.add_system(Arc::new(Mutex::new(RerunSystem::new(
"quad_idle".to_string(),
))));

runner.set_real_time(true);
runner.run();
}
2 changes: 1 addition & 1 deletion lil-launcher/bin_tests/quad_sil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct SILArgs {
#[tokio::main]
async fn main() {
fmt()
.with_max_level(Level::INFO)
.with_max_level(Level::DEBUG)
.with_target(true)
.pretty()
.compact()
Expand Down
12 changes: 4 additions & 8 deletions lil-rerun/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,7 @@ impl System for RerunSystem {
if let (Primitives::Float(roll), Primitives::Float(pitch), Primitives::Float(yaw)) =
(roll, pitch, yaw)
{
let (roll, pitch, yaw) = (
roll * 180.0 / std::f64::consts::PI,
pitch * 180.0 / std::f64::consts::PI,
yaw * 180.0 / std::f64::consts::PI,
);
let quat = UnitQuaternion::from_euler_angles(roll, pitch, yaw);
let quat = quat.quaternion();
let quat = UnitQuaternion::from_euler_angles(*roll, *pitch, *yaw);
rerun
.log(
"attitude",
Expand Down Expand Up @@ -152,7 +146,9 @@ impl System for RerunSystem {

fn get_subscribed_topics(&self) -> std::collections::BTreeSet<TopicKey> {
let mut topics = BTreeSet::new();
topics.insert(TopicKey::empty());
topics.insert(TopicKey::from_str("status"));
topics.insert(TopicKey::from_str("cmd"));
topics.insert(TopicKey::from_str("pose"));
topics
}
}
2 changes: 2 additions & 0 deletions scripts/offload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
ansible-playbook -i ansible/inventory.ini ansible/playbooks/collect_lil_logs.yml

0 comments on commit c763c0f

Please sign in to comment.