Thursday, 7 January 2016

Robots behaving...

Reblogged from: http://scott-ltattempts.blogspot.co.uk/2011/05/robot-behaviours.html


Behaviour based robots was used in the teaching as way of getting the students to think out AI a little deeper and in particular Do we need Human Level intelligence? or rather Do we always need to aim for Human Level Intelligence?

Lego Mindstorms robot are a good vehicle for students to start trying out idea around behaviour-based robotics. They are inexpensive, programmable and with the LeJOS software installed on them; have behaviours built into the programming which is done in Java.

A good example to use comes from Bagnall's book (B Bagnall (2002) Core Lego Mindstorms: 

Programming the RCX in Java , ISBN: 978-0130093646)


code 1: HitWall

//Taken from Bagnall (2002)
import josx.robotics.*;
import josx.platform.rcx.*;
public class HitWall implements Behavior
{
public boolean takeControl()
{
return Sensor.S2.readBooleanValue();
}
public void suppress()
{
Motor.A.stop();
Motor.C.stop();
}
public void action()
{
Motor.A.backward();
Motor.C.backward();
try{Thread.sleep(1000);}catch(Exception e){}
Motor.A.stop();
try{Thread.sleep(300);}catch(Exception e){}
Motor.C.stop();
}
}

Code 2: DriveForward

//Taken from Bagnall (2002)

import josx.robotics.*;
import josx.platform.rcx.*;
public class DriveForward implements Behavior
{
public boolean takeControl()
{
return true;
}
public void suppress()
{
Motor.A.stop();
Motor.C.stop();
}
public void action()
{
Motor.A.forward();
Motor.C.forward();
}
}



Code 3: Bumper Car

import josx.robotics.*;
public class BumperCar
{
public static void main(String [] args)
{
Behavior b1=new DriveForward();
Behavior b2=new HitWall();
Behavior [] bArray ={b1,b2};
Arbitrator arby=new Arbitrator(bArray);
arby.start();
}
}

All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with.

No comments:

Post a Comment

Remote Data Logging with V1 Microbit

In an earlier post  https://robotsandphysicalcomputing.blogspot.com/2024/08/microbit-v1-datalogging.html  a single microbit was used to log ...