how to control a robot
DESCRIPTION
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. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/1.jpg)
How to Control a RobotKickoff 2011
![Page 2: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/2.jpg)
Why, How, Where?• Sense, think, act• Robot, laptop,
your brainGame Robot Human
Game State
Score
External Sensors
Internal Sensors
Robot’s Actions
Robot’s Software
Human Senses
Drivers Brain
User Interface
![Page 3: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/3.jpg)
Moving in a Circlepublic void UserControlledCode() { while (true) { if (robot.isAutonomous == false) { lock (studentLock) { if (true) { //Ignore
leftMotor.motorSpeed = 100; rightMotor.motorSpeed = -50;}
Robot’s Actions
Robot’s Software
![Page 4: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/4.jpg)
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
![Page 5: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/5.jpg)
Avoiding ObstaclesButton = new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO4, true, Port.ResistorMode.PullUp);
if (Button.Read()) { leftMotor.motorSpeed = -60; rightMotor.motorSpeed = -30; Thread.Sleep(1000);
}
![Page 6: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/6.jpg)
More Avoiding Obstacles
External Sensors
Robot’s Actions
Robot’s Software
![Page 7: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/7.jpg)
Program Flow• Decision• Consequences
Should I fire the balls?
True
Fire the Balls
More Code
Code
False
Should I fire the balls?
True
Fire the Balls
More Code
Code
False
Reload the Shooter
![Page 8: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/8.jpg)
Program Flowif (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
![Page 9: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/9.jpg)
Tank Drive//-100<=motorSpeed<=100//0<=Joystick values<=255leftMotor.motorSpeed = ((double)(robot.UIAnalogVals[1] - 128) * 100 / (double)128);
rightMotor.motorSpeed = ((double)(robot.UIAnalogVals[3] - 128) * 100 / (double)128);
![Page 10: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/10.jpg)
More Tank Drive
External Sensors
Robot’s Actions
Robot’s Software
Human Senses
Drivers Brain
User Interface
![Page 11: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/11.jpg)
Using ObjectsCat john = new Cat(10);int johnsMass = john.Eat(5);john.Purr();john.name = "Johnny";john.name = "John";Console.WriteLine(john.name);Console.WriteLine(johnsMass);
![Page 12: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/12.jpg)
More Objects• To create: new Type(arguments, ...);
• Field or Property: variableName.member
• Methods: variableName.member(argument,...)
![Page 13: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/13.jpg)
Robotic Objects• Declare Objects herepublic class StudentCode { // Variables private Robot robot; private SimpleMotorController rightMotor; private InputPort Button;
//More code
![Page 14: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/14.jpg)
More Robotic Objects• Instantiate Objects herepublic 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;
![Page 15: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/15.jpg)
Arrays• To Create: int[] myArray = new int[5];
• To access elements: variableName[index];
• Size: myArray.Length• myArray[0] = 12;• Arrays are 0 indexed
12
-34
7
0
3
myArray[]
myArray[0]
myArray[1]
myArray[2]
myArray[3]
myArray[4]
![Page 16: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/16.jpg)
Relational and Equality Operators
Equality x == y
Inequality x != y
Less than x < y
Less than or equal to
x <= y
Greater than x > y
Greater than or equal to
x >= y
• Turn numbers into booleans
![Page 17: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/17.jpg)
Boolean Operators
Exercise:
(!(12-3 > 8) && (3*5 == 15)) || ( !(17 < 18) || true)
if ( (time <= 30) && !(mode == 2) ){ driveForward();}
And true && trueOr true || falseNot !true
![Page 18: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/18.jpg)
Tracing a Polygonint i = 0;while (i < 5) { leftMotor.motorSpeed = 50; rightMotor.motorSpeed = 50; Thread.Sleep(1000); leftMotor.motorSpeed = -50; Thread.Sleep(500);i++;
}
![Page 19: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/19.jpg)
Tracing a Polygonfor (int i = 0; i < 5; i++) { leftMotor.motorSpeed = 50; rightMotor.motorSpeed = 50; Thread.Sleep(1000); leftMotor.motorSpeed = -50; Thread.Sleep(500);
}
![Page 20: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/20.jpg)
Loopsinitializewhile (condition) {bodypostBody
}
for (initialize; condition; postbody) {body
}
![Page 21: How to Control a Robot](https://reader036.vdocuments.us/reader036/viewer/2022081422/56816181550346895dd112ea/html5/thumbnails/21.jpg)
User Controlled Codepublic 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.
}}
}