1 / 21

How to Control a Robot

How to Control a Robot. Kickoff 2011. Why, How, Where?. Sense, think, act Robot, laptop, your brain. Game. Robot. Human. Internal Sensors. Game State. External Sensors. Robot’s Software. Robot’s Actions. Score. Human Senses. Drivers Brain. User Interface. Moving in a Circle.

moeshe
Download Presentation

How to Control a Robot

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. How to Control a Robot Kickoff 2011

  2. Why, How, Where? • Sense, think, act • Robot, laptop, your brain Game Robot Human Internal Sensors Game State External Sensors Robot’s Software Robot’s Actions Score Human Senses Drivers Brain User Interface

  3. Moving in a Circle public void UserControlledCode() { while (true) { if (robot.isAutonomous == false) { lock (studentLock) { if (true) { //Ignore leftMotor.motorSpeed = 100; rightMotor.motorSpeed = -50; } Robot’s Software Robot’s Actions

  4. Types and Variables • Declare : double x; • Assign : x = 3.5; • Use : int y = x; z = 8 - y + x; x = x + y; • = is assignment (not equals) • C#: Value type vs. Reference type • C# is case sensitive

  5. Avoiding Obstacles Button = new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO4, true, Port.ResistorMode.PullUp); if (Button.Read()) { leftMotor.motorSpeed = -60; rightMotor.motorSpeed = -30; Thread.Sleep(1000); }

  6. More Avoiding Obstacles External Sensors Robot’s Software Robot’s Actions

  7. Program Flow • Decision • Consequences Code Code Should I fire the balls? Should I fire the balls? True True False False Fire the Balls Reload the Shooter Fire the Balls More Code More Code

  8. Program Flow if (isFiring) {shooter.shoot()} if (isFiring) {shooter.shoot()} else {shooter.reload()} if (condition1) {consequent1} else if (condition2) {cosequent2} else {alternative} • Use to change behavior depending on input

  9. Tank Drive //-100<=motorSpeed<=100 //0<=Joystick values<=255 leftMotor.motorSpeed = ((double)(robot.UIAnalogVals[1] - 128) * 100 / (double)128); rightMotor.motorSpeed = ((double)(robot.UIAnalogVals[3] - 128) * 100 / (double)128);

  10. More Tank Drive External Sensors Robot’s Software Robot’s Actions Human Senses Drivers Brain User Interface

  11. Using Objects Cat john = new Cat(10); intjohnsMass = john.Eat(5); john.Purr(); john.name = "Johnny"; john.name = "John"; Console.WriteLine(john.name); Console.WriteLine(johnsMass);

  12. More Objects • To create: new Type(arguments, ...); • Field or Property: variableName.member • Methods: variableName.member(argument,...)

  13. Robotic Objects • Declare Objects here public class StudentCode { // Variables private Robot robot; private SimpleMotorControllerrightMotor; private InputPort Button; //More code

  14. More Robotic Objects • Instantiate Objects here public StudentCode(Robot robot) { Button = new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO4, true, Port.ResistorMode.PullUp); leftMotor = new SimpleMotorController(robot, "COM1", 13); rightMotor.motorBrake = 0;

  15. Arrays myArray[] • To Create: int[] myArray = new int[5]; • To access elements: variableName[index]; • Size: myArray.Length • myArray[0] = 12; • Arrays are 0 indexed myArray[0] myArray[1] myArray[2] myArray[3] myArray[4]

  16. Relational and Equality Operators • Turn numbers into booleans

  17. Boolean Operators Exercise: (!(12-3 > 8) && (3*5 == 15)) || ( !(17 < 18) || true) if ( (time <= 30)  &&  !(mode == 2) ) { driveForward(); }

  18. Tracing a Polygon inti = 0; while (i < 5) { leftMotor.motorSpeed = 50; rightMotor.motorSpeed = 50; Thread.Sleep(1000); leftMotor.motorSpeed = -50; Thread.Sleep(500); i++; }

  19. Tracing a Polygon for (inti = 0; i < 5; i++) { leftMotor.motorSpeed = 50; rightMotor.motorSpeed = 50; Thread.Sleep(1000); leftMotor.motorSpeed = -50; Thread.Sleep(500); }

  20. Loops initialize while (condition) { body postBody } for (initialize; condition; postbody) { body }

  21. User Controlled Code public void UserControlledCode() { if (robot.isAutonomous == false) { lock (studentLock) { //All code for the teleoperated period goes here. It is in an infinite while loop so it is continuously executed. } } }

More Related