Introduction to Programming in RobotC

Slides:



Advertisements
Similar presentations
Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
Advertisements

08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
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.
Automation and Robotics
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
IR SENSORS AND ENCODERS. LCDs Timothy Friez Class # 2.
Introduction to Sensors
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.
RobotC For Beginners Tyler Lutz and Keaton Bonds DRSS Enterprise.
LEGO Mindstorms NXT Programming We will be using the Common Palette for our Robots This is how you download your program onto the brick Drag and drop a.
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.
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
GIRLS Robotic Camp. Let’s Begin Meet and Greet – Camp leaders introduce themselves – Students introduce themselves.
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)
Programming Design ROBOTC Software Principles of Engineering
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.
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.
Vex Robotics Program four: reversing and turning.
Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
BEGINNER FLL PROGRAMMING WORKSHOP BY DROIDS ROBOTICS & EV3LESSONS.
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.
Casne.ncl.ac.uk Taking care of the CrumbleBot Please do NOT stress the robot's motors 1.Do NOT push the robot 2.Do NOT hold the.
Robotics Programming Wall Follow Line tracking for a set amount of time Line tracking for a distance.
Variables. A variable is a space in your robot’s memory where you can store data, such as whole numbers, decimal numbers, and words. Variable names follow.
ROBOTC for CORTEX Teacher Training © 2011 Project Lead The Way, Inc. Automation and Robotics VEX.
How to design, build, and program a LEGO robot!
LEGO Robotics Workshop
Variables and Functions
Class-Level Variables in Alice
Deriving Consistency from LEGOs
Variables and Functions
Variables and Functions
Introduction to Programming
By Sanjay and Arvind Seshan
Automation and Robotics
Programming Design ROBOTC Software Computer Integrated Manufacturing
Programming Part 2 Mod Kit
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
Variables and Functions
Basics for Robotics Programming
Movement using Shaft Encoders
Using Encoders to go Straight
Programming – Touch Sensors
Variables and Functions
Variables and Functions
Variables and Functions
Variables and Functions
Sensors Training.
Automation and Robotics
BEGINNER PROGRAMMING LESSON
Variables and Functions
Controlling your quadcopter
An Introduction to VEX IQ Programming with Modkit
Auto Straightening using VEX Shaft Encoders
Storing Values as Variables
An Introduction to VEX IQ Programming with Modkit
Programming - Buttons Intro to Robotics.
Programming - Buttons Intro to Robotics.
Robotics Programming Using Shaft Encoders
RobotC Programming for LEGO Mindstorms NXT
creating a ecosystems model in net logo
Programming Design ROBOTC Software Principles of Engineering
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
Controlling your quadcopter
Presentation transcript:

Introduction to Programming in RobotC Vex IQ

Build a simple structure to support each of the brain, two motors and each sensor as listed to the right. Connect them as listed Port Connection 1 Motor – LEFT 2 Motor – RIGHT 3 Bumper Switch 4 Touch LED 5 Color Sensor 6 Distance Sensor 7 Gyro Set-up

Programming Each student will work alone When a student thinks they have a program written to complete one of the tasks, one of the instructors will come around with a robot practice station for you to download your program and allow the instructor to check that your program works as expected. Programming

Programming Everyone should complete task #3 first. Display your name on the first line of the display and put a fun quote on the second line of the display Programming

Programming Basics Open RobotC – NOT the graphical program Set up motors and sensors These are listed on page 3 of your packet Give each sensor or motor a unique name Make sure to “apply” the name given Programming

Programming Programming Basics Almost all lines of code must end with a semi colon Most commands you need can be dragged onto the program from the “text functions” panel on the left All parenthesis must open and close Conditional commands use fancy brackets Inside the fancy brackets, many individual commands can be included Programming

Programming Task #3, simple Put the following inside the fancy brackets for task main displayTextLine(1,”your name here”); displayTextLine(2,”Hello World”); Everyone test that this works Programming

The basics of a complete program Programming

It is nice to have words in your code that tells yourself and others what the code is doing. At the end of a line add // then everything on that line after the // will not be read as code, but is a comment Longer comments are contained between the following /* comment goes here */ Comments

Programming Lets change our text to display a button being pushed FIRST – Save the program with a new name Programming

Programming To get the results of a button use the following vexRT[BtnEUp] Replace BtnEUp with other buttons based on the drop down list that appears Programming

Buttons to the BRAIN Test this code So, is the mathematical value of the buttons? Buttons to the BRAIN

Buttons What results do the brain see when a button is changed? Buttons send a zero when not pushed and a one when pushed Buttons

Buttons to the BRAIN Try the same thing with the joysticks So, are the mathematical values of the joysticks? Buttons to the BRAIN

Conditionals Conditionals only do something when the condition is met. Conditionals include If While Conditionals must be followed by fancy brackets Conditionals

Button turn on light The if statement is followed by brackets Exactly what do you expect to happen Button turn on light

How could you change the code so the light goes out when the button is not pushed? Button turn on light

Try this Button turn on light

We can change things with variables Just like math class, we can assign a letter (or a whole word) to represent a value Variables

Programming To do more, we need to add some math Variables Variables allow us to remember a state, however the brain needs information on what kind of variable you may use Programming

What kind of information might you want to store in a variable? String = for storing text Int = for storing integer numbers Float = for storing numbers with decimals Bool = for storing a state, true or false Char = stores a single character Programming

Programming

Try this Counting

Try this Variables

Sensors What about sensors? What values do they send? The bumper switch is very much like the buttons on the controller Sensors

Bumper Switch

Programming How can I make the motors move? motor[Left]=vexRT[ChA]; “Left” must match the name applied in the pragma Add to your program so both motors spin with joysticks. Programming

Let’s work toward programming something to make a robot move Can you display the results of the joysticks on the screen of your brain? Programming

Tank Drive Controls

Arcade Drive Tank drive is easiest to write. Most drivers prefer arcade drive. What does it take to turn and drive forward? Arcade Drive

Arcade 2 Controls

Your turn. Make both motors move forward or backwards with the “a” joystick Then Make the “b” joystick turn the robot Programming

Arcade 1 Controls

Distance sensor Save value to a variable int sonarDist; Get variable sonarDist = getDistanceValue(SonarSensor); Programming

task main() { int sonarDist; // Initialize a variable for the sonar while(true) sonarDist = getDistanceValue(SonarSensor); displayTextLine(1,"%d",sonarDist); // Display the sonar value } // end while true } // end task main Sonar Sensor

Sonar Sensor

How could this be used to affect the drive motors on the robot? Sonar

Sonar How could this be used to affect the drive motors on the robot? Drive slower when closer to an object Drive faster when farther away Sonar

Because the sonar values are generally large, I divided to make them smaller

task main() { int sonarDist; // Initialize a variable for the sonar while(true) sonarDist = getDistanceValue(SonarSensor); sonarDist = sonarDist / 5; // scale the speed to move slower if (sonarDist > 100) sonarDist = 100; // if speed is over 100, reset motor[Left] = sonarDist; // set motor value displayTextLine(1,"%d",sonarDist); // Display the sonar value } // end while true } // end task main Sonar

Sonar

More interesting things happen when you can record and save a “state” for your robot. The following with two variables creates a “latch” that keeps the robot in the same state until the same button is pushed again. Programming

task main() { bool buttonToggleState = false;// possible states are true or false bool buttonPressed = false; while(true) // check for a button press only if we are not already pressed. if( vexRT[ BtnFUp ] == 1 ) if( ! buttonPressed ) buttonToggleState = !buttonToggleState;// change the toggle state buttonPressed = true;// Note the button is pressed } else buttonPressed = false;// the button is not pressed // Now do something with our toggle flag if( buttonToggleState ) displayTextLine(4,"State is On"); // Display the state setTouchLEDColor(Touch, colorRed);// Turn LED on and Red displayTextLine(4,"State is Off"); // Display the state setTouchLEDColor(Touch, colorNone); // Turn LED light off }// while-true loop }// task main Latch

Latch

Programming Challenge If the bumper switch is mounted on the bumper, when the robot hits a wall, can you program it to switch to reverse? Bump it again, and switch to forward Programming Challenge

Bumper Latch task main() { bool buttonToggleState = false;// possible states are true or false bool buttonPressed = false; while(true) // check for a button press only if we are not already pressed. if(getBumperValue(Bump) == 1 ) if( ! buttonPressed ) buttonToggleState = !buttonToggleState;// change the toggle state buttonPressed = true;// Note the button is pressed } }else{ buttonPressed = false;// the button is not pressed // Now do something with our toggle flag if( buttonToggleState ) motor[Left] = 70; // Drive Forward motor[Right] = 70; // Drive Forward motor[Left] = -70; // Drive Backwards motor[Right] = -70; // Drive Backwards }// while-true loop }// task main Bumper Latch

Bumper Latch

Your turn Combine your earlier program of a “Latch” to turn the right motor on with a button Then turn it off again with the same button Programming

Color Sensor So you have a color sensor connected to port 5. What values does this provide to your brain? Can you write a program to figure it out? Color Sensor

Can we display this color number as a color? Color Sensor

Try This!!