to Main Page

Tutorial

MARS Setup on FlashDevelop

1. Download the latest release of FlashDevelop 3.0 from the website. Follow the installation instructions. Make sure you have the required Java version.

2. Download and extract the free Flex 3 SDK.

3. Download the latest release of the MARS Framework from the Downloads section of this site and extract it.

4. Open FlashDevelop 3.0 and create a new ActionScript project. You can do this from the Start Page. Name the project 'MARSTest', check the option 'Create directory for project'.

fig1

5. Copy the contents of the 'source' folder from the MARS Framework release which you extracted in step 3 to the project main folder.

6. Go to the Project > Properties menu and specify the name of the output file, for example 'MARSTest'.

fig2

7. Go to Tools > Program Settings menu (or press F10) and in the AS3Context tab specify the location of the Flex 3 SDK that you extreacted in step 2.

fig3

8. Create a new class 'MARSTest.as' and paste the code on the bottom of the page into it.

9. Right-click the file you just created and mark it as the main project file by selecting 'Always Compile' option.

10. Build the project and run.

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