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.

Slides:



Advertisements
Similar presentations
Why not just use Arrays? Java ArrayLists.
Advertisements

Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
While Loops and If-Else Structures
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
Introduction to Computing Science and Programming I
Automation and Robotics
Animation Mrs. C. Furman. Animation  We can animate our crab by switching the image between two pictures.  crab.png and crab2.png.
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)
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Classes, methods, and conditional statements We’re past the basics. These are the roots.
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.
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Programming & Scratch. Programming Learning to program is ultimately about learning to think logically and to approach problems methodically. The building.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
 Make sure you are subscribed to announcements on Moodle.  Activity 4 will be due 48hrs after your lab ends.
CPS120 Introduction to Computer Science Iteration (Looping)
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
CPS120 Introduction to Computer Science Iteration (Looping)
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.
Mindstorm NXT-G Introduction Towson University Robotics.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
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.
Learning Javascript From Mr Saem
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.
Introduction to Programming in RobotC
Variables and Functions
Variables and Functions
Variables and Functions
Movement using Shaft Encoders
Using Encoders to go Straight
Programming – Touch Sensors
Variables and Functions
RobotC Sensors.
Variables and Functions
Variables and Functions
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Variables and Functions
Using variables, for..loop and functions to help organize your code
Automation and Robotics
While Loops and If-Else Structures
Basketball Drill Programming Alternatives
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Variables and Functions
Line Following Behavior
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops and If-Else Structures
Programming - Buttons Intro to Robotics.
if-else Structures Principles of Engineering
Programming - Buttons Intro to Robotics.
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops And If-Else Structures
How to allow the program to know when to stop a loop.
Presentation transcript:

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 too far down. These problems can be stopped if there was something to PREVENT the arm from moving.

Operator Assist – Touch Sensor

You should see the following code above. Add the code below.

Robotic Arm?

Robotic Arm – Approach #2

Problem!!! The robot does NOT drive properly while handling the arm controls. Each time an arm control is activated the system will stick as it updates. In other words, the program gets trapped inside the “arm” while loops.

Solution? Not a loop! The “if” statement The “if” conditional staement works similarly to a while loop. Whereas a while ( ) loops runs {body} commands over and over while a (condition) is true, an “if” statement runs a {body} of code ONCE if the (condition) is true, and skips past it altogether if the (condition) is false. There is no loop so there is no risk of getting stuck!

“If” statement

Change, check, and save the code with “arm” in the title for later use.

The program already uses if-statements to check the value of the operator inputs. We need to add a second check – on the limit switch – to determine whether it is really appropriate to run the motors.

If you need to find out more than one thing from someone, you ask several questions in order. Depending on an earlier answer, you may need to ask a follow-up question. This is the basic principle behind a nested conditional statement.

??? PROBLEM! The program doesn’t work right

Operator Assist – Limiting the Arm The program is partly working, but we clearly left something out. We told the robot what to do when the Transmitter button was held and the Limit Switch was not being pressed. But we didn’t tell it what to do when the Limit Switch was pressed! The arm simply continued to run at the last given motor power because it was not told to stop. The if-else statement is simply an if-statement with an additional else block added on that describes a second {body} of code to run if the (condition) is false.

If-Else

Pay careful attention to which if each else belongs to. The else blocks belong to the inner if-statements (starting on lines 19 and 30 below). These are the statements that check the Limit Switches, not the ones that check the Transmitter buttons. They tell the robot what to do if you answer “no” to the followup question, not the opener — you had to answer “yes” to the opener for the followup to even be asked.

When you press the button on an elevator, you only need to press it once. When you press a button on your Transmitter, however, you have to hold it down, or its effect stops. The elevator remembers that its button was pressed, but your robot does not. It would certainly be convenient if your robot could also use its memory to keep track of important commands, so that you don’t need to hold down a button to remind it.

When you really need to remember something, it can be helpful to write it down. By storing that information somewhere permanent, you ensure that you can come back to it later when it’s needed. The robot works in a similar way. If it needs to keep track of something, it will need to store that piece of information somewhere. Robots store information in variables. Variables function as containers, or storage, for values. As such, they can hold concrete values, such as the -127, 0, or 127 sent by the Transmitter buttons. They can also store abstract values that a program uses to represent different things (perhaps 1 means up, and -1 means down).

Variables and State Names It is this last type of value, an abstract representation, that we will be using to make the robot arm remember which way it should be going, even after the Transmitter button stops being pressed. Since the robot doesn’t directly understand “up” or “down”, we will use one of the types of values that it does understand to represent those directions. That value will be stored in a variable for the robot to remember.

In order to create (or declare) a variable, the programmer must identify two key pieces of information: the type of value it will hold, and a name for the variable. The naming rules for sensors that you learned earlier also apply to variables. Give a variable a name that makes it easy to remember what kind of information is stored in the variable. This makes it easier to debug your program. Here are some of the most common variable types used in ROBOTC:

Variables For the robotic arm, either letters or simple numbers make sense as a way to represent the direction that the arm should move. We will use numbers, with the following values representing arm directions:

The first step in the program is to create (or declare) the variable. Declaring a variable requires you to specify its type and name. We will use an integer (int) variable and call it “armDirection”. It will store the -1, 0, or 1 representing the direction of arm travel.

Change the existing motor-setting code to set the powers of the motors based on the desired direction (value of the “armDirection” variable) rather than the button being pushed. Continue to check whether the Limit Switches are pressed in.

Summary and checking for understanding After checking your arm directions, apply your own comments to the code and turn it in for grading.