How to trace code?

Hi guys,
How do we trace code for beginners? I tried to print messages on system console. But I don’t see anything for mixer.

For example, I added a warnx() or a printf() at the beginning of commander_thread_main() of commander.cpp. I can see the print out on system console during run time.

But the printf() that I added in mix() of mixer_multirotor.cpp doesn’t output anything on console. I am running a quad_x mixer. I guess the mix() function in mixer_multirotor.cpp should be called during run time. Why I don’t see the message I print out? Does mixer code output the debug message to the same console? Please help.

Thanks.

Hi
You can use PX4_WARN()/PX4_ERR() from pretty much everywhere in the code and it will output to the console. It seems that your code in mix() is not called.

bkueng, I didn’t change code other than adding the print out. The code is still the one released.

If I armed the quadcopter and used RC to change throttle (I can see the console displayed take-off detected), the mix() function should be called, right?

I will try PX4_WARN() or PX4_ERR(). But printf() should also work. I really don’t see why it doesn’t work.

Yes, you’re right. I quickly tested in SITL and the mix() does get called. Which hardware are you using?

Thanks for taking time to test it. I am using Pixhawk.

I don’t think printf will go to the system console if the code is running in the IO coprocessor.

That is what I observed. Then how do we trace/debug that code? Please help.

Well, if you’re a beginner, I’d suggest not to change anything in the IO code.
Are you chasing a suspected bug?

I updated mix() function of mixer_multirotor.cpp for a quadcopter I am building. But it does not behave as I expected. I want to debug. How do you guys debug when you develop IO code?

Hopefully one of the devs who has actually done that will answer. One thing you could do is debug on PixRacer, where the mixer runs in the FMU instead of a coprocessor.

Can someone who are familiar with IO code help? How do you debug IO code? Or how can we output the debug messages to either terminal or log file?

Thanks a lot.