1 unstable release
0.1.0 | Sep 12, 2024 |
---|
#122 in Simulation
36KB
524 lines
FSDS Rust API
The 'fsds-rs' crate provides users a Rust API to create clients that can connect with the Formula Student Driverless Simulator.
Getting started
Let's drive the car forward!
Open the simulator and run this example to make the car move:
use fsds_rs::{client, types::CarControls};
use std::{thread::sleep, time::Duration};
/// The name of the vehicle to control.
const VEHICLE_NAME: &str = "FSCar";
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
// ---------- //
// CONNECTION //
// ---------- //
// Connect to the simulator.
let mut client = client::FSDSClient::init(None, None)
.await
.expect("Cannot establish a connection with the simulator");
// Check network connection, exit if not connected.
client.ping().await?;
// Enable control of the vehicle via the API.
client.enable_api_control(VEHICLE_NAME).await?;
// ---------------- //
// CONTROL THE CAR! //
// ---------------- //
// Set the throttle to 1.0.
let mut controls = CarControls::default();
controls.throttle = 1.0;
client.set_car_controls(controls, VEHICLE_NAME).await;
// Loop to keep the program running.
loop {
sleep(Duration::from_secs(1));
}
}
API reference
This rust library is a copy of the official Python API. Please refer to the official documentation for more information about the API calls.
Dependencies
~4–13MB
~154K SLoC