RobotC For Beginners Tyler Lutz and Keaton Bonds DRSS Enterprise.

Slides:



Advertisements
Similar presentations
While Loops and If-Else Structures
Advertisements

Jason Howard. Agenda I. How to download robotc II. What is tele-op used for? III. How to build a basic tele-op program IV. Getting the robot to drive.
Team 5220 Roboknights. Outline  Getting Started  Hardware Setup/Wiring  Software Setup/Pragmas  Programming with RobotC  Grammar/Syntax  Basic Statements.
Automation and Robotics
VEX and Robot C Chris Patterson Presented by Modified by J. Andazola.
Developed in collaboration with Introduction to Programming.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Autonomy using Encoders Intro to Robotics. Goal Our new task is to navigate a labyrinth. But this time we will NOT use motor commands in conjunction with.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Motor control drive in circles Pragmas configure motors Turning right in function of time Turning left in function of time Main program starts from here.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
RobotC Programming for LEGO Mindstorms NXT Carnegie Mellon Dacta Lego Timothy Friez Miha Štajdohar SOURCES:
CS 106 Introduction to Computer Science I 02 / 11 / 2008 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
Programming – Touch Sensors Intro to Robotics. The Limit Switch When designing robotic arms there is always the chance the arm will move too far up or.
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
Testbed: Exercises.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
1 CS 177 Week 5 Recitation Slides Loops. 2 Announcements Project 2 due next Thursday at 9PM. Exam 1 this evening (switch and loop not covered) Old exams.
Programming 101 The Common Palette Content provided by Connor Statham (6 th Grade Student) Formatting by Shannon Sieber.
Coding for the FIRST Tech Challenge: RobotC Presented by: Audrey Yeoh Acknowledgements: Team Unlimited FTC 0001.
Coding for the FIRST Tech Challenge: RobotC
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
Wall Encounter By Made easy by Dwayne Abuel.
Sentry System Multiple Sensors
A loop is a repetition control structure. body - statements to be repeated control statement - decides whether another repetition needs to be made leading.
Robotics NXT-G: variables, file Rotation sensor Lab: Use buttons to hit specific ball. Homework: Postings. Start planning mapping the room.
Variables and Functions ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
While and If-Else Loops ROBOTC Software. While Loops While loop is a structure within ROBOTC Allows a section of code to be repeated as long as a certain.
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
RobotC Remote Control. Learning Objectives: Focusing on Virtual World with Physical Examples Understand Real-Time Joystick Mapping Understand how to use.
Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.
Programming your Robot
BEGINNER FLL PROGRAMMING WORKSHOP BY DROIDS ROBOTICS & EV3LESSONS.
VEX and Robot C Chris Patterson Frisco ISD CTE Center Presented by.
Automation and Robotics.  First you select the platform type so that you can use Natural Language PLTW.
Vex Robotics program three: using motors and sensors together.
Programming Basics - RobotC Introduction to Robotics.
Decision Making: while loops and Boolean Logic. While Loops A while loop is a structure within ROBOTC which allows a section of code to be repeated as.
Python Programming Module 4 Sensors and Loops Python Programming, 2/e1.
Sensor Information: while loops and Boolean Logic.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
ROBOTC for CORTEX Teacher Training © 2011 Project Lead The Way, Inc. Automation and Robotics VEX.
Introduction to Programming in RobotC
Robotics Programming Using Shaft Encoders
Loop Structures.
Programming - Motion Intro to Robotics.
Movement using Shaft Encoders
Using Encoders to go Straight
Using variables, for..loop and functions to help organize your code
Automation and Robotics
While Loops and If-Else Structures
Loop Strategies Repetition Playbook.
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops and If-Else Structures
Programming - Buttons Intro to Robotics.
RobotC While loop When and how to use the while loop
if-else Structures Principles of Engineering
Robotics Programming Using Shaft Encoders
Programming - Buttons Intro to Robotics.
Robotics Programming Using Shaft Encoders
Remote Control For this activity we will use the Squarebot
While Loops and If-Else Structures
RobotC Programming for LEGO Mindstorms NXT
Robotics Programming Using Shaft Encoders
While Loops and If-Else Structures
While Loops And If-Else Structures
Presentation transcript:

RobotC For Beginners Tyler Lutz and Keaton Bonds DRSS Enterprise

Intro to the RobotC UI Text based Similar to C# or C++. Capitalization matters (eg. lower case “task”) When the program runs out of statements, the program ends. Automatically colors words it recognizes (eg. task will appear as task) Organize your code with comments so that you can understand what you coded later. “//” Makes the rest of the line a comment “/*” Starts a comment, that continues until you use “*/”

Hardware NXT brick Motor Servo Sensors Motor/Servo controllers

Pragma Configuration Tells the robot what motor controllers in what port. #pragma config(Hubs, S1, HTMotor, none, none, none) #pragma config(Sensor, S1,, sensorI2CMuxController) #pragma config(Motor, mtr_S1_C1_1, mL, tmotorTetrix, openLoop) #pragma config(Motor, mtr_S1_C1_2, mR, tmotorTetrix, openLoop, reversed)

Starting out To declare the start of your program, write: task main() { //Code goes here. } Recall that “//” indicates a comment. This is just for indication.

Starting out This code is telling the motor named ‘motorLeft’ to move at 100% power. motor[motorLeft] = 100; To go backwards, set the power to a This code is telling the motor named ‘motorLeft’ to move at 100% power. motor[motorLeft] = 100; Waits for a given amount of time wait1Msec(1000); Place the statements inside the task main() structure. task main(){ motor[motorLeft] = 100; motor[motorRight] = 100; wait1Msec(1000); }

Don’t forget: Semicolons end a statement in RobotC. “;” Brackets vs. Parenthesis. Brackets are used for differentiation between motors, servos, and sensors declared in pragma configuration, for example motor[motorLeft]; Parenthesis are used to indicate conditions for a function, such as wait1Msec(3000);

Practice Try to make a program drives the robot forwards for 1 second, then backwards for 4, then turns in any direction for 2 seconds. Hint: One motor forward, one motor backwards to turn. task main(){ motor[motorLeft] = 100; motor[motorRight] = 100; wait1Msec(1000); motor[motorLeft] = -100; motor[motorRight] = -100; wait1Msec(4000); motor[motorLeft] = 100; motor[motorRight] = -100; wait1Msec(2000); }

The while loop A while loop is a code structure that allows code inside of the statement to run over and over again as long as certain conditions remain true. task main(){ while(true){ //Stuff to be repeated } } The word condition above will always evaluate to true, so the loop will continue until the program terminates.

Example This will repeatedly send the signal for motors at full power, forever. task main(){ while(true){ motor[motorLeft] = 100; motor[motorRight] = 100; } }

Practice Make a program that drives forward for 3 seconds, backwards for 1 second, and repeats this infinitely. task main(){ while(true){ motor[motorLeft] = 100; motor[motorRight] = 100; wait1Msec(3000); motor[motorLeft] = -100; motor[motorRight] = -100; wait1Msec(1000); } }

The Integer (int) Abbreviated ‘int’ First, the variable must be created. int motorPower; Next, you must set the variable to have a value. This can be combined with the first step, or completed at any other time; int motorPower = 84; motorPower = 12; Finally, to use the variable, replace wherever you would put an integer with the variable’s name. motor[motorRight] = motorPower; variable= otherVariable;

The Boolean Abbreviated ‘bool’ Can be true or false Similar to int in creation and usage. bool flag =true; while(flag){ if(condition2){ flag = false; } if(condition3){ flag = false; } }

Working with #include Used to allow access to methods and variables from other files. Example: … pragma config(Servo, srvo_S1_C3_6, servo6, tServoNone) #include “JoystickDriver.c” task main(){ … Note: No semi-colon for this, just like no semi-colon for pragma configuration. Please go ahead and add this to your code.

Basic Teleop Use this expression to force the joysticks to update: getJoystickSettings(joystick); To use the readings of the joystick, try these expressions: motor[mL] = joystick.joy1  y1; motor[mR] = joystick.joy1  y2; Make sure your code compiles at this point, before we go into communications management.

Bluetooth / USB Connections Please follow along as we connect our robot; we will answer any of your questions.

Logic statements A while loop is a code structure that allows code inside of the statement to run over and over again as long as certain conditions remain true. A for loop runs only a specified amount. First, you create a variable (usually "i", nut can pretty much be anything you want), commonly an int. Then, inside the loop, you specify the amount the variable starts at (this is usually 0, but could, again, be different, since you might want to use the variable inside your loop); then, you specify up to what variable amount you want the loop to run (which would be the amount of loops -1, if your variable starts off at 0); finally, you tell the program how much the variable needs to be increased each loop (this is usually 1).

task main() { int i = 0; //the variable "i" is declared as an integer, and initialized to equal zero while(i < 20) //a while loop is delcared with the variable "i" being less than 20 as its true condition { motor[motorA] = 75; //motor A is run at a 75 power level motor[motorB] = 75; //motor B is run at a 75 power level wait1Msec(4000); //the program waits 4000 milliseconds before running further code motor[motorA] = 75; //motor A is run at a 75 power level motor[motorB] = -75; //motor B is run at a -75 power level wait1Msec(750); //the program waits 750 milliseconds before running further code i++; //the variable "i" is incremented (increased) by 1 }

task main() { int i; //the variable "i" is declared as an integer for(i = 0; i< 20; i++) //a for loop is declared that: intializes i equal to zero, continues to run under the condition i is less than 20, and increments i by one after each iteration { motor[motorA] = 75; //motor A is run at a 75 power level motor[motorB] = 75; //motor B is run at a 75 power level wait1Msec(4000); //the program waits 4000 milliseconds before running further code motor[motorA] = 75; //motor A is run at a 75 power level motor[motorB] = -75; //motor B is run at a -75 power level wait1Msec(750); //the program waits 750 milliseconds before running further code }

Touch and Ultrasonic Sensors A touch sensor allows you to detect when something is pressing on the touch sensor or not An Ultrasonic Sensor allows you to detect when something is in front of the sensor or not.

Touch Sensor SensorValue[touchSensor] is statement in RobotC that measures the values that a specific sensor brings in or records. In this case it is for a touch sensor. Put this into a while loop by simply putting while in front of SensorValue[touchSensor] while (SensorValue[touchSensor]) == 0) then insert something that you want to happen such as motors being powered or motors turning off. Example: while(SensorValue[touchSensor]) == 0) { motor[motorA] = 100; motor[motorB] = 100; } Now lets look at implementation.

Touch Sensor task main() { while(SensorValue[touchSensor]) == 0) //a while loop is declared with the touchsensor's value being 0 as it true condition { motor[motorA] = 100; //motor A is run at a 100 power level motor[motorB] = 100; //motor B is run at a 100 power level } motor[motorA] = -75; //motor A is run at a -75 power level motor[motorB] = -75; //motor B is run at a -75 power level wait1Msec(1000); //the program waits 1000 milliseconds before running further code }

Ultrasonic Sensor task main() { do //do instructs the computer to run the code in its braces and after 1 iteration check the condition at the while statment that follows { motor[motorA] = 75; //motor A is run at a 75 power level motor[motorB] = 75; //motor B is run at a 75 power level } while(SensorValue(sonarSensor) > 20); //after each iteration of the loop is conducted, the truth condition, if the sonar sensor value is greater than 20, is checked }