I would like to know if it is possible to use jMAVSim as a visualization for a quadrotor.
The idea would be to disable the simulation engine, read the MAVlink message HIL_STATE_QUATERNION sent by the autopilot hardware and display the states in the 3D visualization.
The PX4 team proposed me to use jMAVSim for the visualization of the quadrotor trajectory (I am currently using FlightGear).
Do you have an idea of an easy way to implement that in jMAVSim?
adding an argument to start jMAVSim without the simulation engine, let’s say ‘-nse’. That will involve a modification of the main function in Simulator.java
for the MAVlink, I guess I should create a new class that inherited from MAVLinkSystem and use it instead of MAVLinkHILSystem. This will be used to read HIL_STATE_QUATERNION and should send nothing.
To keep the same code structure, I guess I would just put the simulator in pause and update the visual with the states from HIL_STATE_QUATERNION. Unfortunately, it seems the Visualizer3D is linked with the physical World object (itself containing the physical vehicle). Is it possible to separate the physical and visual objects?
Any other things I should be aware of before starting?
The term call back is overloaded. An HRT call back in on an interrupt thread. A HPwork call back is on a high priority thread and it would not be a good idea to block it as well.
Interrupts and HP work should be “Short service” “long service” should be done on properly prioritized threads.
In that case a thread waits on a semaphore sem_wait() and the HRT call back posts to that semaphore sem_post(). The down side is resources need to be allocated to the task. If the memory is available this is not an issue.
Thank you for this info, I will explore the options.
I finally implemented it using hrt_call_every() and px4_sem_wait()
px4_sem_init(&_data_semaphore, 0, 0);
hrt_call_every(&_timer_call, LOOP_INTERVAL, LOOP_INTERVAL, timer_callback, &_data_semaphore);
px4_sem_wait(&_data_semaphore); // periodic real time wakeup
inner_loop(); // main execution function
hrt_cancel(&_timer_call); // close the periodic timer interruption
// timer_callback() is used as a real time callback to post the semaphore
void Sih::timer_callback(void *sem)
The suggestions on how to change jMAVSim sound ok. I don’t know the details myself but if you can add your visualization only feature without too crazy changes and disabled by default, I think it’s worthwhile to get it merged.
I implemented something which is working but the rendering is jerky.
I used KinematicObject.setPosition() and KinematicObject.setRotation() to update the position and orientation of the vehicle whenever HIL_STATE_QUATERNION (i.e. the groundtruth) is received from the autopilot. The code is available here.
It looked like an aliasing problem, so I tried with the flags -aa and -no-aa to enable/disable the antialiasing. But both attempts resulted in a jerky display.
Any other flag I can modify for the display?
Any other idea?