Best option for visualizing my controller
I'm using Python. I'm programming a controller for the height of my drone. I know how to do a PID but I need to see how it is working and I don't know which is the best option and how to implement it.
The different positions with respect to a marker are in marker.pose.pose.position.z, but when I try to write that information in a log file, just the last information is saved. This is what I do:
global log_file
log_file = open("log_z_time.txt", 'w') #open a log file
in my def __init__
, inside a class. And then log_file.write(str(marker.pose.pose.position.z)+"\n")
inside another def (in the same class).
Another option may be publishing all the positions in a topic, but how can I do that?
I hope you can help me. Thanks!
I suspect you're opening the file and clearing it for each entry. Try opening it with mode "a" append instead of mode "w" write. You should have a close in there too when you're finished with it.
However. Writing the values to a topic as described in the tutorials would be recommended. Then you could use the provided tools such as the plot plugin of the rqt_gui to plot the change in height over time. Or RVIS to show the pose in real time.
Using 'a' doesn't work properly. It only saves a few samples (like 15000, but I need much more). For example, my drone starts at 2.15 metres and ends at 0 metres and it only saves from 2.15 to 2.14 :S. What can I do? Which are the tutorials to write a lot of samples in a topic?
Not opening and closing a file at a high rate. That is not what that infrastructure was design for.
If you must use a file, open it once, keep the file handle around and use it to write new data to it whenever you need to.
Even more reason to use a topic instead, which is what they're designed for.
How can I paste a lot of floats in a topic? I mean, how would the topic be defined? Imagine that a new value comes each 0.01 seconds, how can I append that value to the topic?
Please read the introduction to topics page, everything you're asking is answered there.
I already read that, but I'm asking because I couldn't find the solution to my problem