Thursday, 19 November 2015

Thinking time

I built a driveway for my house this week so I didn't get much done on the robotics project. I did go to the society meeting and it was probably the best yet. The format was a show and tell so we all turned up, setup the robot we'd been working on and then just had a chat. The first thing I learned is that when you ask people to come along and show what they've done, it's a small meeting. 

This was great for those that turned up because it gave me the opportunity to have a good chat with the people who are genuinely interested in making stuff. I learned a lot about my robot, boot scripts, PIDs,  analogue gpios, transferring files, stepper motors and methods of driving them. It was also good to chat to 4th yr+ students about their experiences so I know what to expect.
It turns out my idea of trying to get a % reading from my IR sensors rather than an on/off reading is an actual thing, I just need to convert the signal to analogue and then decide what to do with it. I could do this with my teensy, also,  if I want more than 3 sensors to improve accuracy then I can make a circuit board on eagle and print it out. Everything is coming together.

I didn't join a society to get drinking buddies, I've got more of those than I can handle and if a society is just a branded drinking club I can do without it. This society is my kind of thing; a group of people who are genuinely interested and active in the subject rather than a load of people just wearing society t shirts and getting pissed.  I think I would enjoy getting pissed though...

Sunday, 8 November 2015

Tony Montana

I spent today getting the code sorted to make the robot follow a line.

The actual code was a lot longer originally but it's nice and compact now.

I'm not sure at what point a piece of code becomes your own; so far I have read through other peoples code, cherry picked the bits I like and then changed them to suit my application.  Apart from naming variables/commands etc and choice of GPIO pins there must be a finite amount of ways to control a line following robot using Python and I guess even if I think this piece of code is unique, it probably isn't.

Anyway, I have spent considerable time on it and it works so whether its truly mine or not I take pride in it.

Update: I put a line of insulation tape on the kitchen floor for the robot to follow and it didnt seem to pick it up as well as when I had the robot on the desk in my office.  The floor is more reflective in the kitchen and the robot seemed to spend a lot of time with 3 lights on and getting confused.  In addition to this I accidentally dropped a screwdriver onto some of the contacts on the line sensor; there was smoke and a smell of burning.  It still seems to work ok...

I think I am going to do another test run but without the section of code where it has an action to take if 2 sensors pick up the line.  And i'll have to do that another day as Jane has just got home and is wondering why there is a line all around the kitchen.

Here's todays code:

import RPi.GPIO as GPIO, sys, time

#use physical pin numbering

GPIO.setmode(GPIO.BOARD)

#pins:  7:left rev, 11:left for, 13:right for, 15:right rev.


GPIO.setup(7, GPIO.OUT)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)

def Stop():
    GPIO.output(7, GPIO.LOW)
    GPIO.output(11, GPIO.LOW)
    GPIO.output(13, GPIO.LOW)
    GPIO.output(15, GPIO.LOW)

def Forward():
    GPIO.output(7, GPIO.LOW)
    GPIO.output(11, GPIO.HIGH)
    GPIO.output(13, GPIO.HIGH)
    GPIO.output(15, GPIO.LOW)

def Reverse():
    GPIO.output(7, GPIO.HIGH)
    GPIO.output(11, GPIO.LOW)
    GPIO.output(13, GPIO.LOW)
    GPIO.output(15, GPIO.HIGH)

def Left():
    GPIO.output(7, GPIO.LOW)
    GPIO.output(11, GPIO.LOW)
    GPIO.output(13, GPIO.HIGH)
    GPIO.output(15, GPIO.LOW)

def Right():
    GPIO.output(7, GPIO.LOW)
    GPIO.output(11, GPIO.HIGH)
    GPIO.output(13, GPIO.LOW)
    GPIO.output(15, GPIO.LOW)

def Hardleft():
    GPIO.output(7, GPIO.HIGH)
    GPIO.output(11, GPIO.LOW)
    GPIO.output(13, GPIO.HIGH)
    GPIO.output(15, GPIO.LOW)

def Hardright():
    GPIO.output(7, GPIO.LOW)
    GPIO.output(11, GPIO.HIGH)
    GPIO.output(13, GPIO.LOW)
    GPIO.output(15, GPIO.HIGH)

#speed is 0.2 m/s
#1 second hardleft or hardright = 45 degrees
#left/right is slight change in direction

#line follower
#IRleft = 16
#IRcentre = 18
#IRright = 22
GPIO.setup(16, GPIO.IN)
GPIO.setup(18, GPIO.IN)
GPIO.setup(22, GPIO.IN)



try:
    Stop()
    raw_input("Say hello to my little friend.")
    while True:
     
        lineleft = GPIO.input(16)
        lineright = GPIO.input(22)
        linecentre = GPIO.input(18)
     
#if it picks up a line the input is 0
     
        if linecentre == 0:
            if lineleft == 0:
                Left()
            elif lineright == 0:
                Right()
            else:
                Forward()

        else:
            if lineleft == 0:
                    Hardleft()
            elif lineright == 0:
                    Hardright()
            else: Stop()
 
 

except KeyboardInterrupt:
    Stop()
    GPIO.cleanup()

Wednesday, 4 November 2015

Had a lecture on making circuit boards with eagle today. Managed to get my head around most of the stuff and feel like I could probably get something done, when I know what I want to do.


Tuesday, 3 November 2015

Finally Moving!

I woke up early (4.30am) on Sunday as I had an idea and it wouldn't go away.  Usually a line sensor will give a combination of on off readings from 3 sensors.  I was wondering how easy it would be to get the outside sensors to measure what proportion of the central IF signal was being bounced back; essentially trying to get some crosstalk but put it to use. If setup right then these readings could be used to set the pwm for the motors; the benefit of this would be smoother direction changes and a greater range of direction change.  I have no idea if this would work or how I would do it which seems to be a regular occurrence for this project.  There was also the small matter of my chassis still not actually moving.

After a bit if faffing around with wires and batteries and stuff I realised that there needed to be a ground from the driver to the pi otherwise there was no circuit for the signal to travel around.  Secondly I found out the the L298 driver board has an on off button.  It's not labelled and I have not seen any mention of it online so I only discovered it by accident when I accidentally pressed it while attaching the ground wire.

It is the white square shaped thing at the bottom of the board:


So if you're working with an L298N driver board and it doesnt work, check its grounded to the pi as well as the power supply and make sure the on/off button is on.

Once these two things were done the motors ran fine.  I ran the test program I had written and it worked perfectly:

import RPi.GPIO as GPIO, sys, threading, time

#use physical pin numbering

GPIO.setmode(GPIO.BOARD)

#pins:  7:motor4, 11:motor3, 13:motor2, 15:motor1.


GPIO.setup(7, GPIO.OUT)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)


#motor test
GPIO.output(7,GPIO.HIGH)
time.sleep(1)
GPIO.output(7,GPIO.LOW)
time.sleep(1)

GPIO.output(11,GPIO.HIGH)
time.sleep(1)
GPIO.output(11,GPIO.LOW)
time.sleep(1)

GPIO.output(13,GPIO.HIGH)
time.sleep(1)
GPIO.output(13,GPIO.LOW)
time.sleep(1)

GPIO.output(15,GPIO.HIGH)
time.sleep(1)
GPIO.output(15,GPIO.LOW)
time.sleep(1)

GPIO.cleanup()

I decided this was a good point to give some time to the mechanical engineering degree I am studying; mechanics comes easier to me than electronics. Clearly.

On Tuesday I was up at 4.30 am again with another idea that wouldn't go away, I woke up and wrote a quick Matlab program that would do the calculations for me that I need to do for mechanical design unit.  It worked first time, the hand calculations I did agreed with it so I was very happy that I had done something that didn't require 10 hours of problem solving.
On reflection, the 10 hours of problem solving I've done on the robot is more a reflection of my understanding of electronics rather than the difficulty of the problem.


Wednesday, 28 October 2015

I had a go at fitting the mobile phone charger today, it was tight but it fit. I had to use longer screws for the mounting board and made some spacers from gear ferrules from my stash of bike components. I thought i'd check the weight of the different battery packs, the new one is half the weight. This is good.

Its a good job I did this as it turned out I didn't have enough batteries to supply the pi and the motors. More on this later.


I then spent the first part of the afternoon writing some code to test the motors, I will post this shortly. I then spent 3 hours debugging it because it did not work.  After this I realised that the battery charger I have says that the battery is full when in fact it is flat.  The only conclusion I have drawn so far is that I am a massive dickhead for not checking it sooner.

Tuesday, 27 October 2015

Mobile pi power?

I happened to be in the right place at the right time today and was given a mobile charger for my phone. After checking the specs it seems it delivers just the right amount of juice for a pi, 5V at 1A.  I'll do some double checking but it see if it will be ok but it seems like a pretty nifty way to power the board on my robot.
After consulting google I think this will power my pi for just over 2 hours so long as I don't run anything with too high a demand for power. I think it will fit nicely in the chassis too.

Sunday, 25 October 2015

Idea for line sensor

So I had a line sensor but there's no information available about how far off the ground it should be. The dagu chassis I'm using also has adjustable ride height so I thought I would experiment with the height of it and see what sort of effective range it has.  After thinking about designing a height adjustable mount for it which I could 3D print I realised that I could have the same thing by sticking a breadboard on the front and using the different connections to play around with the height.  I guess it will affect ground clearance but I only want it to move around on a relatively flat surface; I'm not building a new mars rover.

Next step is to see how it moves and play around with the motors. After that I'm going to play around with the line sensor and see what it can and can't do.

A proper workspace.

I have an amazing and supportive wife however she likes a tidy house without bits of bike or robot strewn about. She's an interior designer and architectural visualiser so I can't blame her.

It was time to sort out a proper workspace and fortunately I had a storage room begging to be re-purposed. I ripped some shelves out and stuck my grandpas old writing desk in there; he was a professor of engineering at Newcastle University and used to mark engineering exams sat at the desk so it seemed appropriate.

I had a monitor donated to me by my friend Rich Lambert and a keyboard and mouse donated to me by Jane's studio. On top of that I had a gold plated HDMI lead that I somehow got suckered into buying when I bought a new telly. This was the perfect pi programming station and I can make as much mess as I like and I don't have to tidy up at the end of every session.

Saturday, 24 October 2015

Week 4, proper assembly

Made some good progress this week. Attended a lecture on basic programming which was useful; a lot of it went over my head but I think its important to try and absorb it anyway. I spent half the time googling words that were being used and am becoming more familiar with the terminology.

I got my mounting board printed and the measurements were fine however I had trouble mounting the motor driver board due to the bolts I was using being to long and hitting the battery. Still, 2 of the bolts were fine so I just used 2.  I put the batteries in for the motor and then removed them after bridging the wires with my arm. I figured I shouldn't fit them all until its ready to roll.  This reminded me why I've never liked electricity; you can't see it and it can kill you.

I spent some time on friday evening wiring it up and then went to the pub and drank some beer.

On Saturday morning the ubec cable I had ordered was deivered so this got attached too, I think it is now at the stage where I can get it to do stuff.



Monday, 19 October 2015

Software issues

Today I found out that solidworks 2016 is not backwards compatible. This evening I will be downgrading both windows and solidworks.

Sunday, 18 October 2015

Designing a board

This weekend I modelled all the boards etc on solidworks so I could play around with the layout of the components.
I designed a board to mount on top of the dagu tracked base which would enable me to mount everything neatly and route the wires.
I aim to make seperate mounts for the line sensor, ultrasonic sensor etc so I put a pattern of holes at one end of the board to allow things to be switched out.


Monday, 12 October 2015

First go at wiring

After ruining myself at Indymanbeercon on Friday night I decided to get the arduino setup on saturday.  This was 5 hours of pain.
Getting IDE installed was fine; I could not get the drivers installed no matter what I did.
Whether it was a hardware wizard or manually installing drivers I had downloaded I could not get it done.

In my device manager it did not say 'ports com' as it should, instead just saying 'other device' which I could not get to work. I found myself typing stuff I didnt understand into google and then getting frustrated that I didnt understand the suggestions.

I gave up and decided to have a look at the pi. This is the point I found out that my pc monitor did not have an hdmi connection. Swearing.

Saturday and sunday night I decided to get the components wired together.  I thought it would be best to just use the gpio pins on the pi and leave power distribution seperate from the board so I didnt blow anything up.  I could then lay out the power circuit on a breadboard and install resistors as necessary.

I got the control bits done by the end of the weekend. It looked like this:
I think at this point I realised that one of my project goals should be to design and build something to hold all this in a way that makes it easy to work and looks nice. I reckon I'll see if I can get it done on solidworks and 3d print it. I used solidworks for the first time last week so it should be a good bit of practice.

On Monday I went to see Tom in the robocave for some help with the arduino. We got mine working on a different laptop and none of the working nanos would get recognised by my laptop.  Turns out that if you have an arduino nano with an unlicensed driver chip then there is a high chance it will stop your laptop from working with any arduino nano.

Once again I got hooked up; Tom sorted me out with a teensy which is much better than an arduino nano and can be made to work with the IDE software by installing something called teensyduino. Unsurprisingly, it's tiny.

First tinkering

I thought id try and get my head around all the connections on the boards; this took a while as I didn't even know which type of components I had. I googled the shit out of it and managed to work out how to connect the motor driver to the chassis.  At this point I realised I was gonna need some more stuff.


Luckily ben posted up on fb that he had some more kit, after a quick trip to his robotics cave in sackville street building I had an sd card for the pi, a couple of servo's for a tilt and pan mount and an arduino.

I liked the look of the arduino as it was smaller than the pi and it seemed to be more intuitive to connect due to the pins being labelled.

I then went on ryanteck and picked up some connecting wires, a line follower, resistors, tiny snips and tweezers as the ones I use for my bike were ridiculous. This turned up on saturday with some haribo which helped my hangover.

Selectimg some parts

I had a look at raspberry pis and thought that this would be a good start as I was already doing some stuff on code academy in python.  I also liked the scratch language that can be used for exploring the concept of programming without getting bogged down in the detail of the code.

I set up a pinterest board and started getting a shopping list together.
https://uk.pinterest.com/Ageorgechambers/robotics-project/
I quite like this as it enables me to have a visual bookmark for relevant stuff.
I also found a magazine called the magpi which is produced by the pi guys; this months edition had an article on making a line following robot which was handy.  I felt it was important not to copy this.
Basic shopping list was: battery and method of distribution, pi 2, motor driver, motors x 2, ultrasonic and line sensors.  I didnt know what else I needed at this point.

The robosoc sorted me right out, I came out with a dagu rover 5 tracked chassis with motors and encoders, a motor driver, raspberry pi 2, radio things.

I had no idea what I was doing.

The brief

The first step was to join the society facebook group.  Next came the information about the challenge; a 'sandbox' challenge.  I have found out this means you set your own agenda.
I got the information from some of the guys and from the fb page as I rudely missed the introductory lecture.

There will be a course to navigate however I see fit.


I decided to make a wheeled or tracked vehicle that would follow a line and not crash into a wall (one of the lines goes into a wall). 
I wanted to keep the robot fairly simple and my personal goals are:

1: learn how to connect the various components (power supply, motors, drivers, sensors, controllersetc
2: learn some programming
3: design a power distribution circuit (I have read that these things are not the sort of things you just plug in and go.)

Depending on how this goes I will make the decision to increase the complexity later on. A couple of ideas are to make a tilt and pan mount for the ultrasonic sensor and to install the radio beacon things which may help to determine whether or not the robot knows it is at the finish.  If I could also then make it do something to signal it thinks it is at the finish that would be cool.

The beginning

I've created this blog to document the project Ihave undertaken with the UoM Robotics Society.
I figured that supplementing a mechanical engineering degree with some practical electronics will improve my skill set and make me more employable.

Previous experience with robotics and electronics is non existent.  2 weeks before introducing myself at the freshers fair I had not heard of raspberry pi, arduino, python and the most complicated electronics I had seen was replacing a potentiometer in a graco paint sprayer in 1998.

It's safe to say I am starting from scratch.

This blog is half for others to read and half for me to write ideas down so I don't forget.