Skip to content
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 Statespace model support to SITL #29462

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

bnsgeyer
Copy link
Contributor

@bnsgeyer bnsgeyer commented Mar 8, 2025

This PR adds a separate model to SITL to support state space models. It currently supports multirotor and helicopter models. It also uses JSON files for model parameter inputs. This allows anyone to use their own state space dynamic model without having to modify the SITL code.

@@ -528,6 +541,7 @@ def options_for_frame(self, frame, vehicle, opts):
if frame.startswith(p):
ret = self.options[vehicle]["frames"][p]
break
print("ret is (%s)" % ret)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove debug?

Comment on lines +44 to +48
const char *colon = strchr(frame_str, ':');
size_t slen = strlen(frame_str);
if (colon != nullptr && slen > 5 && strcmp(&frame_str[slen-5], ".json") == 0) {
load_frame_params(colon+1);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this function in Plane too; the part that finds a colon and a string ending in .json. Do you think there is a way to refactor this and reuse it?

Something like bool is_json_frame(const char *fram_str)

if (model.coll_max - model.coll_min > 0.0f) {
hover_coll = (model.coll_hover - model.coll_min) / (model.coll_max - model.coll_min);
}
float servos_raw[16];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a define we could use for the max servos? I thought certain versions of AP support 32.

Comment on lines +273 to +276
float Dlatlag_dot = (-model.Lag)*(Dlatlag)+(model.Lag)*(_roll_in);
float Dlonlag_dot = (-model.Lag)*(Dlonlag)+(model.Lag)*(_pitch_in);
float Dcollag_dot = (-model.Lag)*(Dcollag)+(model.Lag)*(_throttle_in);
float Dpedlag_dot = (-model.Lag)*(Dpedlag)+(model.Lag)*(_yaw_in);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these locals could be const.

rot_accel.y = (model.Mu)*(velocity_air_bf.x)+(model.Mlon)*(Dlonlag);
rot_accel.z = (model.Nr)*(gyro.z)+((model.Nped)-(model.Lag*model.Lead))*(Dpedlag)+(model.Lag*model.Lead)*(_yaw_in);

float lateral_y_thrust = (model.Yv)*(velocity_air_bf.y)+(model.Ylat)*(Dlatlag);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps run astyle on the code? Some operators have space around them, others don't.


// ramp speed estimate towards control out
float runup_increment = dt / runup_time;
if (motor_status > 2) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an enum for the status?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants