lego robots and software design - the university of western australia

31
Lego Robots and Software Design CITS1220 Software Engineering

Upload: others

Post on 12-Sep-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lego Robots and Software Design - The University of Western Australia

Lego Robots and Software Design

CITS1220 Software Engineering

Page 2: Lego Robots and Software Design - The University of Western Australia

2

Lecture Overview 1.  Designing NXT Robots 2.  NXT Hardware 3.  Sensors and Actuator API 4.  The Behaviour Interface

Page 3: Lego Robots and Software Design - The University of Western Australia

3

Software Design is a problem-solving process whose

objective is to find and describe a way  To implement the system’s functional

requirements...  While respecting the constraints imposed by

the quality, platform and process requirements, including the budget

 And while adhering to general principles of good quality

Page 4: Lego Robots and Software Design - The University of Western Australia

4

Lecture Overview 1.  Designing NXT Robots 2.  NXT Hardware 3.  Lejos Java API 4.  The Behaviour Interface

Page 5: Lego Robots and Software Design - The University of Western Australia

5

 From the Czech word:

robota  Slavery, Drugery, Servitude –

Forced Labour

Lego NXT: by Ro Mathew

Page 6: Lego Robots and Software Design - The University of Western Australia

6

Robot Sensors:

  Provide information for the robot to examine its environment.

Page 7: Lego Robots and Software Design - The University of Western Australia

7

Robot Sound:

Page 8: Lego Robots and Software Design - The University of Western Australia

8

Robot Touch:

Page 9: Lego Robots and Software Design - The University of Western Australia

9

Robot Vision - Colour:

Page 10: Lego Robots and Software Design - The University of Western Australia

10

Robot Vision – Distance:

Page 11: Lego Robots and Software Design - The University of Western Australia

11

Robot Peripherals:

  Allows the robot to change its environment.

Page 12: Lego Robots and Software Design - The University of Western Australia

12

screen speakers

Robot Peripherals:

Page 13: Lego Robots and Software Design - The University of Western Australia

13

Robot Controller:

  Acts as the brain for the robot: Coordinates Devices

Page 14: Lego Robots and Software Design - The University of Western Australia

14

ROBOT CONTROLLER

Connect to our computer

Store programs and data

Connect to our sensors and motors

Retrieve information and provide power

Run programs and display information

Page 15: Lego Robots and Software Design - The University of Western Australia

15

Robot Motion System:

  Acts as the muscles for the robot allows physical movement

Page 16: Lego Robots and Software Design - The University of Western Australia

16

The more sensors, the better the robot is able to interact with the environment.

 Motors  Gears and Axles

Robot Motion:

Page 17: Lego Robots and Software Design - The University of Western Australia

17

Robot System:

  Incorporates sensors, peripherals, motion and power systems

Page 18: Lego Robots and Software Design - The University of Western Australia

18

Robot System:

Page 19: Lego Robots and Software Design - The University of Western Australia

19

For Building Instructions see CITS12220 Resources web page Components   Basic NXT Driving Base

Motor Module Sound Sensor Module Touch Sensor Module Ultrasonic Sensor Module

Models   Scorpion

TriBot Alpha Rex humanoid

Page 20: Lego Robots and Software Design - The University of Western Australia

20

Lego RCX

Page 21: Lego Robots and Software Design - The University of Western Australia

21

Lecture Overview 1.  Designing NXT Robots 2.  NXT Hardware 3.  Lejos Java API 4.  The Behaviour Interface

Page 22: Lego Robots and Software Design - The University of Western Australia

22

Cockroach Robot import lejos.nxt.*; class Cockroach { public static void main(String [] args) { LightSensor ls = new LightSensor(SensorPort.S2); Motor.B.forward(); Motor.C.forward(); LCD.drawString("Too much light",3,4); LCD.refresh(); while (ls.readValue() > 55) { //keep moving forward until dark is found } LCD.drawString("That’s better",3,4); LCD.refresh(); Motor.B.stop(); Motor.C.stop(); } }

Page 23: Lego Robots and Software Design - The University of Western Australia

23

Lecture Overview 1.  Designing NXT Robots 2.  NXT Hardware 3.  Lejos Java API 4.  Lejos Behaviour Interface

see handout: Max Lego NXT, Chapter 18

Page 24: Lego Robots and Software Design - The University of Western Australia

24

package lejos.subsumption;

public interface Behavior {

public boolean takeControl();   Trigger condition for invoking this behaviour

public void action();   Start a behaviour (eg. move forward)   Actions must return quickly (so that Arbitrator can

continue checking takeControl)

public void suppress();   Terminate this behaviour (eg. Stop a motor)   Also update any data if needed }

Page 25: Lego Robots and Software Design - The University of Western Australia

25

Arbitrator public Arbitrator(Behaviour [] behaviours);   Create an arbitrator with an array of behaviours:

highest array index has highest priority

public void start()   Starts the arbitration system:

 call takeControl() for each behaviour starting with the highest priority behaviour, until true

 Execute the suppress() method of the current (lower priority) behaviour then

 Execute the action() method of the chosen behaviour

Page 26: Lego Robots and Software Design - The University of Western Australia

26

package lejos.subsumption;

public class DriFord implements Behavior {

public boolean takeControl() { return true; }

public void action(); { Motor.A.forward(); Motor.C.forward(); } public void suppress(); Motor.A.stop(); Motor.C.stop(); }

Page 27: Lego Robots and Software Design - The University of Western Australia

27

package lejos.subsumption;

public class HitWall implements Behavior { public TouchSensor touch = new

TouchSensor(SensorPort.S!);

public boolean takeControl() { return touch.isPressed(); }

public void suppress(); Motor.A.stop(); Motor.C.stop(); }

Page 28: Lego Robots and Software Design - The University of Western Australia

public void action(); { Motor.A.backward(); Motor.C.backward();

try{Thread.sleep(1000);} catch(Exception e) {} // Rotate by causing only one wheel to stop: Motor.A.stop(); try{Thread.sleep(300);} catch(Exception e) {} Motor.C.stop(); }

28

Page 29: Lego Robots and Software Design - The University of Western Australia

  import lejos.subsumption.*; public class BumperCar { public static void main(String [] args)

{ Behavior b1 = new DriFord(); Behavior b2 = new HitWall(); Behavior [] bArray = {b1, b2}; Arbitrator arby = new Arbitrator(bArray);

arby.start(); } }

29

Page 30: Lego Robots and Software Design - The University of Western Australia

30

Subsumption

Page 31: Lego Robots and Software Design - The University of Western Australia

31

Learn More …

 CITS1220 Resources web page  Lejos NXT API  Sample Programs

  See BumperCar example for behaviours  Lego RCX tutorial (for previous generation

hardware, but many parts still relevant)

  http://lejos.sourceforge.net/