View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide

WifiBotST Framework Description

A WifiBotST robot is an instance of class WifiBot or one of its subclasses. A robot is charactererized by a body and a behavior. In the following, we introduce each of these part and show how to run a robot. We illustrate the description with simple examples and provide the corresponding code.

Getting Started

In a workspace run the following example.
myMission := WifiBotMission new.
arena := ArenaForMorphicWifiBot new.
arena mission: myMission.
arena width: 1000; height: 600.
arena openInWorld.
obstacle := RectangleMorph new.
obstacle width: 100.
obstacle height: 50.
obstacle color: Color black.
arena addMorph: obstacle.
obstacle position: 400@300.
bot1 := ObstacleAvoiderWifiBot morphic.
bot1 body openIn: arena.
bot1 body positionInArena: 400@200.
bot1 forwardSpeed: 40.
bot1 rotationSpeed: 20.
bot2 := ObstacleAvoiderWifiBot morphic.
bot2 body openIn: arena.
bot2 body positionInArena: 400@500.
bot2 forwardSpeed: 30.
myMission start.

Once you're done, evaluate the following expression within the same workspace
myMission start.

Missions and Arena

A mission is a description of a setup to reach some goal. A mission allows driving a set of robots.
An arena is a graphical object (a morph) that can contain morphic robot bodies or other morphs (e.g. obstacles). It can be open (robots wrap when they go beyond a border) or closed (robots can't go beyond edges).

Below an example to run in a workspace. Evaluate each paragraph separately and watch what happens.
mission := WifiBotMission new.
arena := ArenaForMorphicWifiBot new.
arena mission: mission.
arena openInHand.

bot := ObstacleAvoiderWifiBot morphic.
bot forwardSpeed: 20.
botBody := bot body.
botBody openInHand.

Now you can drop the robot morph inside the arena.

mission start.

The robot starts moving.

botBody showSensors.

You can see the infrared sensors in the front of the robot morph.

arena close.

robot rotate each time it reaches a border"

arena open.

"robots wrap around the arena"

mission stop.

Graphical vs. Physical Bodies

The robot body can be either a graphical body driven using an instance of MorphicWifiBotBody or a physical body driven through an instance of RealWifiBotBody. The WifiBot class provides class methods to build both kinds of robots. We give examples with the ObstacleAvoiderWifiBot class.
robot := ObstacleAvoiderWifiBot morphic.

robot := ObstacleAvoiderWifiBot bodyIP: #(192 168 0 130).

Running a robot

To run the robot, it should be sent the step message in a loop, often in a dedicated process as shown in the code snippet below with an obstacle avoider robot.
| bot runFlag delay |
bot := ObstacleAvoiderWifiBot morphic.
bot body 
  positionInArena: 500@400.
bot forwardSpeed: 30.
runFlag := true.
delay := Delay forMilliseconds: 500.
[[runFlag] whileTrue: [
  bot step.
  delay wait]] fork.
PopUpMenu inform: 'click to stop the robot'.
runFlag := false.
bot body delete

A better approach is to rely on the WifiBotMission class as povided in the following code. A mission provides several utilities for driving multiple robots.
| bot mission |
bot := ObstacleAvoiderWifiBot morphic.
bot body 
  positionInArena: 500@400.
bot forwardSpeed: 30.
mission := WifiBotMission bot: bot.
mission start.
PopUpMenu inform: 'click to terminate the mission'.
mission stop.
bot body delete

Implementing a robot behavior

WifiBot class is the root class of robots. It is an abstract class that provides method step that should be overriden in subclasses in order to define the robot behavior. An example of such overriding is done in class SimpleReactiveWifiBot as following:
  self body updateSensorValues.
  self computeActuatorValues.
  self body commitActuatorValues

First robot sensor values are updated. Then, new actuator values are computed. Last, new actuator values are commited which result in sending them to the actuators in order to actually perform the desired action.

In order to implement a simple reactive robot that performs some task, method computeActuatorValues need to be overriden in a subclass. As an example to implement an obstacle avoider robot similar to the one provided by the ObstacleAvoiderWifiBot class, one must implement a subclass with the following method.

  "Move forward or turn to avoid obstacles"
  self body distanceToRightObstacles < 50
    ifTrue: [^ self body forwardSpeed: 0 rotationSpeed: -30].
  self body distanceToLeftObstacles < 50
    ifTrue: [^ self body forwardSpeed: 0 rotationSpeed: 30].
  super computeActuatorValues.