velocity layer working

This commit is contained in:
franchioping 2026-04-02 17:40:15 +01:00
parent db084b0c03
commit c1041f901e
8 changed files with 139 additions and 11 deletions

View File

@ -107,6 +107,7 @@ class SimVisualizer:
# If read_json doesn't flatten automatically, we expand the dicts:
for col in [
"linvel_current",
"linvel_target",
"accel_current",
"accel_target",
"angvel_target",
@ -136,13 +137,14 @@ class SimVisualizer:
self.ax.clear()
to_plot = [
("rot_target", "Rot Target"),
("rot_current", "Rot Current"),
("angvel_current", "Angvel Current"),
("angvel_target", "Angvel Target"),
# ("rot_target", "Rot Target"),
# ("rot_current", "Rot Current"),
# ("angvel_current", "Angvel Current"),
# ("angvel_target", "Angvel Target"),
("accel_target", "Accel Target"),
("accel_current", "Accel Current"),
("linvel_current", "Linvel Current"),
("linvel_target", "Linvel Target"),
]
for name, label in to_plot:

View File

@ -23,4 +23,16 @@ stack = { max_rate = 3.14, rotation_pid = { kp = [
0.0,
0.0,
0.0,
], frequency = 600.0 } }
], frequency = 600.0 }, linvel_pid = { kp = [
4.0,
4.0,
4.0,
], ki = [
0.0,
0.0,
0.0,
], kd = [
0.0,
0.0,
0.0,
], frequency = 25.0 } }

View File

@ -23,4 +23,16 @@ stack = { max_rate = 3.14, rotation_pid = { kp = [
0.0,
0.0,
0.0,
], frequency = 600.0 } }
], frequency = 600.0 }, linvel_pid = { kp = [
4.0,
4.0,
4.0,
], ki = [
0.0,
0.0,
0.0,
], kd = [
0.0,
0.0,
0.0,
], frequency = 25.0 } }

View File

@ -23,4 +23,16 @@ stack = { max_rate = 3.14, rotation_pid = { kp = [
0.0,
0.0,
0.0,
], frequency = 600.0 } }
], frequency = 600.0 }, linvel_pid = { kp = [
4.0,
4.0,
4.0,
], ki = [
0.0,
0.0,
0.0,
], kd = [
0.0,
0.0,
0.0,
], frequency = 25.0 } }

77
inputs/vel_all.json Normal file
View File

@ -0,0 +1,77 @@
{
"records": [
{
"input": {
"joystick": {
"throttle_input": 0,
"roll_input": 0,
"yaw_input": 0,
"pitch_input": 0
},
"position": {
"lat": 0,
"long": 0,
"alt": 0
},
"rotation": {
"roll": 0,
"yaw": 0,
"pitch": 0
},
"velocity": {
"x": 0.15,
"y": 0.15,
"z": 0
},
"mode": "Velocity"
},
"time": 0
},
{
"input": {
"joystick": {
"throttle_input": 0,
"roll_input": 0,
"yaw_input": 0,
"pitch_input": 0
},
"velocity": {
"x": 0.3,
"y": -1.3,
"z": 0
},
"mode": "Velocity"
},
"time": 3
},
{
"input": {
"joystick": {
"throttle_input": 0,
"roll_input": 0,
"yaw_input": 0,
"pitch_input": 0
},
"velocity": {
"x": 3.4,
"y": 0,
"z": 1
},
"mode": "Velocity"
},
"time": 10
},
{
"input": {
"joystick": {
"throttle_input": 0,
"roll_input": 0,
"yaw_input": 0,
"pitch_input": 0
},
"mode": "Velocity"
},
"time": 20
}
]
}

View File

@ -154,6 +154,7 @@ impl Drone {
self.controller
.set_angular_velocity(rb.rotation().inverse().transform_vector(&rb.angvel()));
self.controller.set_rotation(*rb.rotation());
self.controller.set_linvel(self.linvel);
self.target_throttles = self.controller.get_motor_throttles();
}

View File

@ -52,6 +52,7 @@ impl From<Vec3Serialize> for na::Vector3<f32> {
pub struct SimLogRow {
pub time: f32,
pub linvel_current: Vec3Serialize,
pub linvel_target: Vec3Serialize,
pub accel_current: Vec3Serialize,
pub accel_target: Vec3Serialize,
pub angvel_target: Vec3Serialize,

View File

@ -200,10 +200,20 @@ impl Simulation {
] * 3.14
};
let accel_target = na::vector![
let accel_target = if current_input.mode != ModeInput::Acceleration {
cont.linvel_rt.last_output.unwrap_or_default().0
} else {
na::vector![
current_input.acceleration.x,
current_input.acceleration.y,
current_input.acceleration.z
current_input.acceleration.z,
] * 3.14
};
let linvel_target = na::vector![
current_input.velocity.x,
current_input.velocity.y,
current_input.velocity.z
];
let accel = self.drone.get_accel();
@ -213,6 +223,7 @@ impl Simulation {
.log(&SimLogRow {
time: self.world.get_time(),
linvel_current: (*self.drone.get_rb(&self.world).linvel()).into(),
linvel_target: linvel_target.into(),
accel_current: accel.into(),
accel_target: accel_target.into(),
angvel_target: target_angular_vel.into(),