GlynM
Posts: 4
Joined: Sat Feb 02, 2013 9:37 pm
Location: Surrey, UK

First Atempt at building a robot

Sat Feb 02, 2013 11:06 pm

I have been lurking in these forums for a while but this is my first post.

Having started out with the Raspberry Pi driving LEDs then an LCD display I decided to have a go at building a robot.

So this is my first attempt:

Looking at Front Left
Image

Looking at Rear Right
Image

This is using a chassis from a Heng Long Tiger Tank that was going spare after an upgrade.
It has a Raspberry Pi driving two pairs of L298 motor controllers which have been paralleled up to achieve the necessary current drive to each motor. These are being driven by one port on a MCP23017 GPIO expander.

Probably somewhat over the top I have ended up using using 10 IR proximity detectors, two looking forwards, two looking back, one looking out each side and four more diagonal front and back, on posts, which were a development to replace front and rear micro switch bumpers that were getting destroyed by the impact forces.

There are also two line following detectors that are looking at the tracks and are used to detect a single white painted link on each side. These are to detect a stalled track and allow an indication of the distance traveled. While it probably will not work in a dirty environment they are fine inside my house. These, along with the proximity detectors are fed as inputs to another 3 MCP23017 ports.

I also have a HMC5883L digital compass raised up on a post at the back to keep it away from interference from the motors and being screened by metal objects like the battery. There is also a 2 line, 16 character I2C LCD display.

Currently it is just running a simple roving and collision avoidance program. It is a fairly simple state machine where the motor drives are derived from the states of the IR detectors. The front & rear horizontal detectors drive left or right turns as do the side detectors which are to make sure there is space to perform a turn. The front & rear bumper detectors, plus the track stall timeouts just put the machine into the reverse direction.

The compass is currently just being used to put the bearing, in degrees, onto the display which is also being used to show the system status to help with debugging.

This all seems to be working well although it does occasionally gets stuck underneath something that is above the detectors but lower that the height of the robot :? .

I think my next challenge is improve it from being a random wanderer into being a better explorer and record directions and distance traveled with a view to generating a map of its current environment.

I am using RiscOs on the RPI so that I could program it in BBC Basic, which is something I used a lot in the 1980s ;) and meant I did not have to learn another programing language . I started off using a downloaded GPIO module but this was bit orientated and causing a lot of performance overhead to drive the byte wise IO mapping I am using. As I also had to master I2C for the compass and display I ended up writing my own GPIO interface.

The only thing I have had to import is an ATN2 function, needed to convert the the compass output to degrees, which is not available in BBC Basic. Acknowledgements for this go to Richard Russel and the Windows BBC Basic forum.

I certainly could not have got this far without the help of this forum and the RiscOc open forum. So lots of thanks.

I hope this makes sense and would welcome any comments.

Glyn

User avatar
tonyhughes
Posts: 951
Joined: Wed Dec 26, 2012 3:46 am

Re: First Atempt at building a robot

Sun Feb 03, 2013 3:20 am

So cool. I want to do something similar with my 6 year old son to teach him about robotics and programming.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: First Atempt at building a robot

Sun Feb 03, 2013 3:33 am

wow - good job.

Whats it like on slopes?

Maybe there is a way to optically sense the gaps between the track links?

Steve Drain
Posts: 99
Joined: Tue Oct 30, 2012 2:08 pm
Location: Exeter UK

Re: First Atempt at building a robot

Sun Feb 03, 2013 8:28 pm

GlynM wrote:These are being driven by one port on a MCP23017 GPIO expander...
I started off using a downloaded GPIO module but this was bit orientated and causing a lot of performance overhead to drive the byte wise IO mapping I am using. As I also had to master I2C for the compass and display I ended up writing my own GPIO interface.

The only thing I have had to import is an ATN2 function, needed to convert the the compass output to degrees, which is not available in BBC Basic. Acknowledgements for this go to Richard Russel and the Windows BBC Basic forum.
That's wonderful. It takes me back to teaching in the 90s, with a classroom full of year 8s, BBC Bs and Lego buggies with microswitches and photo cells. The programs were in Control Logo and the fastest groups had a buggy that would run on a tabletop without falling off and back away from obstacles. Even the slowest could drive a buggy in a desired pattern. That is what I would be delighted to see the Pi stimulate in schools again.

It's a bit late now, but I wrote my MCPIO module to provide just the 8-bit interface to the MCP23017 you may have been looking for.

Would this have been the ATN2 you were also looking for?

Code: Select all

DEFFNATN2(y,x)
 IF x=0 THEN =SGNy*PI/2
 IF LOGABSy-LOGABSx>38 THEN =SGNy*PI/2
 IF x>0 THEN =ATNy/x
 IF y>0 THEN =ATNy/x+PI
=ATNy/x-PI
You should find a lot of help with RISC OS BASIC on comp.sys.acorn.programmer or in the ROOL forums. I might also be able to help directly.

GlynM
Posts: 4
Joined: Sat Feb 02, 2013 9:37 pm
Location: Surrey, UK

Re: First Atempt at building a robot

Sun Feb 03, 2013 9:23 pm

pygmy_giant wrote:wow - good job.

Whats it like on slopes?

Maybe there is a way to optically sense the gaps between the track links?
I have not tried it on a slope but the original Heng Long Tiger is quoted as being to do a 30 degree slope. I have seen it climb over a couple of shoes :? .

Looking for the track link gaps sounds like a good idea. I will have to give it a try.

Thanks,

Glyn

GlynM
Posts: 4
Joined: Sat Feb 02, 2013 9:37 pm
Location: Surrey, UK

Re: First Atempt at building a robot

Sun Feb 03, 2013 9:42 pm

Steve Drain wrote: Would this have been the ATN2 you were also looking for?

Code: Select all

DEFFNATN2(y,x)
 IF x=0 THEN =SGNy*PI/2
 IF LOGABSy-LOGABSx>38 THEN =SGNy*PI/2
 IF x>0 THEN =ATNy/x
 IF y>0 THEN =ATNy/x+PI
=ATNy/x-PI
Thanks for the encouragement and references Steve.

I used this for the ATN2 function, very similar to yours, which I found here:

http://bb4w.wikispaces.com/The+ATAN2+function

Code: Select all

DEF FNatan2(y,x) : ON ERROR LOCAL = SGN(y)*PI/2
      IF x>0 THEN = ATN(y/x) ELSE IF y>0 THEN = ATN(y/x)+PI ELSE = ATN(y/x)-PI
Research suggested that this would cope with out of range errors as well as the divide by 0 error.

I modified it a little bit to preserve and restore my original error handler:

Code: Select all

DEF FNatan2(y%,x%)
LOCAL ERROR
ON ERROR LOCAL : =SGN(y%)*PI/2
IF x%>0 THEN
  =ATN(y%/x%)
ELSE IF y%>0 THEN
  =ATN(y%/x%)+PI
ELSE
  =ATN(y%/x%)-PI
Many thanks,

Glyn

Steve Drain
Posts: 99
Joined: Tue Oct 30, 2012 2:08 pm
Location: Exeter UK

Re: First Atempt at building a robot

Mon Feb 04, 2013 11:29 am

GlynM wrote:

Code: Select all

DEF FNatan2(y%,x%)
LOCAL ERROR
ON ERROR LOCAL : =SGN(y%)*PI/2
IF x%>0 THEN
  =ATN(y%/x%)
ELSE IF y%>0 THEN
  =ATN(y%/x%)+PI
ELSE
  =ATN(y%/x%)-PI
That looks like a better bet than mine. I glanced at the BB4W version, but was concerned about its missing LOCAL ERROR, which may not actually be needed in that variant of the language.

I expect your y% x% values are port values, but for anyone who is going to use this in general, I think the parameters have to be floats.

GlynM
Posts: 4
Joined: Sat Feb 02, 2013 9:37 pm
Location: Surrey, UK

Re: First Atempt at building a robot

Mon Feb 04, 2013 4:40 pm

Steve Drain wrote: I expect your y% x% values are port values, but for anyone who is going to use this in general, I think the parameters have to be floats.
Agreed. I went to integers because what comes out of the compass module is 16bit, 2s compliment, numbers which I convert to signed integers but you are right that for general use they should be floats.

Glyn

Steve Drain
Posts: 99
Joined: Tue Oct 30, 2012 2:08 pm
Location: Exeter UK

Re: First Atempt at building a robot

Wed Feb 06, 2013 11:59 am

As a result of this thread I have written ATN2 as an alternative keyword in my Basalt BASIC extension module. It is only about 30% faster than the FN, because most time is taken using the same BASIC module routines, but it is very much neater. I have not upload this version, but I can send it to anyone to try.

While testing, I realised that when the error handler is invoked the FN is vastly slower, so the routine I offered that checks for out of range values is probably better after all. :)

photomankc
Posts: 80
Joined: Fri Aug 24, 2012 12:58 pm

Re: First Atempt at building a robot

Wed Feb 06, 2013 3:40 pm

Your first attempt is going quite well! Hope to have a submission of my own for this summer. Keep us updated with your progress. :D

User avatar
entozoon
Posts: 25
Joined: Sun Feb 12, 2012 7:27 pm
Location: Sheffield, UK
Contact: Website

Re: First Atempt at building a robot

Wed May 21, 2014 12:46 pm

Thank you for such an informative post! I never knew you could pair up L298 controllers to handle higher powered motors :)
I think I'm going to try a set of relays myself though.. and build some DIY tank tracks from bike chains

southpaw
Posts: 52
Joined: Wed Nov 30, 2011 2:23 pm

Re: First Atempt at building a robot

Wed May 21, 2014 5:11 pm

good job glyn, an improvement might be pan+tilt proximity sensors, could cut the 10 down to 2 that way, nevertheless, nice project

Return to “Automation, sensing and robotics”