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!
Asked by Dylan on 2018-11-11 17:37:34 UTC
Comments
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.
Asked by PeteBlackerThe3rd on 2018-11-11 20:02:34 UTC
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.
Asked by PeteBlackerThe3rd on 2018-11-11 20:06:55 UTC
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?
Asked by Dylan on 2018-11-11 22:12:08 UTC
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.
Asked by gvdhoorn on 2018-11-12 02:03:22 UTC
Even more reason to use a topic instead, which is what they're designed for.
Asked by PeteBlackerThe3rd on 2018-11-12 06:41:26 UTC
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?
Asked by Dylan on 2018-11-12 09:26:02 UTC
Please read the introduction to topics page, everything you're asking is answered there.
Asked by PeteBlackerThe3rd on 2018-11-12 12:56:56 UTC
I already read that, but I'm asking because I couldn't find the solution to my problem
Asked by Dylan on 2018-11-12 13:59:13 UTC
I guess the procedure would be:
NodeHandle
objectadvertise(..)
thefloat64
topicpublish(..)
msgs whenever appropriateyou don't "append" to a topic. It's not a file.
Asked by gvdhoorn on 2018-11-12 15:47:49 UTC
Can you please give me a link to a tutorial or something where that is explained?
Asked by Dylan on 2018-11-12 18:20:15 UTC
I hate to repeat what was already said, but the basic ROS tutorials show you exactly this.
Asked by gvdhoorn on 2018-11-13 03:14:30 UTC
I searched the tutorials where that was explained and couldn’t find it. That’s why I’m asking here. Can you please tell me the exact link or tutorial?
Asked by Dylan on 2018-11-13 05:50:03 UTC
I assume @PeteBlackerThe3rd is referring to: Writing a Simple Publisher and Subscriber (Python).
Asked by gvdhoorn on 2018-11-13 05:53:12 UTC
But it is not explained there! I read that tutorial more than 5 times
Asked by Dylan on 2018-11-13 05:54:27 UTC
Perhaps you can be a bit more clear about what "is not explained there". What are you exactly looking for?
Asked by gvdhoorn on 2018-11-13 08:35:25 UTC
I need to save a variable quantity of floats in a topic. Floats are the distance between a drone and the hround, and it is updated 10 times per second, approximately
Asked by Dylan on 2018-11-13 12:17:40 UTC
Topics do not 'save' data they communicate it to any listening nodes. A std_msgs/Float64 sends single 64 bit float values, it can send many of these individual values per second the rate is not fixed and will depend on the publisher.
Asked by PeteBlackerThe3rd on 2018-11-13 13:18:05 UTC
But if I send multiple floats, are all going to be ‘saved’ (I don’t know how to say it better) or just the last one? I need to have them all, like when using rosbag
Asked by Dylan on 2018-11-13 16:06:45 UTC
The topic itself will not 'save' anything, rosbag can be used to record topics and bandwidth allowing would record every float you publish if you start rosbag record before your node.
Asked by PeteBlackerThe3rd on 2018-11-13 18:46:17 UTC