Coding Chase - Projects

My 3D Hub

Thank You For Donating:

Ikeeki (linux-sunxi@irc.freenode.net)
Computer Troubleshooters Brasil

Sunday, 18 May 2014

QtZumoTruck

Going through some of the stuff in the office study, I came up with an idea - how about a remotely controlled vehicle - yet another one - but with Qt 5.2.1 in the mix?

Maybe not the simplest setup, but certainly a great one for learning/testing.
I got hold of an Arduino Uno R3 that was lying around, slapped a Zumo robot on it and connected it to a Cubietruck.

What came out of this got named QtZumoTruck and it has been quite the entertainment around here!





Ok so I'm not the handiest guy around when it comes to shortening usb cables, but it worked and it lightened the load - although to be honest, the little Zumo packs quite a punch and was able to handle the weight of the all the components previous to being stripped down!

As stated, the Zumo has its own Arduino libraries to handle the two microgear motors, I just added serial port communications to it by following this blog.

And then, on to Cubietruck. Cubietruck is quite awesome, in the sense that it already has built-in battery management - it recharges the battery while on power socket and commutes between power sources without affecting the running OS.

I got the battery off of an old HTC Tattoo smartphone and soldered a couple of wires to be able to connect it to the Cubietruck.

Reading the battery state is also possible under /sysfs, which comes in handy to measure remaining battery.

I installed Cubian (server version) on a microSD card, set up the WiFi for the onboard chipset and also mjpeg-streamer to stream live video over a connected Logitech C160 USB webcam, based off of the sunxi wiki.

Once the Arduino got connected to one of the USB ports on the Cubietruck, the /dev/ttyACM0 device was created and I was in business!
I used minicom on Cubietruck, over ssh, to test interaction with Zumo.

Having WiFi and video streaming on Cubietruck and having Zumo accept serial port commands to control the motors, what was left was to combine the two in an attempt to remotely control the little car over IP.

Possibly not the most immediate choice of framework, but I obviously went with Qt.

Qt 5.2.1 includes QtSerialPort which is specifically oriented at serial port communication. Working with the terminal example, I added QtTCPSocket and made Cubietruck act as a TCP Socket-to-Serial gateway.

So with Cubietruck controlling Zumo over serial port and receiving the commands over TCP socket, I made a simple TCP socket client and that's it!

From old Socket-to-GPIO code I had, I tweaked both Server and Client to work with Serial and fit with the Zumo's needs.

When the Client has focus on the Desktop, using the arrow keys sends messages over the TCP socket to the Server.
The Server picks up the message in question and sends the equivalent command over serial port to Zumo, which in turn handles the motors.

Since the serial port code is sequential, to avoid having to press forward and then stop to halt and change command, I used Qt's events to:

- send a forward command on up arrow key press event
- send a full stop command on any arrow key release event

... and so on for the remaining directions.

There is still a lot of polishing code-wise, but onwards with the first run!




WiFi signal was pretty decent although I did get a few break ups in video reception when getting far away from the access point, located inside.

The video feed was at 640x480 resolution and between 25 and 30fps, which is pretty good - and the whole system feels quite responsive!

And in the end, the whole solution from TCP to Serial uses a graphical framework, without caring much for... graphics.

Yes, Qt is that impressive.

No comments :

Post a Comment