1 / 14

Behavior Programming

Behavior Programming. 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

chaeli
Télécharger la présentation

Behavior Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Behavior Programming

  2. 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.

  3. 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.

  4. The Behavior API • Only one interface and one class • Behavior interface • Arbitrator class MMN Lab.

  5. 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 active • void suppress() • Immediately terminate the code running in the action() method MMN Lab.

  6. Arbitrator • Constructor • public Arbitrator(Behavior [] behaviors) • Higher index has the higher priority • Method: • public void start(); MMN Lab.

  7. Coding Behaviors MMN Lab.

  8. Coding Behaviors cont’d MMN Lab.

  9. Coding Behaviors cont’d MMN Lab.

  10. Coding Behaviors cont’d • Add a new behavior MMN Lab.

  11. Coding Behaviors cont’d • Add the new behavior to the Arbitrator MMN Lab.

  12. Sensor Listener MMN Lab.

  13. 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) Low Priority High MMN Lab.

  14. Lab6 • Hint: • You can use SensorListener for more accurate sensor action • Add delay if the program starts in the unexpected way MMN Lab.

More Related