Repository navigation
uart functionality - #140
Conversation
knmcguire
left a comment
There was a problem hiding this comment.
The implementation looks good, but I'm mostly worried about it being too specific for the Rasp PI. But it seems that it can be made generic pretty easily so that users can also read from uart from for instance, a linux computer.
| self.in_queue = queue.Queue() | ||
| self.out_queue = queue.Queue(1) | ||
|
|
||
| self.ser = serial.Serial('/dev/ttyAMA0', 512000, timeout=1) |
There was a problem hiding this comment.
How about having the ability to assign this already in line 86, so that users can define this URI from their script directly? This way, this functionality can also be used on other machines as well, and we can test it out on ubuntu.
There was a problem hiding this comment.
Just to make sure that I got it right.
You mean that the URI has the form 'serial://<device string>'?
Would this work from a PC (I have never used Uart from my PC, so I do not know if it works the same as for the Raspberry Pi)?
There was a problem hiding this comment.
Yeah probably, like serial://dev/ttyUSB5 or something like that for ubuntu.
There was a problem hiding this comment.
On Windows, Serial() would expect something like COM3, so one way would be to strip of serial:// and put the rest of the URI into the first argument of the constructor. That would mean serial:///dev/ttyUSB5 on Ubuntu (note the triple slash).
Considering the pyserial documentation we could also pass things like serial://rfc2217://....
Looks a bit weird (and I guess is not valid URI), but the other option would be to pass the full CrazyFlie URI to it. As other drivers would not feel responsible, that could also be a solution. The problem is that Serial takes both URIs or file names.
What is your preference @knmcguire?
There was a problem hiding this comment.
I kind of thinking about in the direction of how the USB is handled, where you can select either usb://0, 1, 2 .... so then you will do that for serial://0,1,2....
But if this is too much work for this pull request, just let us know and we can make an issue out of this after acceptance. It is just that we don't have a rasp pi lying around that is properly configured to test this out and would be nice to do this from the computer directly.
There was a problem hiding this comment.
I changed the Uri to the form serial://name where the name is the short device name like ttyAMA0 or ttyUSB5.
To see which serial devices are available you can use the command python -m serial.tools.list_ports -v.
|
|
||
| # Check if it is a valid serial URI | ||
| uriRe = re.search('^serial://([a-z A-Z 0-9]+)/?([0-9]+)?$', uri) | ||
| uriRe = re.search('^serial://pi$', uri) |
There was a problem hiding this comment.
See my comment here underneath
|
Perfect! With the new changes, I managed to make a connection with the Crazyflie directly from my ubuntu 18.04 with the following codelines URI = 'serial://ttyUSB5' when the CFLAGS += -DUART2_LINK_COMM enabled in config.mk in the firmware. So I can confirm this working :) I will merge this and the other prrt pull request too. We would like to also receive instructions for this in markdown format so we can add this to the documentation, but that can be done seperately. |
|
@s9meboeh : I am curious if you could provide any guidance with getting serial to work with a Roadrunner and Raspberry Pi 3B+? Specifically, what OS are you running on the pi? What I have done so far is update the firmware to include the CFLAGS += -DUART2_LINK_COMM enabled in the config.mk and reflashed the Roadrunner. Made sure I had the latest version of crazyflie-lib-python, enabled the serial port on the Raspberry Pi (disabled shell), and then ran the basiclog.py. It gets to the point of "Connecting to serial://ttyAMA0" and sits there. I'm not sure if there is anything else I need to do in the process. Thanks again for all of your help. |
|
@gimlisonofgloin
For more information about Pi UARTs have a look here: Fell free to ask further questions if it does not work. |
|
@s9meboeh: Thank you for the quick response! I double checked to ensure I properly enabled uart. I re-accomplished each of the above. I have the Roadrunner connected to pins 4 (5V), 6 (Gnd), 8 (GPIO14), and 10 (GPIO15). I am worried that I did not update the firmware properly on the Roadrunner or am missing some other step. Unfortunately, I am working from home and cannot rebuild the firmware with my Windows machine as it keeps getting stuck on arm_iir_lattice_init_q31.o claiming the .c file is missing. Is CFLAGS += -DUART2_LINK_COMM enabled the only thing in firmware that needs to be changed? I am downloading raspberry pi buster and will start with a clean build. |
|
Alright, restarted with a clean buster image. Pulled the latest crazyflie-lib-python version and went through the steps to set up the UART for serial communication. Same as before: And then it just holds up. I'm guessing it is something with my Roadrunner firmware. I will continue to see if I can rebuild the firmware. Additionally, I'll try to verify that my UART is actually working. Thanks again for the help! |
|
I have confirmed serial is working with a basic gyroscope (BNO055) and running their simpletest.py using '/dev/ttyAMA0'. That would lead me to assume that it is the Roadrunner firmware or something I missed with the serialdriver.py. Any help would be greatly appreciated at this point! |
|
@gimlisonofgloin |
|
I am somewhat new when it comes to compiling large projects like this. Would the command then be make |
|
Yes that is the command I thought about. (Although I do not have a Roadrunner to test it.) |
|
Yes, those are the pins I am using. As soon as I hear back from my students I will let you know what I find. |
|
@s9meboeh: I got it working! What I assume happened is my student didn't properly make the firmware before sending it to me. I downloaded a VM and compiled it and it worked great. For those who want to repeat serial communication with RaspberryPi 3B+ Stretch or Buster.
Second, update firmware for Roadrunner/Crazyflie per @knmcguire:
Last, run the code:
Thanks again for all of the help and discussion. It is working great and does not hang up as it does using USB. |
|
@s9meboeh thank you for helping out! @gimlisonofgloin glad it is working for you now :) If you have any more problems, open up another issue here or use the forum.bitcraze.io. |
|
@s9meboeh , Can you think of any reason it would work with Python3 and not Python2.7? I followed all of the crazyflie-lib-python instructions using python2.7 and run the basiclog.py script and it just gets stuck at "Connecting to serial://ttyAMA0". I can connect to UART using python3 and I can connect to USB using python2.7. I just cannot connect to UART using python2.7. I've included all of the dependencies (pyserial, etc). The ROS version we are using with all of our other projects is using python2.7. Thanks again and sorry for all of the questions! |
|
Hi, This will make sense since we stopped actively supporting python 2.7 after the latest release of the cflib, since python will be dropping support for 2.7 soon as well. |
|
Makes sense. I updated my ROS package to use Python3 so we are good to go! Thanks again! |
|
New commit requires adding |
Enable CRTP communication via Uart.