Blog

Code refactor

The last few days have been spent doing some fairly major refactoring and other code improvements. I wanted to add functionality for the FlthyMcNasty HP control systems and realised as I add extra API calls, then the main.py code would start to get a bit unwieldy.

To this end, I started learning about Blueprints in the Flask web framework I use.  Blueprints allow API calls to be added functionally in a modular fashion. This meant all the API definitions and functions could be brought out of main.py and into the actual script for the device in question.

Along with this I learnt how to dynamically import code into main.py, which coupled with using blueprints has given me a much more modular approach to adding various devices.

Now, plugins can be loaded by just adding them to a line in the config file. They will then be dynamically added on startup. This is going to make it a lot easier to add the various modules such as the PSI, logics, Charge Bay, etc. to the API.

Update and Roadmap

After a busy, busy May, June has been a bit more relaxing. May was filled with events, not just with R2, and pretty much drained my (and R2’s) batteries.

Got a few events coming up on the buildup to the big R2UK event in August, and a list of ideas for R2.

R2 Update

Until recently I was considering building another droid (as well as BB8), but with recent occurrences in my non-R2 life I’ve decided against it and have gone into a bit of a money saving mode. So, what does that mean? It means actually doing all the upgrades to R2 that I’ve been planning for ages and have all the kit for, but never got round to doing!

HP Twitch

I at least want to get the front HP twitching, and have done a quick model to mount the servos on and printed it out. Just need to work out the linkage ideas that will survive the little darlings pulling at it at every opportunity. These should run off the same system as the HP lights, and have i2c control

Modularise the code

Currently, adding new devices (lights, servos, etc.) involves writing a library and including that in the main code. I’d like to see if I can make each device a module which can be enabled and adds the commands dynamically to the REST API. Not sure how to do this yet, but part of the reason for doing my own control system was to learn some more difficult aspects of coding.

Knock/capacitive sensor

I want to actually utilise the REST API a bit more. One thought is a wifi knock or capacitive sensor installed in the dome that connects to R2’s hotspot to detect hands or whatever and play a sound via the API.

General brain improvements

After the Legoland event, I had to totally replace (and upgrade) R2’s brain. However, I only did the bare install and didn’t set up the extras in him such as the wifi hotspot, etc. I want to get this working properly to make debugging a lot easier.

Smoke generator

Another device for the dome, something to generate a load of smoke and that can be triggered via the API. This way I should be able to do a script to flap panels, play a sound, and release some smoke.

Theres loads of other general improvements to be made too, minor repairs and such like. I’ve also got a new set of foot shells to put on which should make swapping and maintaining the drives a lot easier than it is now.

 Another droid?

Yes, I know I said I’m not going to build another droid. By that I meant astromech. I’ll finish off BB8’s dome at some point, with some electronics in the eyes which I’ve already got. Got ideas to extend the normal setup of electronics to make him more dynamic.

My other thought was to produce a MSE droid. Something a bit fun and a lot cheaper than a full sized astromech. I also want to add features to it that I’ve not seen on other droids such as smoke, opening doors, maybe even a bit of AI for automated roving? Still 100% on the drawing board, and plenty of other non-astromech/droid related projects to do around the house, but it is something I’d like to do.

A lot easier to transport too. 😉

Apart from all that, got other Starfury events to help out at, and that nasty thing called Real Work to do to keep the money coming in.

BB8 build

Not happy with just having an R2D2, I’ve decided to also build a BB8. 🙂

The BB8 Builders Club is an offshoot of the R2 Builders Club, with many of the same members, and have kindly produced a brilliant set of 3d printer files to allow anyone to print out their own BB8.

Of course, for this I needed a 3d printer (or rather, another one). I’ve had a few printers up to this point with the last one being bought just over a year ago from ebay. However, none of them had really been any good and took way too much fiddling with to get even half decent prints out of. In November 2017 I took the plunge and preordered a Prusa i3 Mk3. This arrived at the start of Feb, and with a slight build issue that Prusa sorted out quite rapidly, I was ready to start printing.

As a side note, I can’t recommend the Prusa enough. Its a high quality printer, designed by one of the main members of the reprap project, and copied by just about every other cheap chinese printer out there. The official one is leagues ahead of any other sub £1000 printer, with auto bed levelling, brown out detection, no endstops needed, and a great support infrastructure.

So with the printer working, I started printing out the first BB8 parts. Currently, the plan is to get the dome finished before I even start thinking about the main sphere and if I’m going to make him radio controlled. The printer was running nearly constantly for a week, and I managed to get all the main parts of the dome printed without any major hassle or wasted filament.

The printing is, however, the easy part. Next comes a lot of sanding, gluing, filling, sanding, painting, a bit more sanding, and finally the last bit of paint. There will also be a bit of electronics to go in the dome, tho I will be trying to keep that to a minimum so that it doesn’t weigh too much.

Just waiting for some warmer weather so I can work in the garage and continue on with this build. The build gallery can be found here:

https://photos.app.goo.gl/QwztBR8r2jmAlrZN2

Release 1.0 of r2_control

After a few false starts and more or less total rewrites, I have decided that the core functionality of r2_control deserves a 1.0 release.

https://github.com/dpoulson/r2_control/releases/tag/1.0

The last few updates have added some much needed core functionality that makes this code work well for basic driving at events. Future versions will improve on this and add extra modules for more fancy items.

With this release, the following functionality is working, having been tested at a number of events over the last few months.

  • Sounds – 486 MP3 tracks installed, and easy to add more.
  • Servo control – Can add Adafruit 16 channel PWM controllers and control many servos for opening doors, etc.
  • Web control – Built in web interface to do basic controls and testing
  • PS3 controller – The PS3 controller is working well, interfacing with the r2_control API to trigger sounds, servos, scripts, etc. It also interfaces directly to the motor controllers for movement.

There is also some WIP functionality that I don’t class as core.

  • Monitoring – got a POC of system monitoring (voltages, currents, etc.)
  • Telegram – Communication and control over instant messenger

I’ve many plans for future expansion of r2_control for version 2.0, which I will hopefully get time to do in the coming months. These are just some of them:

  • Refactor of PWM code using updated Adafruit I2C libraries
  • Add modules for rseries logics and flthy HP systems.
  • Finish the monitoring system
  • Switch the dome control to packet serial rather than PWM servo control
  • Move dome control into core r2_control, rather than direct from PS3 controller
  • Auto dome (auto center, turn, etc.)

For now, there are too many events coming up to be able to risk taking R2 out of commission, so most of the work will be on tweaking the actual droid and tidying things up.

 

Omnis and center foot

As mentioned in my previous post, R2’s current main upgrade is to the center foot. The main parts to improve are the wheel, the shell, and the ankle attachment to the body. Improving all these should give a much smoother ride.

Wheels

Assembled set of wheels
Assembled set of wheels

Originally, the center foot had one large castor that swivelled on a mount. The main problem with this is that a) it has to swivel to change direction, and b) because of that the wheel needs to be smaller to allow the change of direction and not hit the foot shell.

With the new Omni wheels from Vex Robotics, there is no need to have any swivel built in as the wheels can roll in any direction smoothly. This also allows the use of much bigger wheels which gives a smoother ride and makes it easier to get over obstacles. The wheels were mounted into a custom chassis that I made from sheet and square tube aluminium which gave a very solid ride. (See this blog post for more info) This also mounted directly to the ankle to make the whole system more rigid.

See the build gallery for more pictures

Foot Shell

The foot shell I had in place was one I received near the start of my build, and was never particularly happy with. Recently a member of the UK Builders Club, Mark Leigh, started making some new steel foot shells for members and I decided to fork out for a set. I’m very glad I did as they are excellent quality and up to club spec.

Center foot assembly

There are a number of benefits to the new shells. For one, the side panels come off which allows for easy access to the main ankle bolt which was a major limitation of the previous one. Also, all bolts could be tightened up with allen keys or screwdrivers whereas before a lot of them could only be done to hand tight, and even then it was very awkward.

Lastly, the new foot shell is no longer structural, with the shell, ankle, and wheel chassis all being mounted via the same bolt. Previously the castor was attached to the shell, which was then attached to the ankle. When I removed the old foot, there was a lot of wear and potential failures waiting to happen.

Ankle

This improvement should never really have been needed if I’d done the job properly in the first place. The ankle is bolted to a plate which bolts through the body into the skirt. When I initially did this, I didn’t make sure the plate was a consistent level, and didn’t have all the bolts done up properly. This led to a lot of wobble and eventual failure of one of them, and then a temporary fix.

This time however, I made some decent spacers all the same length, and bolted everything through them to R2’s skirt (a new aluminium one, but that doesn’t really make a difference, would work fine with the old fibreglass one).

Conclusion

After all this, R2 was feeling rock solid, at least as far as the center foot is concerned.

R2's previously worst nightmare - carpet
R2’s previously worst nightmare – carpet

This weekend R2 was at NWCC Bolton which was going to be his first big test on the new foot. The night before the event, the organisers posted a picture of the hall where everything was taking place and it got me a bit worried. It was a fully carpeted venue. The only part that looked like a hard floor was a little bit infront of the bar where they had the arcade games lined up.

With the old foot, this would have been pretty much a show stopper. However, I got there and unloaded R2 into the hall and turned him on for a test.

Wow, what a difference. At his last event at new year, R2 had great issues being on carpet and I had to push him a fair bit. This time however, not a problem at all. I even got brave and tried going over the transition from hard floor to carpet, and he didn’t miss a beat or slow down. Even going over door thresholds with barely a judder.

This has got to be one of the best upgrades I’ve given R2 since I got him working. I’m so pleased with it all and would heartily recommend Omni wheels for any astromech. Infact, I’m currently wondering if I should replace the castors on the main drive too.

Of course, it wasn’t just the Omni wheels that made the difference, a combination of all three improvements contributed, but I do feel that the wheels made the majority of it.

Looking forward to the Northern Builders Day in a couple of weeks to show him off a bit more.

Weekend of code enhancements

The temperature is getting low, and after spending most of saturday getting numb fingers and feet whilst working on R2’s center foot, I decided to do some much warmer work in the office and do some code enhancements.

  1. Telegram Bot
  2. i2c Monitoring
  3. Drinks Mixer

Telegram Bot

Telegram is a communication system that I already use for my home automation, so figured it might be handy for R2 to use it to. Not many functions added yet, just some simple volume and sound commands, but the main function is the /status command.

Current Status
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Uptime: 14:26:25.870000
Main Battery: 24.865 (balance: 0.011)
Remote Battery: 
Wifi: 
Internet: True 
Location: 
Volume: 0.296875
--------------
Scripts Running:

Still some clean up needed, but gives a good way of checking various stats.

i2c Monitoring

This is something I’ve been wanting to add for a while, and have had the circuit and basic arduino code done already. It is all now tied into r2_control and so current draw and battery status (current voltage and max cell difference) can now be queried. Not only that, if logging is enabled then it will also log to a file twice a second (configurable) as a csv. This means it can be imported into a spreadsheet and graphed so I can see power draw throughout the day.

As can be seen above, the details can also be retrieved using the telegram bot and /status.

Drinks Mixer

Not so much part of R2 exactly, but it will be going into him. The plan is to have a few reservoirs, some pumps, and some control circuit to allow drinks to be mixed and poured.

A base outline of code is now done, which will take in an array of substances and amounts, and turn a set of i2c controlled motors on and off for the desired duration. Still lots to do on this, not least of which is to get a working circuit done, and a decent web interface, etc. But its a start.

Summary

So, all in all I’m rather happy with a mega weekend of hacking at R2. May try to get out to the garage one evening this week to do some more work on his center foot. I’d like to have it ready for the midnight premier of The Last Jedi that I’m attending. Trouble is, the garage is currently sat at around 4.5C.

Working on the new center foot

The main issue R2 has at the moment is a rather dodgy center foot. For a start off, the shell is actually structural which I don’t like. The shell is also not the best, with no easy access to remove the center foot without a full dismantle which isn’t easy.

So R2 got some new foot shells made up, and I started work on a new set of wheels to fit in them.

Based on a design by another builder (Youtube video of them in action), the chassis for the wheels is made out of plates of aluminium with some square tubing for spacing. The wheels going into them are 4″ Vex Omni Pro ones, which allow movement in all directions, not just forwards and back. Much better than a caster as it doesn’t have to swivel when changing direction. Also allows for larger diameter wheels which helps getting over bumps.

Center foot chassis
Center foot chassis

This chassis will be bolted directly to the center ankle, and the foot shell will more or less just be floating on top. This, coupled with a few other modifications and tweaks, should make for a much more steady ride with less rattles.

 

Birmingham MCM, MOT, and Tier 2.

This weekend was R2’s first official outing with the UK R2 Builders. We were invited to attend Birmingham MCM Comic Con with the UK Garrison, an arm of the 501st cosplay group.

I loaded R2 into the car on Friday after work, and drove down to a hotel near the Birmingham NEC. Due to late booking of the hotel, I wasn’t really left much choice, and it showed.  Saturday was an early start so I tried for an early night so I was all set for a 7am start. That didn’t go quite to plan, nor did the hotel room shower. Still, fun and games at the hotel were just a blip on what promised to be a great weekend.

After driving round and getting lost in the maze that is the NEC, I finally saw a few other builders who were also trying to figure out where to go and its always better to be lost in a group than on your own.

Eventually we did find where to park, and where we were unloading and after a quick registration we started getting the droids into the building and set up on our stand.

First order of business was to get my droid a pass on his MOT. To be allowed at official events, and to get some Public Liability Insurance (you know, just incase I ‘accidentally’ run over a little darling who is poking R2 too much), R2 has to pass a club MOT and I have to show I can drive him. Its a really good idea, and adds a great level of professionalism to the whole event.

Thankfully, R2 passed, which meant he was free to roam around and entertain.

The Saturday of the event was extremely busy, with so many extra people showing up that we pretty much didn’t leave the stand. Not only that, but the UK Garrison couldn’t do their usual parade due to safety worries. Still, it didn’t really put a damper on things as people were constantly coming to the stand and being entertained by the droids.

It really is fantastic seeing the interactions that people of all ages have with R2. He isn’t just a remote controlled robot, he is an actual person to a lot of them, and I’m less of a driver and more of a puppeteer.

Then there are the Jawas. Damn things get everywhere!

Only kidding, the UK Garrison have a few Jawas in their midst, and they certainly get into character. It was so much fun getting R2 to play along with them and everyone around absolutely loved it. Even better when their wrangler started jangling keys to distract them and move them along. Bringing out the play in cosplay.

The day passed all too quickly, and we were soon packing up for the day and making our way back to our hotels. A few of us went out for a meal that night at a local hotel, and surprisingly the conversation wasn’t just about droids. Well, not quite anyway.

Another attempt at an early night and a bit more sleep was had, ready for a not quite so early morning on Sunday. The doors were opened for us at about 8:30am, and we wandered in to make sure the droids hadn’t got out over night.

Sunday was a little bit quieter, so a few of us managed to roam about the convention a bit more. I took R2 out on a number of jaunts through the day along the concourse infront of the halls where MCM was running. It was a great area to roll around, lots of people but not as packed as it was around the stalls and other areas.

It did take quite a long time to get from one end to the other, not because of the distance but because he was getting stopped every meter or so for photos, or to chat with me about him. R2 really does like his picture taken, much more so than I do.

We had a few more encounters with the Jawas, and some sneaky avoiding of imperial troops looking for droids but I managed to convince them that these weren’t the ones they were looking for. There was also a group of large feline types who seemed to take a great interest in R2 and got a little curious.

The UK Garrison do a troop on each day if possible, and thankfully they were able to do one on Sunday, not only that but R2 was allowed to join in. At 2pm sharp, we waited outside the UKG changing room, ready to tag onto the end of the parade. There were a lot of the UKG there, I thought the line coming out was never going to end, but it eventually did and R2 joined in. We did a basic loop of the event which took about 20 minutes, it was great fun even for someone like me who doesn’t like to be in the center of attention. Of course, R2 takes a lot of it off me.

So, you’d think that was the highlight of the weekend? Nope, as the event was drawing to an end, I noticed a load of rebel pilots gathering around at the stand next to us. Next thing I know, Anthony Daniels asked if he could borrow my droid for a photo shoot. Not really going to say no now, am I? He stuck around afterwards too and had a few other photos with some of the other droids too.

Sadly, the event drew to an end. We were rather tired by this point, me, the other builders, and even poor R2’s battery was starting to show some signs of tiredness. R2 got loaded back into my car (I really need a van!), and I set off on the 2 1/2 hour drive home. A quick take out once I was in, and then bed became too tempting.

Now that I’ve recovered however, I’m planning the next steps with R2. As well as the MOT to get insurance coverage, there is also a tier 2 option. Tier 2 means that your droid is effectively screen ready (maybe not screen accurate, R2 changes too much between the films and even between scenes in the same film!) and can be used in official Lucas/Disney functions.

This is another great thing about the R2 Builders club, we have tight bonds with Lucasfilm, and now Disney, and occasionally get asked to do some official events. Anyone who is active in the club and has a tier 2 droid can get the chance to do one of these events.

To this end, there is now a long list of issues on my github page that needs sorting to get tier 2 approval. After a weekend with other droids, and seeing what is possible, it has pushed my motivation up a level to improve the droid, and also given me direction. I’m going to stop going for the fancy stuff, and instead concentrate on getting R2 as solid as possible, and looking the part.

Python code to control an R2D2 (or other astromech) from a Raspberry Pi over i2c
Milestone: Tier 2
Issues: 2 open, 11 closed.

Make R2 more solid for shows, and aim for that Tier 2 classification (ready for LucasFilm)

So all in all, it was a really fun weekend. I don’t think the smile left my face during the entire event. I really can’t wait for the next big event with the builders.

Spectre Squad Photo Shoot

This morning, Spectre Squad had got access to the Preston Laser Quest arena for doing some photo shoots with everyone in their gear. R2 wasn’t going to miss out! Early start (for me), but no real problems. Car quickly loaded and off to Preston.

Got there a little early, and waited for the facilities to be opened, then the problems started…

Managed to get R2 through the door, just, and started wheeling him through to the changing room area so I could put him together properly and get him running.

Unfortunately, half way there his foot fell off. The center foot just decided it no longer wanted to be attached. This coupled with the fact that the main leg nuts weren’t tightened yet led to a very unstable droid. Unable to really move him anywhere, I had to get some help to lay him down, whilst I started figuring out if it was repairable or not.

Thankfully, it seemed there was no real damage, and just the main nuts had worked loose. Probably thanks to the nut rattling floor at Preston Guild Hall during the previous event. It still took a good twenty or thirty minutes to dismantle the foot, bolt it back in place, and reassemble it.

Ok, that was the fun for the event, right? Nope. I powered him up and tried to activate the controller. For some reason, there was no connection made. A bit more faffing with mobile phone hotspots and the laptop and I determined that the controller had just lost its pairing with R2. No problems, I’ll just re-pair.

Darn, need a mini-usb cable, and I’d not brought my bag o’ cables. Asking around, noone had one handy. Plenty of usb-micro, but no mini. Last ditch attempt was to ask the staff of the Laser Quest. To which I got presented a rats nest of cables, with the hope that what I wanted was in there.

Success! One fully functioning droid!

With all the drama over it was time for photos. First one was a full group shot outside. Not the easiest of things to do with cars driving by (we got a fair few honks and waves as they passed), but managed to get a decent shot or two

Spectre Squad, outside Preston Laser Quest and Escape Room

Then it was into the arena for various posed and group shots.

We eventually got turfed out as they started to get paying customers coming in, including a kids birthday party who got the added bonus of some Star Wars people attending! R2 did get a bit of a mauling from them, but he’s fairly tough for the most part.

It was a really enjoyable morning, despite the difficulties with R2. Was great meeting more of the Squad, and getting to know them a bit better. Hopefully I’ll be able to troop with them more often in the future, as their events are generally in the North West.

So, lessons learnt for next time? Well, first of all I think R2’s feet need a full overhaul, especially the center one. Fingers crossed I’ll be getting my new foot shells next month, and can start on an improved center wheel solution. I also need to make sure I’ve got the right cables with me. A usb-mini is already in my toolkit.

I also need to improve the options for diagnosing issues and connecting to him with my laptop. He will soon be getting a dedicated 3g connection and will be a wifi hotspot so I can connect directly with my laptop. Possibly also a VPN back to home.

Looking forward to my next event! 😀