Tutorial
MARS Setup on Adobe® Flex® Builder™ 3
1. Download the trial version of Adobe® Flex® Builder™ 3 from the Adobe® website.
2. Download the latest release of the MARS Framework from the Downloads section of this site and extract it.
3. Open Flex Builder 3 and create a new ActionScript project. You can do this from the file->new menu, or by right-clicking in the navigator panel.
4. Name the project. For the tutorial we'll name it "MARSTest". The name of the project will also be the name of your main application class. Leave the "Use default location" checkbox checked.
5. Click "Next" to go to the build paths screen of the new project wizard. Make sure the "Source path" tab is selected. Then press the "Add Folder" button, click "Browse", and navigate to the location of the MARS 'source' folder that you have extracted in the step 2. Click the "OK" button and the path to the MARS source will now be displayed in the list of additional source folders.
6. Click the "Finish" button and you're done. The source code will appear under your project in the navigator panel. The main application file can be altered as the code shown below. It's a simple example of using MARS, creating a simple robot with no sensors.
NOTE: to prevent the Flex Builder from generating the HTML wrapper file, right click the MARSTest project in the navigator panel and click 'properties'. Click the "ActionScript Compiler" button on the right and uncheck the "Generate HTML wrapper file" checkbox. Click the"OK" button and confirm the warning.
-
package {
-
import flash.display.Sprite;
-
-
import org.MARS.dynamics.enum.Simplification;
-
import org.MARS.robot.Robot;
-
import org.MARS.robot.control.BrainOne;
-
import org.MARS.robot.locomotion.DifferentialSteering;
-
import org.MARS.simulation.Environment;
-
import org.MARS.simulation.Simulation;
-
import org.MARS.util.IOUtil;
-
import org.MARS.util.LocomotionUtil;
-
import org.MARS.util.MathUtil;
-
import org.MARS.view.shape.Rectangle;
-
-
// Set the stage dimensions and color here
-
[SWF(width="800", height="600", backgroundColor="#333333")]
-
public class MARSTest extends Sprite
-
{
-
public function MARSTest()
-
{
-
//set the framerate
-
stage.frameRate = IOUtil.FRAMERATE;
-
-
//get Simulation and Environment instances
-
var s:Simulation = Simulation.getInstance();
-
var e:Environment = Environment.getInstance();
-
-
//define table shape
-
e.addTableShape(new Rectangle(100, 100, 600, 400));
-
-
//robot parts
-
var wheels:Array = LocomotionUtil.createTwoWheelSystem(7, 2, 20);
-
var brain:BrainOne = new BrainOne(0.2, 0.3);
-
var locomotion:DifferentialSteering = new DifferentialSteering(wheels);
-
var robotShape:Rectangle = new Rectangle(-20, -20, 40, 40, 0, null, 0x00FF00, 0.7, 0x000000, 1, 3);
-
-
//connect brain to locomotion
-
brain.getPort(2).connectPorts(locomotion.getPort(0));
-
brain.getPort(3).connectPorts(locomotion.getPort(1));
-
brain.getPort(4).connectPorts(locomotion.getPort(2));
-
brain.getPort(5).connectPorts(locomotion.getPort(3));
-
-
//assemble the robot
-
var robot:Robot = new Robot(650, 300, MathUtil.degreesToRadians(180), robotShape, brain, locomotion, Simplification.AVERAGE_MASS);
-
-
robot.addToEnvironment();
-
-
//attach the simulation to stage and stay still until the start button is pressed
-
addChild(s);
-
s.useMouseDragger(true);
-
s.focusObject = robot;
-
s.still();
-
-
//add the output panel
-
IOUtil.createTextPanel(this);
-
}
-
}
-
}
