behavior programming. structured programming a series of if-thens easy to get started in and hardly...
TRANSCRIPT
Structured Programming
• A series of if-thens
• Easy to get started in and hardly requires any thought or design beforehand
• But the code ends up as spaghetti code
MMN Lab.
Behavior programming
• Requires a little more planning before coding
• Each behavior is nicely encapsulated within an easy to understand structure
• Very easy to add or remove specific behaviors
MMN Lab.
Behavior Interface
• API– boolean takeControl()
• Returns a boolean value to indicate if this behavior should become active
– void action()• Initiates an action when the behavior becomes acti
ve
– void suppress()• Immediately terminate the code running in the acti
on() method
MMN Lab.
Arbitrator
• Constructor– public Arbitrator(Behavior [] behaviors)
• Higher index has the higher priority
• Method:– public void start();
MMN Lab.
Lab6
• Based on the sample code, design the following behaviors with proper priorities
• DriveForward (included in sample code)• HitWall (included in sample code)• Turn 360 degree by triggering ultrasonic sensor• Play music by triggering sound sensor• DoStop (included in sample code)
MMN Lab.
Low
High
Priorit
y