Tank Day 29: FPS Mode

On the previous Build Diary entry, I shared a video of what it looks like to drive the tank from the web user interface, calling it “First Person View”. The natural development of that, then, it to turn it into something like a “first-person shooter”—a display that is just the video feed, and a set of keybindings to allow the user to drive it like it was a videogame.

This is a pretty easy interface to add, building on top of the existing javascript and adding some onkeydown and onkeyup bindings.

The code is now available in the Web UI folder of the Raspberry Tank code repository. You can chek out what it looks like (including my ssh debug readout and my very messy living room!) below.

FPS Mode Screenshot

Comments

Hi!

Nice project! Im trying to do something similar with an Arduino.
Will keep both TK-board and HL Multifunction an Arduino will read TK:s signal and pass it through or manipulate speed etc

Problem is i cant figure howto read TK-signal. I have read your and ancvi_pIII:s posts about problems TK signal varying in time etc
Tried all kinds of Arduino methods/libraries but no luck

Im no electronic geniuos and lacks knowledge. Any tips/hint is of interest.
I might have to clean up signal before it ends up in Arduino? Im sharing gnd and just using signal pin connected to Arduino

Cheers,
/Z

Zoomzky, how are you reading in the signal from the TK board? If you're reading it using a digital input line, you may have to step up the voltage using a transistor as the TK board is likely to be outputting 3-4V instead of the 5V that the Arduino would be happier with.

You could sample it from an analogue input too, although you would then have the challenge of converting that to a digital signal within the Arduino's limited memory capacity.

Could you share your circuit and code? It would help us understand what's going on with your setup!

Anonymous 08 March 2014

Hi Ian!

So far i just tried example code for reading Tk-board signal. There is a manchester-code-library for the Arduino https://github.com/mchr3k/arduino-libs-manchester but im not sure it is usable. The simplest example
https://github.com/mchr3k/arduino-libs-manchester/blob/master/examples/ManchesterRX_Basic/ManchesterRX_Basic.ino havent worked. Going through the source code i couldnt understand how library is catching start of signal. Should signal start with a 4ms High-signal?

I think as you mentioned i need to step up voltage on TK-signal. Im uncertain how i should share power between Arduino and tank.

Hardware setup

Arduino------Tank

GND----------GND

Digitalpin---Signal from TK

5+-----------?? Divider? this is a 5volt pin on the Arduino Uno board. Should be connected to tank + to get same reference voltage?

Im using serialmonitor on pc connected with USB-serialport to Arduino
and when USB is connected Arduino get its power through USB?

Im sorry if i cant explain in a more clear way! =)

/Z

The first (hopefully only) issue is probably your voltages. The TK board expects to be powered with something like 7-8V from the tank's battery, whereas you're providing 5V. I've never tried supplying it with 5V so it might be OK, but if you're not seeing anything, I'd try giving it a higher voltage by connecting it to the tank's battery as it originally was.

Your Arduino should be just fine powered from its USB cable.

If you have an oscilloscope, it will be easier to monitor the output of the TK board with that first to make sure you're actually seeing something, rather than jumping straight into trying to decode the signal on the Arduino.

Another thing to check is if you're pressing the "ignition" button on the remote control. For some reason you need to press this (even though all it normally does is make an engine noise) before you can start driving the tank. I believe this is controlled by the RX-18 rather than the TK board, so it shouldn't have any effect on what you're doing, but it's worth checking.

I sadly dont have a oscilloscope but i managed to measure signal with analoginput on Arduino. Next step is to find start of message using Arduinos pinchangeinterrupts. No fancy code just trying to find that first LOW

With the analyse you did http://files.ianrenton.com/sites/raspberrytank/analyse-vi-front.png
and this page about manchestercoding http://www.pcbheaven.com/wikipages/manchester_coding/

i should be able to get som results. Article about manchestercodes points out importance to know the clockperiod and your analyze says message is 21ms long and first low is 4ms long?

/Z

Yeah, the message itself comes out at around 21ms long. The 4ms low (not shown in the screenshot) is the time for which the signal is low before the start of the message (i.e. the time between one message and the next) - in practice I found that time varied a bit. If you're trying to capture the waveform, it's probably best to wait for a >=4ms low, followed by a rising edge, and start the capture there.

Hi Ian!

Im now equipped with a descent oscilloscope and managed to capture tk-signal. Makes me wonder though if its manchestercode. Start of signal with 4ms low and about 900 microsecs high doesnt follow manchesterstandard ? https://drive.google.com/file/d/0B8OuH4GxJ9ZEM1NXQzhBaVRyVmM/edit?usp=sharing

I also have trouble matching your codes with my oscilloscope-readings.
Next image shows 3 last groups of bits when tank is idling without enginestart. Might be 3 bytes? Tricky to distinguish where each byte begins/starts.

https://drive.google.com/file/d/0B8OuH4GxJ9ZETjBlU0RaZFcyR00/edit?usp=sharing

According your list idle no engine is
HEX=FE40121C Binary=11111110010000000001001000011100
My last "byte" is either 0:s or 1:s depending on where split the byte

/Z

It may not be "proper" Manchester Code — I'm no expert on these things so the timing may be different to the standard. However, it definitely follows the Manchester Code style approach in that each bit is either a high-low or a low-high transition. (For example, pressing a button — a one-bit change in information — will always swap a high and low around, never just change one of them.)

It is indeed very tricky to see where the bits start and end — I had some luck freezing the scope display and reading them off, but didn't get a set I was confident with until I sampled it in software.

Matching the codes seems to be a bit of a dark art. Over the time I was working on the tank I came up with several sets of codes, all of which seemed to work to some extent, and others that I spoke to online have slightly different codes to achieve the same effect, some of which work on my tank and some don't. It may be that if your codes aren't the same as mine, we have subtly different remotes / receiver boards.

Alexandre Lugand 03 April 2014

Hi Ian !

My name is Alex (I'm French, sorry for my poor English), and I created a Raspberry tank based on your work (with a German Panther, not the Tiger).

I tried to improve the tank control. I cracked CRC code for example. I can make dual actions together. See excel file at this URL, if you want: https://github.com/alexandrelugand/RaspiTank/blob/master/Docs/CRC.xls .

You can find C++ code at the end of this file:
https://github.com/alexandrelugand/RaspiTank/blob/master/RaspiTank/Command.cpp

You can watch my tank at this URL:
https://plus.google.com/u/0/102283018376698006991/posts

Some functions are not completly ready (magnetic compass, gyro, accelerometer ...), but all I2C devices work fine.
I remade all web UI design. I use two gamepads to control the tank (all commands are sent over web socket. Thanks Javascript, JQuery and HTML5 :-)

At this time, I use only Chrome Browser, but it's work also on my tablet (Samsung galaxy Note 10.1 under Android).
I continue to improve my tank, gradually ...

Alex

That looks really cool, I like what you've done with the web interface! Does the tablet support multi-touch in the browser so you can use both sticks at the same time?

I would have used WebSockets originally but I had the crazy idea that I should support Internet Explorer which didn't have WebSockets back then. It looks like a better solution than the integrated HTTP server.

I've been very lazy about the whole CRC code issue — the solution was posted in the RC Tanks Australia thread ages ago, and GitHub user TheTesla implemented it on top of my original code too. I just need to find time to implement it myself — your code looks better written than mine so I might use yours if that's OK!

(And don't worry about your English, it's very good — and 1000x better than my French!)

Anonymous 04 April 2014

No problem, you can use it of course, but there are again a lot of bugs :-)

The tablet doesn't support multi-touch. I'm searching a Javascript library for that.
At the moment, I use the Hammer.js library. It's a good library but the multi-touch is used only to manage the 'pinch' action.

Otherwise, Internet explorer supports WebSocket since version 10.

Alex

Ian wrote:


That looks really cool, I like what you've done with the web interface! Does the tablet support multi-touch in the browser so you can use both sticks at the same time?



I would have used WebSockets originally but I had the crazy idea that I should support Internet Explorer which didn't have WebSockets back then. It looks like a better solution than the integrated HTTP server.



I've been very lazy about the whole CRC code issue — the solution was posted in the RC Tanks Australia thread ages ago, and GitHub user TheTesla implemented it on top of my original code too. I just need to find time to implement it myself — your code looks better written than mine so I might use yours if that's OK!



(And don't worry about your English, it's very good — and 1000x better than my French!)


That looks great! Are you using the Arduino Motor Shield to control the main motors, or an LM293/etc?

Anonymous 21 April 2014

Ian wrote:

That looks great! Are you using the Arduino Motor Shield to control the main motors, or an LM293/etc?

Kept the RX18 only to be used as motor shield. Read somewhere the motors use a lot of amps and i havent found such a Arduinomotorshield yet...

/Z

That should easily be capable! I calculated the motor current draw at about 6A, but I measured it simply by battery depletion (Ah) / run time (h) rather than measuring directly with an inline ammeter.

Hi Ian, Found your blog while looking in RCUniverse. Very interesting. I was/am wanting to use a Rasberry with camera/WiFi to run my tank in battle. We use a IR battle system instead of the BB. My goal is to put a Rasberry on the tank then sit over on the side and run the tank as if I am the tank commander. This would make our battles more interesting in that we would have to move slow and scout the area before moving. Angle would be slightly down as you would be steering useing the camera and not standing over the tank.
Long winded but here is the question.. (iknow..FINALLY)
Where did you get the parts and is the Rasberry doing the transmitting to the laptop?

Hi!

I got the parts from a few places:


  • the tank was originally from Howes Models

  • the Wifi dongle and USB hub came from Amazon

  • the I2C compass and rangefinder came from Robot Electronics

  • the Raspberry Pi and the rest of the electronics came from Farnell.

If you're not in the UK, I'm not sure if Howes or Robot Electronics ship internationally, but if not hopefully there are similar places in your country.

In my setup, the Raspberry Pi acts as a WiFi base station, so the laptop sees the "Raspberry Tank" wireless network and connects to it. The control is all done via a web browser on the laptop.

Add a Comment