Tower's Clouds

Thoughts From Up Top

Left Sidebar

Skip to content

Archives

Arduino Head-Tracking Revisited

April 12, 2016 @ 9:03 am

It’s been a year or so since I talked about my Arduino head-tracking, and I think it is a topic worth revisiting. For one, the original sources have disappeared or become lost with forum directory changes, and I wasn’t particularly happy about my original coverage of it.

As a foreword, I want to thank “Kroda1” of arduino.cc for the base source code. Also newboerg for his original FaceTrackHAT guide which got me into this, and snowsky for his commands code addition; both of these latter folks where members of the Arma 3 community from around 2014 when I first came across this, and I’ve been using it fairly regularly since, especially with Elite: Dangerous.

The Build

This is made from a Generic Pro Micro Atmega32u4 (Arduino Leonardo), which looks like there are plenty of choices to pick from online and all pretty comparable. With an MPU-6050 accelerometer and gyro board addition, which is probably the more important part. There may also be other more advanced hardware with compass functionality included to improve accuracy, but this works ok to a degree, but with some extra work required.

Mine is a rather ridiculous looking electronic breadboard with the Arduino and MPU-6050 perched upon it, I’ve also found velcro to be beneficial and some normal tape over the breadboard’s paper bottom; which suffered at the hands of double-sided tape until I had the smart idea to use plastic tape wrapped around the edges onto the sturdier breadboard’s plastic.

There are numerous guides on wiring up the MPU-6050, depending upon whether you went with the above Arduino you may want to double check but mine is wired up thusly:

  • MPU VCC to Arduino 5V
  • MPU GND to Arduino GND
  • MPU SDA to Arduino 2
  • MPU SCL to Arduino 3
  • MPU AD0 to Arduino GND
  • And of course a micro USB to USB cable for the PC

Beyond this, I’m afraid I’m no hardware hacker or tinkerer, so I cannot be of much assistance. This setup at least allows for rotational control, and while the MPU-6050 is capable of translational control, I haven’t looked into it (and I suspect it would introduce a whole new kettle of fish).

You will also want to grab the Arduino IDE to compile and upload the code (please see second page for full source-code) and the head-tracking software. I originally suggested FaceTrackNoIR with the Hatire plugin, but now OpenTrack actually includes both in one package, but currently has a few small problems (high CPU usage being one).

The Problems

Initially I used Kroda1’s original code with the command changes made by snowsky (allowing the software to send a command to stop/start the tracker), though I found that any combination of the commands or drift-correcting arduino code wasn’t quite right. It was either over-zealous counter-action or just a bit too inconvenient to keep hitting a key every 30 seconds (though this actually only centers in software, but that doesn’t really matter).

And then I had the “neck-snap” drift, I recorded a lot of debug output and saw large drifting action on the x and y axis; x in this case was yaw and y being roll. Roll would auto-correct in a short time (don’t ask me why or how, I have no idea) but the yaw would not, even minor anti-drift doesn’t help when you’re suddenly looking 90 degrees or more to the left/right. But recording the debug output let me know this was happening suddenly, in other words, a single moment/wrong reading from the MPU.

Note: I may not be correct about x and y above, they certainly improved things when altered but its been some time since I originally did this and didn’t document things well enough when I did.

The Fixes

The first problem, drift correction – because yaw is most often used I couldn’t just keep hitting a key when it didn’t quite return to center. So I have a simple drift correction for those moments when its not too frustrating and I just let it do it automatically:

The downside to the above is that if I want to track a target that stays on my left or right for too long, the yaw will center regardless.

After I made the below changes I actually found I didn’t need this first adjustment, as such I will be commenting it out in source and I’ve added a little section at the bottom of this first page.

The second problem is much simpler in its solution, filtering out large erroneous spikes from the MPU (or perhaps arduino calculation). See the following code:

This required some other modifications from the original source of course, get_last_acc_x_angle() (and y’s equivalent) didn’t exist; and we have to pass the current calculated angle acceleration to the function that saves the last angle’s acceleration.

Anyhow, essentially if the current calculated angle’s acceleration is greater than the last angle plus 15 degrees, then we’ll just use the last angle’s acceleration. Yes, this could introduce drift, but as we don’t expect this erroneous output that often (maybe once every 5 seconds or so, on a hardware-based timescale of nanoseconds at that), it shouldn’t have much impact for our planned use.

The logic is that we can’t actually turn out heads fast enough in a nanosecond (or whatever the actual timescale of the hardware’s clock is), we’d have to be doing ourselves some serious harm if that was the case.

I may actually refine these numbers at some point; and it may reduce the drift immensely that I don’t need the first solution, but we’ll see.

Warning! If you have this setup, then the solution above is/could be very specific to my hardware, your drift may be on different axis to mine and as such you may want to implement your own version of these changes. I have no drift in pitch or seemingly erroneous output so I don’t bother with it (the x axis in code).

Removing re-centering

This is a late addition to this article, I’ve done some experimenting after adding and improving the second fix and found it pretty much removed the worst drift; there can still be small amounts of drift of course, without a compass to correct there isn’t much chance of avoiding it.

I think though, this hardware can sometimes become uncalibrated when things warm up – so it can be worth taking the tracker (or head-set its mounted to) off, putting it somewhere stable (I hold mine on my desk or brace my headphones against my desk to stabilise) and hitting stop/start in OpenTrack or Reset in the Hatire dialogue.

I’ve been able to play for multiple hours without having to hit my center button that often.

Please see the second page for full source code.

What Gaming Can Do

December 10, 2014 @ 4:44 pm

I had an interesting discussion a few months ago, it was with a family friend who, really knows very little about gaming, and… that is fine! What took me off-guard simply is what kind of games they thought were out there, to paraphrase “its just military, gun games, isn’t it?”. Now, I’m not blaming this friend for not knowing what games are out there, not one bit; if you have a busy life and don’t follow gaming your only source of information is likely a newspaper and television, but this to me, shows what the general non-gaming folks have been led to believe games are.

That general consensus seems to be that the majority are all ultra-violent “gun games”, for the record I did try to inform this person, and I think I probably achieved that – mentioning recent examples like Euro Truck Simulator 2 and Farming Simulator (though I haven’t played the latter… yet) and why people might opt to play these over what is more popular and often in the media’s collective gaze.

Then the thought crossed my mind, I’ve learned a fair bit from games…

[Arduino HT] Assetto Corsa

July 31, 2014 @ 12:12 pm

As a follow up to the Arduino head tracking tutorial this post goes through how I’ve got Assetto Corsa configured in FaceTrackNoIR. Note that in all these cases I do not have a camera attached; in theory you could include one to try and provide an extra source for positional data, but how FTNoIR handles any differences to that I wouldn’t know.

But first, a little video of Asetto Corsa in action with the head tracking device on…

Note that at the time of recording I was still getting to grips with AC, as such my driving is barely passable (I’ve actually since turned off the racing line and found its an overall better experience, less distraction). Throughout the video you may see me glancing left and right; as this was simply a practice race I was doing my best to simulate checking side mirrors for competitors, preferring racing games with a cockpit and mirrors… they become somewhat handy when playing against buddies.

Anyhow, the configuration… now do note these are guidelines, my view consists of a 1920×1080 24″ monitor; so people with larger or multiple (EyeFinity) setups may opt for different values. The basic idea is that you can keep the monitor in your line of sight (or in my cases, with my glasses frame) but move the ingame head the entire range available – the curves should smooth this or slow-down/speed-up the rate of turning.

Here is what the curves should roughly look like…

Arduino HT Curves

And the settings (note, these may require customising if you load them directly into FTNoIR, you may be better off making an initial ini file with your default settings and placing the relevant parts from this into your own manually).

 

Arduino MPU-6050 Head Tracking

July 18, 2014 @ 3:30 pm

Back in 2013 I experimented with FaceTrackNoIR, a means of head-tracking using a webcam; alas the only decent webcam we had was not my own and so I used a cheap model camera… it would regularly lose track and require resetting, but the brief moments when it did work, it was an obvious improvement when playing games like Arma. But as the only real commercial option was well over £100 I put the idea to bed. Until I saw someone talking about using a little homebrew project on the Arma 3 forum, see this thread on the BI forum.

The assembly instructions are nearly identical to the EDTracker; with the exception of I have no reset button. But for the sake of making sure this information doesn’t disappear entirely… the hardware is as follows:

  • Pro Micro ATMega 32U4 5V/16MHz
  • MPU-6050 Six-Axis Gyro
  • Plenty of cable (optionally a breadboard)
  • Soldering will be required

When wiring it up, wire up the following:

  • Arduino GND  <–> MPU GND
  • Arduino GND <–> Arduino GND
  • Arduino GND <–> MPU ADO
  • Arduino VCC <–> MPU VCC
  • Arduino 7 <–> MPU INT
  • Arduino 2 <–> MPU SDA
  • Arduino 3 <–> MPU SCL

In terms of software you will require FaceTrackNoIR and the hatire plugin. At this point I haven’t talked about the actual sketch file for the Arduino; the original sketches can be found via this link, and a modified version of the same sketches which adds basic commands via this link. But, before you commit to downloading either of those I made my own modifications. This might not affect you, but in my case it was a substantial roadblock to having a smooth experience, constantly having to readjust the centre point.

Essentially the MPU was occasionally outputting (or at least according to the Arduino it was) a spike in acceleration, it roughly translated to anywhere between 20 and 40 degrees; now given that the electronics work in fractions of a second, to rotate your head that far in a micro-second would be a feat to behold I think. So, simple solution, you compare the current output with the previous output, if it goes above a margin of your choosing you ignore the output and use the last output. Yes, in theory this means there might be a moment where your view doesn’t go quite where you expect it (hopefully by using the last output it helps smooth things over). But I combined it with a recentering (or spring) sketch snippet to basically mean I should never have to touch the recenter key for FTNoIR again… and in my quick 4 lap test in Assetto Corsa, I never did (whereas before I would have had to wait till a straight to recenter my view every other if not every lap, not ideal when trying to concentrate).

Its worth noting that I use a maximum of about 8 degrees motion of my own head in either direction to translate to ingame (as far as the specific game at hand will go). So a margin of 15 degrees is ample and even then, my own physical limitations should stop me from ever exceeding 15 degrees of rotation in a micro-second. Even if there is a micro-error of less than 15 degrees, the recentering code should be able to handle that perfectly fine; its those regular large spikes that are an deal-breaker. The sketch itself is below, credit to the original creator and people who have modified it since, my own changes are pretty minimal all-in-all:

If you are wondering what my addition to the code is, it is pretty much as follows:

I’ve not included the defining of the float or its initial assignment, rather I’ll just explain this. What I’m looking at is the absolute current acceleration angle (x axis) and comparing it with the last angle (which is always updated). Note that abs (or absolute) is essentially making a negative number equal to a positive number; handy when both will be used; so -30 might as well be 30 for all the code cares.

The margin (+/- 15 degrees) is calculated based on the last angle, because the angle does increase with more head movement, we need to factor that in and have a margin that moves with the current angle. But if we exceed that margin, we have to ignore it (because there is a high likelyhood its a spike of 20-50 degrees (or more); so we use the old value instead. My experience has been that the spikes are one-off in otherwise stable output; so maybe once every 20 seconds at most; more than enough time for a new value to have been output and the old value to have been replaced.

The second article will contain the configuration of FTNoIR and the Arduino Hatire plugin, I’ll make further posts for a few games I own and the configurations I’ve opted for; including Arma 3, Assetto Corsa, Euro Truck Simulator 2, and Evochron Mercenary.

Configuring OBS

January 28, 2014 @ 11:59 pm

Open Broadcasting Software is an open source solution for streaming to the various streaming sites now becoming popular (Twitch, UStream, Youtube), but in addition to that you can also save recordings to disk; operating a lot more like Fraps or DxTory… yet of course, open source! While it is still in a beta state, its usable, though not without a few minor issues. Since the time of writing some updates may be fixed by using beta releases (it does have a stable version, to clarify).

Settings

Once you’ve installed OBS you may notice two shortcuts, 32bit and 64bit; it’ll be trial and error to a degree, but if you are playing a game with a 64bit executable/version then it might be worth attempting the 64bit version of OBS. Settings should appear across both versions.

Once you’ve started it, hit the ‘settings > settings’ to open up the menu. Starting with General, this allows you to create profiles of settings, primarily if you want different streaming sites pre-configured; but for the purposes of this guide I will be focusing on disk-based recording. Create a profile and call it ‘Local Recording’ or something to that effect. As a fore-warning, when you change which category of settings you are in it will prompt you to save or discard changes, if you’re happy with the settings, apply them.

Encoding

  • Video Encoding
    • Quality Balance: 10
    • Max Bitrate: 24000
  • Audio Encoding
    • Codec: Your Choice (MP3)
    • Bitrate: 320
    • Format: 44.1khz stereo

Broadcast settings

  • Mode: File Output Only
  • File Path: Use your recording drive and a filename (mine: R:\obs_recording.mp4)
  • Hotkeys, while optional, are extremely useful

Video

  • Ensure your main GPU/Display Adaptor is selected
  • Resolution Downscale: None
  • FPS: 60

Audio

  • Experiment at your will, but try and ensure ‘Use Input device for desktop audio’ is not ticked

Advanced

  • Use multithreaded optimizations: ticked
    • Process Priority Class: Above Normal
    • Scene Buffering Time: 200
  • Allow other modifiers on hotkeys: ticked
  • Video:
    • x264 CPU Preset: faster
    • x264 Encoding Profile: high
    • Keyframe interval: 0
    • Use CFR: ticked
  • Everything else has been left as default/unticked

Now, while still in the advanced section, you may notice Quick Sync and Use custom x264 settings for QSV are disabled; if they are available, tick them. Otherwise consult page 2 for more details on enabling these (if you use an Intel CPU with iGPUs (Ivy Bridge and later).

Setting up sources and scenes

Now OBS is meant for streaming, so it has a lot of streaming features; such as switching between scenes, these could be different layouts of elements, capture areas, monitors, webcams, games, images, text, etc. At the bottom of the main window you will see Scenes and Sources, to the right of those is the microphone and output volume (its advised to avoid using the main audio slider, though its perhaps unavoidable to adjust your speech volume).

Note the ‘Global Sources…’ button, the first proposed source is a hotkey based option; this should allow you to use a hotkey on any game which has focus. When you have the global sources dialogue open, hit Add, then ‘Game capture’ from the list; name it hotkey. Then select Use Hotkey, set the hotkey and leave everything else as-is.

I’ve suggested this as some games may loose their DirectShow hook either from the get-go or after a loading screen (what OBS uses to detect and record); having the hotkey gives you a means to attempt refocusing it without alt-tabbing or losing focus of the game – indeed you may opt to just use the hotkey outright, if you’re post-processing it shouldn’t be an issue to trim out black-screen footage.

Windows 8.1 and headphones

A problem I didn’t have with Windows 7 is that for some reason the recording of headphone audio was of a substantially bad quality; sounding bass heavy and a little muffled. This was solved by changing my Creative card to the Stereo speaker setup and Windows to Quadraphonic (this creates a faux-surround sound, which is passable when using headphones). This appears to have solved the issue of muffled sound.

GRID 2 Thoughts

January 17, 2014 @ 2:22 pm

To put the following scribbles into context, I was a fan of the first GRID game by Codemasters, it was a lovely all-round racing game which never particularly swayed towards realism or arcade-like gameplay. It struck the perfect balance for me, if any game got close to such mechanics since on the PC, that game would have to be Need For Speed: Shift. I won’t be limiting what I cover to GRID 2, not even to the racing genre perhaps, but as a gamer and consumer first and foremost, I worry about Codemasters.

(more…)

Tidying Up PHP Errors

October 4, 2013 @ 3:17 pm

This post should have something for people like me, I’m using a heavily tweaked choice of programs for my development server. The server in question is balancing multiple jobs – being a NAS for the household, a web server for my development needs, and of course the occasionally game server. So I tinker a lot, and the side effect is I have a server running Nginx and MariaDB – the latter causing the most trouble for a development server whereby I want to see issues reported somewhere onscreen.

Essentially this means I get a huge number of warnings about mismatched versions in the header, at least until MariaDB gets some major support (it basically acts as a MySQL drop-in replacement), the problem manifests as a large unformatted section of text warning me of mismatching headers – not a problem at all, apart from making a rather messy show of things on my lovely work-in-progress.

Anyhow, what I wanted to do was to shift all of those PHP errors, warnings and notices to the JavaScript console; I use it often enough so why not?! Please bear in mind, this is a development environment, not a production environment. I’ll be doing this with WordPress, though in theory it could be used in any framework or project – so long as the package doesn’t have its own error handling methods later which might interfere.

Updated 2013-12-18

(more…)

The Lost Art of Trolling

August 6, 2013 @ 8:46 am

I recently had a friend proclaim “what he is doing is trolling” in regards to an internet discussion whereby he was insulted, at which point I proceeded to  um and ah a sentence out to the contrary – but of course it quickly moves on to the actual discussion rather than why my friend was actually misusing the term ‘troll’ or ‘trolling’. Not that I agree with anyone insulting anyone else for their views, I think it disingenuous. Yet the media have made themselves a fine bandwagon using some slang and people are hopping on-board.

It does point out how a term has been acquired by the media and promptly misused to mean something rather different than the original intention. But I do feel now that the original definition has about as much chance of a comeback as the correct pronunciation of `gif` does (a soft ‘j’ for those wondering); most people, including myself, will continue using the hard g on that one, apologies Steve Wilhite. I would like to explore what trolling was, and what it has become in this new internet moment – and perhaps offer some other thoughts about it.

Onwards to the footbridge

Windows 8 opinion from a power-user

June 16, 2013 @ 5:52 pm

In late 2012 I got my hands on Windows 8 (the super cheap upgrade price), I’d used it briefly on a 17″ laptop but decided to forgo worries and concerns I’d had with the release candidate, and stick 8 on my desktop rig… this isn’t the only time I’ve undertaken such risky shenanigans of course, I ended up with Vista too. Anyway, I’ve been using it for a while now, and I think its not actually that bad. Of course, there is a catch to that – I’m probably classed as a power user; so things are a little different.

This means my usage patterns are a little different from the average everyday user, for one I use the keyboard for the vast majority of navigation – opting to search for applications and settings rather than slowly click my way through the various menus and panels; this particular means of navigation is something Ubuntu recently really wanted to nail down – enabling it throughout all the applications (in theory, I have no idea how it works in practice, the only Linux I use currently is Linux Mint and Ubuntu server).

(more…)

Navigation

Return to top Return to navigation Return to index beginning
Skip to toolbar