-
Notifications
You must be signed in to change notification settings - Fork 6
Add vehicle module #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add vehicle module #109
Conversation
295bad5
to
e58ff22
Compare
src/device/recording/mod.rs
Outdated
trace!("Handling RecordingManager request: Success"); | ||
Ok(ans) | ||
pub async fn zenoh_pose_bridge(latest_pose: Arc<RwLock<Option<VehicleData>>>) { | ||
let session = match zenoh::open(zenoh::Config::default()).await { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's missing the service configuration as declared in mavlink-camera-manager and mavlink-server, for more information about it check the zBlueberry document that I sent to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added new config following our requirements,
please check the load/save/generate steps and let me know you have some suggestions.
src/device/recording/mod.rs
Outdated
}; | ||
let sub = match session.declare_subscriber("mavlink/1/1/AHRS2").await { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should subscribe to mavlink/**/1/AHRS2 to work with any system id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to use :
mavlink//1/ATTITUDE and mavlink//1/GLOBAL_POSITION_INT
where both are used to generate:
let pose = VehicleData {
roll: att.roll,
pitch: att.pitch,
yaw: att.yaw,
alt: pos.alt as f64 / 1000.0,
lat: pos.lat as f64 / 1e7,
lon: pos.lon as f64 / 1e7,
};
76c1d86
to
5e76d00
Compare
.insert_json5("mode", r#""client""#) | ||
.expect("Failed to insert client mode"); | ||
config | ||
.insert_json5("metadata", &format!(r#"{{"name": "{}"}}"#, node_name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.insert_json5("metadata", &format!(r#"{{"name": "{}"}}"#, node_name)) | |
.insert_json5("metadata", &format!(r#"{{"name": "{node_name}"}}"#)) |
src/vehicle/mod.rs
Outdated
config | ||
.insert_json5("scouting/timeout", r#"3000"#) | ||
.expect("Failed to insert scouting/timeout"); | ||
config | ||
.insert_json5("scouting/multicast/enabled", r#"true"#) | ||
.expect("Failed to insert scouting/multicast/enabled"); | ||
config | ||
.insert_json5("scouting/multicast/ttl", r#"1"#) | ||
.expect("Failed to insert scouting/multicast/ttl"); | ||
config | ||
.insert_json5("scouting/gossip/enabled", r#"true"#) | ||
.expect("Failed to insert scouting/gossip/enabled"); | ||
config | ||
.insert_json5("scouting/gossip/multihop", r#"false"#) | ||
.expect("Failed to insert scouting/gossip/multihop"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this configuration is not necessary for an extension, the ttl and and multihop configuration is only necessary for peripherals to not leak data inside the vehicle. The only thing necessary is to change the connect/endpoints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we still need to deal with it for standalone app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no need to configure it as well for a standalone app, the connection ip is the only thing necessary
src/vehicle/mod.rs
Outdated
fn save_config(config: &zenoh::Config, config_path: &str) { | ||
match serde_json::to_string_pretty(config) { | ||
Ok(json_str) => { | ||
if let Err(e) = std::fs::write(config_path, json_str) { | ||
error!("Failed to write zenoh_config.json: {e}"); | ||
} else { | ||
info!("zenoh_config.json saved successfully"); | ||
} | ||
} | ||
Err(e) => { | ||
error!("Failed to serialize config with serde_json: {e}"); | ||
debug!("Config debug: {:#?}", config); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saving the configuration on loading the configuration from a file is problematic, this will save the zenoh id that should be unique per application while being unnecessary at all.
If the goal is to load custom zenoh configuration you should do as the following pseudo-python script
zenoh_config = zenoh.Config()
zenoh_config.insert_json5("mode", json.dumps("client"))
zenoh_config.insert_json5("connect/endpoints", json.dumps(["tcp/127.0.0.1:7447"]))
zenoh_config.insert_json5("adminspace", json.dumps({"enabled": True}))
zenoh_config.insert_json5("metadata", json.dumps({"name": node_name}))
if input_file:
zenoh_config.from_json5(json5.dumps(input_file))
session = zenoh.open(zenoh_config)
src/vehicle/mod.rs
Outdated
loop { | ||
tokio::select! { | ||
Ok(sample) = attitude_sub.recv_async() => { | ||
if let Ok(env) = serde_json::from_slice::<Envelope<ATTITUDE_DATA>>(&sample.payload().to_bytes()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to use serde_json5 over serde_json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
src/vehicle/mod.rs
Outdated
roll: att.roll, | ||
pitch: att.pitch, | ||
yaw: att.yaw, | ||
alt: pos.alt as f64 / 1000.0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice to have the units here in docstring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
pub struct VehicleData {
#[schemars(description = "Roll angle in radians")]
pub roll: f32,
#[schemars(description = "Pitch angle in radians")]
pub pitch: f32,
#[schemars(description = "Yaw angle in radians")]
pub yaw: f32,
#[schemars(description = "Altitude in meters above sea level")]
pub alt: f64,
#[schemars(description = "Latitude in decimal degrees")]
pub lat: f64,
#[schemars(description = "Longitude in decimal degrees")]
pub lon: f64,
}
let vehicle_data = Arc::new(RwLock::new(None)); | ||
|
||
// Start the Zenoh-client with shared data | ||
tokio::spawn(zenoh_client_bridge(vehicle_data.clone())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be reconnected if it fails to connect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please check
012ee15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @patrickelectric
207de55
to
945e1ec
Compare
012ee15
to
11518c6
Compare
src/device/recording/mod.rs
Outdated
// Define topic strings | ||
let ping1d_topic = format!("/device_{}/Ping1D", device_id); | ||
let ping360_topic = format!("/device_{}/Ping360", device_id); | ||
let vehicle_topic = format!("/device_{}/VehicleData", device_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to inform you, topics don't have trailing slashes in zenoh, it would be better to remove them.
src/vehicle/mod.rs
Outdated
Ok(s) => s, | ||
Err(e) => { | ||
error!("Zenoh session error: {e}, retrying in {reconnect_delay_secs}s"); | ||
sleep(reconnect_delay).await; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the delay in the beginning of the loop to avoid calling it in every continue call
src/vehicle/mod.rs
Outdated
let reconnect_delay_secs = 30; | ||
let reconnect_delay = Duration::from_secs(reconnect_delay_secs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
30s is a lot. We should make it 5 or less.
src/vehicle/mod.rs
Outdated
lon: pos.lon as f64 / 1e7, | ||
}; | ||
let mut pose_guard = latest_pose.write().await; | ||
*pose_guard = Some(pose.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this clone is unnecessary
src/vehicle/mod.rs
Outdated
config | ||
.insert_json5("connect/endpoints", r#"["tcp/127.0.0.1:7447"]"#) | ||
.expect("Failed to insert endpoints"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should have it by default, if there is a configuration in the loaded settings it'll replace it.
11518c6
to
b2c1179
Compare
b2c1179
to
b1c62df
Compare
Add Vehicle module to handle relevant data and share across other services.
The technical approach uses a RWLock that updates accordingly with the latest received values.
The Zenoh connection changes according to the feature flag "blueos-extension", which defines local/remote settings.
A channel containing the structure VehicleData (with JSON schema autogenerated already) will store vehicle data alongside Sonars. This closes a requirement also desired by integrators such as ThinkSmart, that have their own GPS data source.
The channel log was changed to use log_with_time, ensuring both channels will have the same timestamp.