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'.
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'.
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.
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-
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);
-
}
-
}
-
}
