to Main Page

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.

fig1

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.

fig2

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.

fig3

PLAIN TEXT VIEW
  1. package {
  2.     import flash.display.Sprite;
  3.    
  4.     import org.MARS.dynamics.enum.Simplification;
  5.     import org.MARS.robot.Robot;
  6.     import org.MARS.robot.control.BrainOne;
  7.     import org.MARS.robot.locomotion.DifferentialSteering;
  8.     import org.MARS.simulation.Environment;
  9.     import org.MARS.simulation.Simulation;
  10.     import org.MARS.util.IOUtil;
  11.     import org.MARS.util.LocomotionUtil;
  12.     import org.MARS.util.MathUtil;
  13.     import org.MARS.view.shape.Rectangle;
  14.    
  15.     // Set the stage dimensions  and color here
  16.     [SWF(width="800", height="600", backgroundColor="#333333")]
  17.     public class MARSTest extends Sprite
  18.     {
  19.         public function MARSTest()
  20.         {
  21.             //set the framerate
  22.             stage.frameRate = IOUtil.FRAMERATE;
  23.            
  24.             //get Simulation and Environment instances
  25.             var s:Simulation = Simulation.getInstance();
  26.             var e:Environment = Environment.getInstance();
  27.            
  28.             //define table shape
  29.             e.addTableShape(new Rectangle(100, 100, 600, 400));
  30.            
  31.             //robot parts
  32.             var wheels:Array = LocomotionUtil.createTwoWheelSystem(7, 2, 20);
  33.             var brain:BrainOne = new BrainOne(0.2, 0.3);
  34.             var locomotion:DifferentialSteering = new DifferentialSteering(wheels);
  35.             var robotShape:Rectangle = new Rectangle(-20, -20, 40, 40, 0, null, 0x00FF00, 0.7, 0x000000, 1, 3);
  36.            
  37.             //connect brain to locomotion
  38.             brain.getPort(2).connectPorts(locomotion.getPort(0));
  39.             brain.getPort(3).connectPorts(locomotion.getPort(1));
  40.             brain.getPort(4).connectPorts(locomotion.getPort(2));
  41.             brain.getPort(5).connectPorts(locomotion.getPort(3));
  42.            
  43.             //assemble the robot
  44.             var robot:Robot = new Robot(650, 300, MathUtil.degreesToRadians(180), robotShape, brain, locomotion, Simplification.AVERAGE_MASS);
  45.            
  46.             robot.addToEnvironment();
  47.            
  48.             //attach the simulation to stage and stay still until the start button is pressed
  49.             addChild(s);
  50.             s.useMouseDragger(true);
  51.             s.focusObject = robot;
  52.             s.still();
  53.            
  54.             //add the output panel
  55.             IOUtil.createTextPanel(this);
  56.         }
  57.     }
  58. }