support
support copied to clipboard
[Feature] Implement pybricks.tools.Datalog for data logging with Pybricks Code
Is your feature request related to a problem? Please describe. Data logging can be a very useful tool when debugging robot programs.
We have the pybricks.tools.Datalog
class, but it is currently only supported on EV3 because the other hubs do not have a file system.
Describe the solution you'd like
Enable pybricks.tools.Datalog
on all hubs. But the file is created locally in Pybricks Code instead of on the hub.
The .log()
method is just a wrapper around print
, so maybe we could prefix/postfix something to each line so Pybricks Code knows that it should go into a file instead of onto stdout.
Describe alternatives you've considered Use pybricksdev, which has a hidden feature to allow a form of data logging.
This was also requested below:
in fact the DataLog class is for the EV3 hardware - we overlooked that in the heat of the moment.
We would like to write log data from SPIKE - so will set a ticket accordingly. After all, we have no other way to do this.
Originally posted by @legotronic in https://github.com/pybricks/support/issues/703#issuecomment-1217796851
This was also requested below:
I found DataLog module in EV3 but it is not working on spike prime. Also I cannot write or create csv file. How do I log sensor data on Spike Prime?
Originally posted by @mihye126 in https://github.com/pybricks/support/discussions/796
Datalogging (beyond the 1000 lines in the output window) would be very helpfull!
Are you still considering this feature?
Or, can you elaborate in the alternative you mentioned above, using pybricksdev?
If you run this script with pybricksdev
print("_file_begin_", "./test.txt")
print("time, speed, angle")
print("0, 0, 0")
print("1, 10, 10")
print("2, 20, 30")
print("_file_end_")
It will produce a file test.txt
on your computer as follows:
time, speed, angle
0, 0, 0
1, 10, 10
2, 20, 30
Anything between the begin and end "commands" will go into the file. It doesn't have to be columns with numbers.
Are you still considering this feature?
In the long run, yes. It would be nice if we could make a datalog class that will "print" data to a channel separate from the standard output pane. That way it won't get mixed with normal print
statements, and it could write to different files at the same time.