SITL Matlab - correct startup?

Hello everyone,

i´m trying to do a quadplane SITL Simulation with the ardupilot firmware and an own matlab physics model.

(I updated the firmware from github last on the 01. Feb. 2021)

Right now i´m debugging my model because the simulation doesn´t fully work yet. Still i was wondering if my SITL startup/set up is correct.

To start the simulation i run matlab and start MAVProxy in cygwin via:
cd ~/ardupilot/ArduCopter
…/Tools/autotest/sim_vehicle.py -v ArduCopter -f JSON:127.0.0.1 --map --console (-w if i want to reset params)

In the MAVProxy command i load default and parameters with:
param load …/Tools/autotest/default_params/plane.parm (don´t know if that is really needed)
param load …/Tools/autotest/default_params/quadplane.parm
param load …/Tools/autotest/default_params/myParameter.parm
Down under is what´s inside myParameter.parm.

I set the servos for my control surfaces and my motors. There are four lift motors and one pusher motor.

When i start i get the errors:
APM: Skipping INS calibration (doesn´t appear when i leave matlab running and restart MAVProxy)
When i try to arm the aircraft i get APM: PreArm: EKF2 Roll/Pitch inconsistent by 179 deg. Even though Roll and Pitch are zero in my model before arming. I added ARMING_CHECK 65518 to stop this error and with this i can takeoff in quadrocopter mode without a problem. The only thing is that the Heading in the console “spins” around without the aircraft actually turning. When i set a waypoint (after the takeoff and when the set height is reached) the airplane crashes, which is my problem right now.

These errors may result because my model isn´t correct but i was still wondering if the SITL set up is correct.

Thanks in regard!

myParameter are:
ARMING_CHECK 65518
AHRS_EKF_TYPE 10
SERVO1_FUNCTION 4
SERVO1_MIN 1000
SERVO1_TRIM 1499
SERVO1_MAX 2000
SERVO2_FUNCTION 19
SERVO2_MIN 1000
SERVO2_TRIM 1486
SERVO2_MAX 2000
SERVO3_FUNCTION 70
SERVO3_MIN 1000
SERVO3_TRIM 1000
SERVO3_MAX 2000
SERVO4_FUNCTION 21
SERVO4_MIN 1000
SERVO4_TRIM 1509
SERVO4_MAX 2000
SERVO5_FUNCTION 33
SERVO5_MIN 1000
SERVO5_TRIM 1000
SERVO5_MAX 2000
SERVO6_FUNCTION 34
SERVO6_MIN 1000
SERVO6_TRIM 1000
SERVO6_MAX 2000
SERVO7_FUNCTION 35
SERVO7_MIN 1000
SERVO7_TRIM 1000
SERVO7_MAX 2000
SERVO8_FUNCTION 36
SERVO8_MIN 1000
SERVO8_TRIM 1000
SERVO8_MAX 2000

I would guess there are some issues with your physics model, does the quad example model work for you? Are you re-using the forces and moments code from that example?

Yes the quadcopter example works for me.

I have my own forces and moments code but i´m re-using the SITL_connector, update_dynamics and rotate_dcm functions from the quadcopter example.

So i don´t have to set further options for the SITL to work properly? The INS calibration skipping isn´t a problem?

OK, that is a good start.

How do you know its not actually turning? I would guess you have some servos reversed or the tune is just wrong, maybe you can share your model somewhere?

@j0hn can you provide your setup i am also doing this but same problem happen with me for arduplane

Hello,
Sorry for not answering for a while.

I’ve had problems with my phsysics model. Some general mistakes but i also have to switch between different models for the different flight phases, one for the plane flight and one for the quadrocopter flight. That fixed my problems but i’m still looking for a smooth way to switch between models. In the LOG file i´ve found a parameter called Tm (Transition state). But i haven’t found this parameter in the complete parameter list for plane. Is it possible to send this parameter, or another one which gives information about the start and the end of the transition, via the JSON format when the UAV is flying in auto mode? I´ve read that it is possible to extend the JSON format.

Thank you in advance for your answers

I´ve followed the instructions on the website for the installation on windows. But i had to do additional things to make it work. I want to do the setup again to write down which additional steps i needed to make it work on my PC. I can post this here when I´ve done it. I guess I´ll be doing it in the next 2 or 3 weeks.

For the Matlab Modell I´m using the basic structure of the ardupilot example. I haven´t touched the SITLconnector function, I´ve done my own physic modell to calculate the forces and moments which the updateDynamics function uses to calculate the dynamics for the JSON format. There I´ve done my own function to calculate the euler angles. Don´t know if the rotateDCM function is wrong but I didn’t fully understand it why i did it myself.

I can´t post my Matlab modell here bc i need it for my thesis. But i did the most mistakes by calculating AoA, SS-Angle and the euler angles. And i had to make sure that every calculation is done in the correct coordinate system. Another problem was that i have to switch between models for different flight phases bc i´m simulating a quadplane. In your case i think you don´t necessarily need different models.

These where the things i had to check. Or do you have a specific problem? Or for which specific setup are you looking?

best regards

Another question i have: Is there a paramter to set the climb speed somehow? I´ve scanned the complete parameter list and mav.parm but i haven´t found anything useful. Does someone have an idea?

Thank you in advance for your answers and best regards!

Hi

we must send euler angles or roll , pitch , yaw angles with matlab ?

Its 321 euler If I recall correctly. If your using matlab you should be able to change the example without having to get into all this stuff.