Deepwire's Blog

Programming

Joystick.

by on Apr.08, 2014, under App Development, Electronics, Programming

In my new found free time recently, between unsuccessfully searching for a new job and having it made clear that money is more important than I was led to believe, I’ve been taking part in a couple of MOOCs (Massive Online Open Courses) for Android Development. I have previously toyed with Windows Phone development (for Windows Phone 7) but felt that while easy, there wasn’t much point to it. I don’t have any killer app ideas, and there just isn’t the user base. Since switching my own phone to Android, I’ve wanted to look at Android development, but did not really have an idea to develop.

Since getting an m3pi Robot last year, I finally had a complete robot to play with, after still never solving the problem of how to connect the omni-directional wheels to the output shafts of the motors on my Netduino based robot. It made sense to recreate the Windows Phone app I wrote to control the Netduino robot for Android to control the m3pi. But where do I start? Fortunately, the two MOOCs had me covered.

The long-winded “Programming Mobile Applications for Android Handheld Systems” from the University of Maryland was where I started. This was a very dry, rigid course, that went step by step through Android development concepts individually, out of context from a complete app. One week was spent looking at Intents, another on Permissions, another on Fragments etc. It was a good starting point, but didn’t do a very good job at showing how everything fits together into a complete app.

The second MOOC, “Begin Programming: Build Your First Mobile Game” from the University of Reading, has been much more fun. Right from the start this course gives you a working Android game, shows you it working, and lets you explore the code. Week by week it then goes through different programming concepts, such as Variables and For loops, explaining how they are used in the game. It’s a good combination of programming for beginners, and an introduction to Android development. Straight away this gave me the perfect framework to use as a starting point for my m3pi Controller App. From what I’ve learnt on the two courses, and help from Google, I’ve managed to get an app working to send UDP packets over WiFi to the WiFly module on my m3pi. It’s not perfect, it still crashes often, particularly when I try to leave the app, but it does the minimum I need it to.

But that didn’t mean everything was finished. For my Netduino robot, as I planned to use omni-directional wheels, my control method of providing a direction and magnitude (dragging a ball away from the centre of a circle in any direction) worked well. The robot would just move instantaneously in that direction, it’s speed determined by how far away from the centre the ball was. But for a 2 wheel robot with differential drive, this wouldn’t work. I needed different programming on the robot to receive the data sent by the Android app, and move the robot in a sensible manner.

I spent a long time pondering this, looking into robot kinematics and curved path planning, getting myself more and more confused finding ever more complicated potential solutions. Then it hit me. Joysticks. What I had basically made was a virtual touch screen joystick.

I could move the ball around a central point in a constrained circular area in much the same way that a joystick is pushed in any direction about it’s pivot, up to a maximum angle. Realising this, I thought there had to be a simple method for driving a 2 wheel differential drive vehicle by joystick. Another quick Google and I’d got my control technique!

The app essentially outputs 2 values, corresponding to the X and Y coordinatates of the ball, in relation to the centre (origin) of the circle. Both the X and Y are in the range -100 < 0 < 100, but also constrained to stay within a circle of radius 100 about the origin (so coordinates such as 100,100 are never possible). The technique I am using is adapted from Roborealm’s page on Differential Drive. Essentially the Y value is responsible for the speed forwards/backwards, and the X value is responsible for the robot turning.

Each received value is first normalised into the range -1.0 < 0 < 1.0, by dividing by 100, as the m3pi motors require a speed in this range. Following the Roborealm example, each value is then halved. This is still something I am experimenting with, as it does limit the top speed of the robot. But it is is required to allow the robot to turn.

The turn value is calculated from the X value, subtracting it’s value from the left motor’s speed and adding it’s value to the right motor speed. If there is no forward/backward (Y) component, the wheels will spin in exactly opposite directions at the same speed, causing the robot to turn on the spot. If there is any Y component, it creates a speed differential between the two motors, such that one spins faster than the other, even if both are turning in the same direction. This allows the robot to drive in a curved path. My current implementation of this algorithm for the mbed on my m3pi robot is below. Variables rx_x and rx_y are the integer values received from the Android app, in the range -100 < 0 < 100.

speed = ((float)rx_y/100) * 0.5;
turn = ((float)rx_x/100) * 0.5;
//Calculate the left and right motor speeds using the speed and turn values
//By adding the turn value to one motor, and subtracting it from the other,
//it creates a speed differential so the robot will turn
//(if speed = 0, robot turns on the spot)
mleft = speed - turn;
mright = speed + turn;
//Check motor values, and limit within -1.0 < 0 < 1.0
//if they exceed this range
if (mleft < -1.00) {
    mleft = -1.00;
}
if (mleft > 1.00) {
    mleft = 1.00;
}
if (mright < -1.00) {
    mright = -1.00;
}
if (mright > 1.00) {
    mright = 1.00;
}
//Set the motor speeds to move the robot
m3pi.left_motor(mleft);
m3pi.right_motor(mright);

There is a point to having the initial values halved. If for example the Y value received was above 50, and the X value was also above 50, then the combined value given to the right motor when normalised would be above 1.0 (e.g 102/100 = 1.02). This is above the maximum speed possible, so the motor would be limited to run at maximum speed, and the motion of the robot would be inconsistent with the input.

Halving the input values ensures the speed values sent to the motors stay within their minimum and maximum limits. Unfortunately this does limit the maximum speed, both directly forwards or backwards and spinning on the spot, to 50% of the maximum. But it does mean the motor speeds change continuously for all X and Y values received from the Android app.

I will continue experimenting with this, seeing if I can improve on the algorithm to allow for maximum speeds in all cases (e.g. both motor speeds at 1.0 for forwards). Having realised my Control App is a touch screen joystick, I may even rewrite it as a general wireless robot remote control, as it doesn’t really need to be specific to the m3pi. That was just what gave me the incentive to get started.

Leave a Comment :, , , , more...

Me. Redesigned.

by on Jan.31, 2014, under Programming, Random, Web Development, Work

I left the PGCE course. After spending the Christmas period thinking long and hard about it, I came to the realisation that teaching is not for me. At least, not right now. Who knows, maybe in 20 years time I’ll be ready. I got a lot of advice about what to do, some people suggesting I’d probably get on better teaching in a college or adult education. Others said I would probably have felt differently had the Computer Science PGCE actually been primarily Computer Science, and not have me teaching mostly ICT. That is true. If I had stayed, I would have done a short placement in a different school, one that did teach Computer Science. But even so, my feelings were more on the experience of teaching in general, things that would be the same at any school. And also the growing realisation of what I want to be doing.

I still don’t know what I want to do. I don’t have a single job in mind that I want to do, or specific company I’m desperate to work for. But one of the things I missed most was ‘making things’. The chance to build something from components, or write software, or program an embedded system, and the persistence to keep going and overcome any problems to reach the desired end goal. To make it do what I want it to do. My last job didn’t give me much opportunity for this. Any software was likely to be VBA based in Microsoft Word or Excel, and even that was much less a part of my role towards the end as they shifted the focus of our team to providing training courses.

I feel knowing I want to do more of that is a good thing. Since leaving the PGCE, I’ve had time to work on projects of my own and go through the material on different online courses, to try and learn new things. I won 6 months subscription to Treehouse when I went to Breaking Borders in December. While I am currently between jobs, I’m working through as much material on there as I can. Even though I don’t want to be a web designer (maybe a web developer) I have gone through all of their web design material. I have then taken what I’ve learned there to completely redesign my website http://dw87.co.uk. It’s not much, but it now makes use of more current date HTML and CSS than before, and looks different.

I’ve also finally made use of my Raspberry Pi, after perhaps avoiding it because I had never really used Linux. I’ve made a project that uses a web server on the Raspberry Pi with a Python script to change the LEDs of the PiGlow module when someone visits my website. This was also a good opportunity for me to join and learn to use Github, something I had also not used (shocking, I know). For those interested, the project can be found here, PyGloworm.

I am also working on another web project using Twitter, to explore their new 1.1 API, as it’s all changed since I last developed anything with Twitter (about 4 years ago). I am really enjoying the challenge of knowing what something should do, and trying to work out how to make it do it. Over Christmas, I admit I did a lot of gaming on my Xbox 360. Since starting work on my own projects, I’ve been more focussed on making them work, and learning what I need to achieve that, and have barely touched my Xbox. In fact, I’ve only really touched it to swap the HDMI cable over into my Raspberry Pi so I can use the same screen. After the Twitter project, my next goal is to get into Android development, and convert my old Windows Phone 7 app that controlled my Netduino robot into an Android app to control my m3pi robot.

As well as redesigning my website, I feel that I am redesigning myself at the same time. I’ve got a better idea what I want to do, and I’m enjoying working on projects of my own while hopefully learning new skills at the same time. I’m even considering taking up a new hobby, something I’ve not really had in recent years. I’ll keep you posted on that one. Even though I’m technically currently unemployed, I feel more positive about things that I have for a long time, and hope I can find a job that won’t rob me of this feeling.

Leave a Comment :, , , , , , , more...

It’s finally over!

by on Dec.31, 2013, under Electronics, Programming, Random, Technology, Work

2013 has come to an end. Thank f**k for that!

The fact that this year was numbered 13 was never going to bode well for anyone. Superstitious or not, the number 13 is never very appealing, and to have it looming over every single day this was not going to be good. But it’s finally over. I have no idea if 2014 is going to be better, but it already gets off to a better start being the number 14.

It seems 2013 was the year things went wrong. I went in to the year with bright ideas of changing careers and doing something completely different, that I actually had the right skills and qualifications for (after multiple rejections at job interviews confirming the experience I’d got from my job was not sufficient enough for anything) – teaching. With Computer Science coming onto the National Curriculum from 2014, it seemed like the perfect time to train. Everyone was saying it would make getting a job really to start teaching Computer Science in September 2014, when more schools need to offer it.

Unfortunately the University were loose with their naming and description of the course. A PGCE in Secondary Computer Science feels more like a PGCE in Secondary ICT with Computer Science, as many of us found ourselves placed in schools that only teach ICT. Not what we thought we were signing up for. Coupled with the drastic increase in funding if we waited until 2014 (more than double the training grant, for the same classification of degree), it definitely seems 2013 was not the right year to train. If we had waited to start until 2014, we would have had more chance of being placed in schools that teach Computer Science, and better funded! But now I’m on the course, I either stick it out and finish, even though I no longer feel teaching is the right job for me, or leave and somehow find something else to do. But I was already not skilled or qualified enough for most of the jobs I wanted to do, so it’ll be near impossible to find anything.

I leave 2013 behind, glad to see the back of it, but not having a clue what the future holds. All the advice I get is I should stick with the course, that no matter how I feel about it, I should complete it. If I follow my gut feeling though, it’s that I should leave the course, and find something new. That I really don’t actually want to be a teacher, now I’ve had the opportunity to experience it. I’m definitely glad I’ve tried, not only did it get me out of a job that was making me miserable to the core, but it gave me the chance to find out what being a teacher is actually like. That is not something I could ever have found out from reading books or talking to people. It’s just that now I’ve found out what it is like, I am 99% certain it is not what I want to be doing with my life. Not now at least.

So I go into 2014 even less certain about what I want to do, and where I want my career to go than I did going into 2013. At least then I knew I wanted to get out of a job I was stuck in. I wrote last year that you should always follow your instincts, not advice from other people. Right now my instincts are mixed, but more on the side of leaving than staying. It is the advice of others that is pushing me to stay.

But it is also not knowing what I would do instead that stops me. I know I enjoy working with electronics, embedded systems and some programming. But I don’t really have enough skills in any of that to get a job doing it. I might get lucky and find a junior/entry level position, but I doubt it. I know I enjoy working with young people, within Scouting and things such as Young Rewired State, helping them learn to code. I have tried combining all of that by going in to teaching, which hasn’t worked. But I think it would be difficult to find a job working in just one of those areas, that I would enjoy.

I’ve got to hold out hope that something will work out. Whether I suddenly start enjoying teaching, and ‘see the light’ that it is the right thing for me to do, or I find some other opportunity – either I apply to a job and miraculously get it, or something else comes along. If I don’t, then it’s difficult to see the point in anything.

Leave a Comment :, , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!