Best option for visualizing my controller

asked 2018-11-11 16:37:34 -0500

Dylan gravatar image

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!

edit retag flag offensive close merge delete



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.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-11-11 19:02:34 -0500 )edit

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.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-11-11 19:06:55 -0500 )edit

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?

Dylan gravatar image Dylan  ( 2018-11-11 21:12:08 -0500 )edit

What can I do?

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.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-12 01:03:22 -0500 )edit

Even more reason to use a topic instead, which is what they're designed for.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-11-12 05:41:26 -0500 )edit

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?

Dylan gravatar image Dylan  ( 2018-11-12 08:26:02 -0500 )edit

Please read the introduction to topics page, everything you're asking is answered there.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-11-12 11:56:56 -0500 )edit

I already read that, but I'm asking because I couldn't find the solution to my problem

Dylan gravatar image Dylan  ( 2018-11-12 12:59:13 -0500 )edit