Programming Concepts (Part B) ENGR 10 Introduction to Engineering

Slides:



Advertisements
Similar presentations
Robofest 2005 Introduction to Programming RIS 2.0 RCX Code.
Advertisements

1 Signals, Circuits, and Computers John Athanasiou Part B Spring 2010.
Engineering Roles We will be forming groups of 3 students
Sensors.
Rotary Encoder. Wikipedia- Definition  A rotary encoder, also called a shaft encoder, is an electro- mechanical device that converts the angular position.
Automation and Robotics
VEX and Robot C Chris Patterson Presented by Modified by J. Andazola.
EML 2023 – Motor Control Lecture 4 – DAQ and Motor Controller.
Photos and Sensor Instructions
1 Sensors, Actuators, Signals, and Computers Part D Ping Hsu, Winncy Du, Ken Youssefi.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Available at: – Program Optical Quad Encoders in Autonomous Mode Program optical quad encoders in autonomous mode.
Blogics! It’s a logic circuit simulator aimed at beginners. It introduces simple concepts in the design of interactive physical computing systems such.
Connecting VEX and ROBOTC
Programming Concepts C: GOTO_Beacon ENGR 10 Introduction to Engineering 1.
Copier Jam Detector Design Problem
Controller, Sensors and Motors Ding Ke Tutorial 1, UGB 230N.
Program ultrasonic range sensor in autonomous mode
Programming Concepts Part B Ping Hsu. Functions A function is a way to organize the program so that: – frequently used sets of instructions or – a set.
GIRLS Robotic Camp. Let’s Begin Meet and Greet – Camp leaders introduce themselves – Students introduce themselves.
Programming Concepts (Part B) ENGR 10 Introduction to Engineering 1 Hsu/Youssefi.
Introduction to the VEX ® Robotics Platform and ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
Available at: Lesson 3.6 – Program Line Follower in Autonomous Mode Program Line Follower in Autonomous Mode.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
10/10/ Controlling YOUR ROBOT. 10/10/2015 Basic Stamp  Basic Stamp Input - output pins Interpreter Chip Power supply: 5 Volts voltage Memory: EEPROM.
7.2 V battery pack and charger Put the battery in the charger station at the end of the lab. period. Red light indicates charging. Ken Youssefi Introduction.
Robot sensors MVRT 2010 – 2011 season. Analog versus Digital Analog Goes from 0 to 254 Numerous values Similar to making waves because there are not sudden.
Programming Design ROBOTC Software Principles of Engineering
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3.
VEX and Robot C Chris Patterson Frisco ISD CTE Center Presented by.
Vex Robotics Program Two: Using two motors. Program two: using the motors In the last section, you learned how to turn on one motor. Now, you will take.
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.
Mechanical Components and Programming Ken Youssefi Introduction to Engineering – E10 1.
Connect VEX and ROBOTC Electrical Engineer Responsibilities © 2011 Project Lead The Way, Inc.Automation and Robotics VEX.
ROBOTC for VEX Online Professional Development. Homework Questions Thoughts? Questions?
Introduction to VEX® components
Basic Programming: Until Commands. The Problem with Wait States Motor Speed is affected by battery power. –If the battery is fully charged, the motors.
ROBOTC for CORTEX Teacher Training © 2011 Project Lead The Way, Inc. Automation and Robotics VEX.
Introduction to Programming in RobotC
Electrical Engineer Responsibilities
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
Programming & Sensors.
Electronic Control Systems Week 3 – Switches and Sensors
- Usable range of 0 to 6 feet. - Find dark or bright areas.
VEX IQ Curriculum Smart Machines Lesson 09 Lesson Materials:
Download the GOTO BEACON program from the E10 website, Robot lab section,
ROBOTC for VEX Online Professional Development
Electrical Engineer Responsibilities
Sensors For Robotics Robotics Academy All Rights Reserved.
ROBOTC for VEX On-Site Professional Development
Robotics Programming Using Shaft Encoders
ROBOTC for VEX Online Professional Development
IR Control Materials taken from a variety of sources including IR Remote for the Boe-Bot by Andy Lindsay.
Sensors For Robotics Robotics Academy All Rights Reserved.
Electrical Engineer Responsibilities
Vex Ultrasonic Sensor (US) Interfacing and Programming
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
Electrical Engineer Responsibilities
RobotC Sensors.
Movement using Shaft Encoders
Continuing with LED’s and Arduino
Automation and Robotics
Download the GOTO BEACON program from the E10 website, Robot lab section,
TECH 1 BAMS Technology Education
Controlling YOUR ROBOT
Copier Jam Detector Design Problem
Robotics Programming Using Shaft Encoders
LEGO MINDSTORMS NXT PROGRAMMING
Presentation transcript:

Programming Concepts (Part B) ENGR 10 Introduction to Engineering Hsu/Youssefi

Introduction to Engineering – E10 Summary Most commonly used logic statements: IF statement (for one case only) IF – ELSE statement (for two cases only) ELSE – IF statement (for more than two cases) WHILE loop (finite or infinite) statement Ken Youssefi/Ping Hsu Introduction to Engineering – E10

Functions What is a function? Why use a function? Function is just a group of code given a name. By grouping and naming it we can reuse it any where in the application without having to rewrite the whole block of code again. It saves time and reduces the overall code size of your program. But more importantly, if there is a problem you only have to fix it in one place. Why use a function? The following example shows how to write a function and how to call that function MAX_Three  find the maximum of 3 numbers Hsu/Youssefi

How to Define a Function in easyC V4 Right click on User Functions and select Add New Function Name the function (Max_Three and select Return Type (Int) Hsu/Youssefi

Sequential execution of main program which calls the defined function A, B, C, Z1, and Z2 are defined as global variables Main Program Function Hsu/Youssefi

Introduction to Local Variable The MAX_Three function finds the greatest of the three numbers A, B and C. These variables were defined as global variables. Before this function is called, your program must have copied the values into these three variables. This operation can be done more efficiently by using local variables. Hsu/Youssefi

Program using Function with passing variables x, y, and z are defined as Local variables A, B, and C are NOT defined as global variables Hsu/Youssefi

What is a Local variable ? The value of a local variable is accessible only to the function within which it is defined. The main function (main program) passes the values into the function and these values are copied into the local variables of the function. The function doesn’t care what are the names of the variables defined in the main function. The function does what it should do and then returns the result to the main function. The values of these local variables are lost after the execution of the function is completed. Hsu/Youssefi

Global Variable Concept A, B, C, and Z are defined as global variables Main Function Defined Function A Task of the function Z B C Hsu/Youssefi

Local Variable Concept Main Function Defined Function x, y, and z are defined as Local variables A x Task of the function max Z B y z C Hsu/Youssefi

Mechanical Components – Motors Clutch Make sure the clutch module is always used. It prevents damage to the motor in case of large torque (resistance to motion). Motor (Continuous) Motor, continuous rotation of the shaft (3 wire) Servo Servo, shaft rotates through a specified angle (3 wire) Hsu/Youssefi

Mechanical Components – Motor (New) The new motor has two wires (2-wire motors). It can be converted to a 3-wire motor using the controller 29. Ports 1 and 10 on the controller are designated for 2-wire motors only. 3 pins 2 pins Hsu/Youssefi

This chart describes the combination of the motor movement required to perform each maneuver Hsu/Youssefi

How to connect the motor to the Controller? On the VEX controller you have several ports available so that you can connect not only motors but also other devices and sensors to it. PORT: A port is a specific place on the board where we can connect other external devices, so that the two devices in connection can exchange information or data. Hsu/Youssefi

Continuous Motor Max. speed counter clockwise Custom speed Choose motor number, as connected to the Controller Max. speed counter clockwise Max. speed clockwise Custom speed Select Motor, drag and drop on the line between Begin and End Hsu/Youssefi

How to move a motor? Use the following statement to move a motor SetMotor ( 2 , 60 ); This number sets the direction and speed of the motor This number indicates that the motor is connected to motor port 2 of the total available 10 ports Hsu/Youssefi

X Controller (Cortex) Motor and Servo ports 8 analog and 12 digital ports. Digital ports are used for Limit, Bumper and Ultrasonic sensors X connected to the IRB mounted on the robot Hsu/Youssefi

Side view of the VEX Controller Battery Ports (Square and round connectors) Hsu/Youssefi

Cortex Two continuous motors to drive the robot (2-pin) Two 3-Wire motors to operate the claw and the arm (3-pin) Hsu/Youssefi

Program to move the robot forward Now let us write a program to make the robot move forward for 2 seconds and then stop. Assume: Left Motor – connected to motor port 3 Right Motor – connected to motor port 2 Hsu/Youssefi

Program to make the motor move forward for 2 seconds and then stop ; Hsu/Youssefi

Clicker Question 3 What value of x will cause the motor for Cortex controller to be stopped: SetMotor(2, x)? A. 64 B. 127 C. 0 D. 255 E. -127 Hsu/Youssefi

Servos Servo units are similar to motors except that they control position rather than speed. Servo units have limited range of motion (about 120o) A value between (-127) and (127) sets the direction of the servo. (127) – Extreme counter clockwise direction (0) – No movement (-127) – Extreme clockwise direction Hsu/Youssefi

Graphical representation of the direction of rotation of the Servo  Counter-clockwise Clockwise  60o -60o -127 127 Hsu/Youssefi

Indicates the motor port number to which the servo is connected. Similar to the motor the following statement is used to set the servo to turn to a direction. SetServo ( 5 , 64 ); Indicates the motor port number to which the servo is connected. This value sets the direction and the rotation of the servo Hsu/Youssefi

SetServo (5 , 64) - EasyC clockwise  Motor shaft rotates 30o clockwise and then stops 0o  Counter-clockwise clockwise  30o 64 600 -60o 127 -127 Hsu/Youssefi

Program showing how to move the servo continuously Hsu/Youssefi

Output of the above program  Counter-clockwise 0o clockwise  -30o 30o -64 64 - 60o 60o 127 -127 Hsu/Youssefi

Mechanical Components - Sensors Sensor blocks Limit Switch Sensor (Digital) Bumper Switch Sensor (Digital) Ultrasonic Sensor (Digital) Hsu/Youssefi

Introduction to Logic Signals A logic signal can take on either 0 volt or 5 volt 0v represents “Low state” or “Logic 0” 5v represents “High state” or “Logic 1” A logic signal can also be called a “digital signal” Hsu/Youssefi

Bumper/Limit Switch A Bumper/Limit Switch is a digital sensor. It can distinguish between two states: pressed or not pressed (On or Off) When the switch is not pressed, the robot interprets this value as a 1 (high state). When the switch is pressed the robot interprets the value as a 0 (low state). Hsu/Youssefi

Bumper & Limit Switches Use of the following statement in the program to read the bumper/limit switch. Bumper = GetDigitalInput ( 2 ); A variable into which the status of the bumper/limit switch will be stored. This indicates the port number to which the bumper/limit switch is connected Hsu/Youssefi

Program to make the robot stop and turn for 2 seconds when it hits an obstacle stores the state of the bumper switch into the variable “bumper”. checks if there is a contact with an obstacle (switch will be pressed if there is a contact) motor moves forward as long as there is no obstacle (bumper ==1) if the switch is pressed (bumper==0), these statements make the robot halt for 1 second Then the robot turns left for 2 seconds (green arrow is ccw) Hsu/Youssefi

Digital Output The “Digital output” function can be used to control the state of a digital output. By using this function you can send digital signals (either 0 or 1) to the devices which can accept digital signals. For example, by using this function you can turn off or on an LED. 1 => 5v => light is on 0 => 0v => light is off Hsu/Youssefi

Drag and drop the Digital Output Set the output signal (range), 0 or 1 Port # List of the output port # Hsu/Youssefi

Digital Output This statement is used in the program to control the devices i.e., send digital signals. SetDigitalOutput ( 11 , 1 ); Indicates the port number (here port 11) to which the device to be controlled is connected The digital value to be sent (either 0 or 1) Hsu/Youssefi

Program to make an LED blink continuously Hsu/Youssefi

Ultrasonic Sensor The Ultrasonic Sensor is a digital sensor. The Ultrasonic Sensor uses high-frequency sound waves to detect objects. It emits a sound wave, measures how long it takes the sound wave to bounce back, and then calculates how far away the object is. The measurement is translated into a numeric value from 2 - 100. Lower signal value corresponds to a closer detected object and vice versa. Hsu/Youssefi

Ultrasonic Sensor Connections Digital Output port Input Digital Input port Output (Interrupt port) Ultrasonic Sensor VEX Controller Hsu/Youssefi

Sensor connected to input port 5 Ultrasonic Sensor The following statement starts an ultrasonic sensor i.e., the sensor starts sending and recording the sound signals. Sensor connected to output port 6 through which it receives digital control signals from the controller. StartUltrasonic ( 5, 6 ) ; Sensor connected to input port 5 Select start Hsu/Youssefi

Ultrasonic Sensor The following statement is used to read a value from the sensor Range = GetUltrasonic ( 5 , 6 ); The sensor is connected to output port # 6 on the controller Variable into which the translated value is stored Input to Ultrasonic port #5 Select Get option Define variable Range, (2-100) Hsu/Youssefi

Changing Input port to Output port Edit Config Change port 6 from input to output by clicking on the circle Digital ports taken by the IRB Hsu/Youssefi

Checking if the obstacle is near or far Input to Ultrasonic sensor connected to output port 6 on controller Output from Ultrasonic sensor connected to input port 5 on controller Checking if the obstacle is near or far Hsu/Youssefi

Analog Signals For the VEX controller, an analog signal can take any value between 0v and 5v. 0v is represented by a value 0 5v is represented by a value 1023 (210) All other voltage levels between 0v and 5v are represented by the numbers between 0 and 1023. 5v 1023 2.5v 511 0v Hsu/Youssefi

Light Sensor A light sensor is an example of an analog sensor. A light sensor reads the intensity of light of an area, translates the reading into a single numeric value, and sends that value to the robot. The range of values used by this sensor is 0-1023 The higher the value, the darker will be the area and vice versa. Hsu/Youssefi

Light sensor The following statement is used to read the analog signal from a light sensor. light = GetAnalogInput ( 1 ) ; A variable named “light” into which the reading (0-1023) from the light sensor is stored Indicates the port number (here port 1) to which the light sensor is connected Hsu/Youssefi

Program to make the robot move towards the moving light source ELSE IF is used for more than 2 cases If light intensity is more on the left side, the robot turns toward the left side If light intensity is more on right side, the robot turns toward the right side If light intensity is the same on both sides, the robot moves forward Hsu/Youssefi

Optical Shaft Encoder The optical shaft encoder is a digital sensor. It is used to measure rotational movement. As the disc rotates, an infrared light sensor is used to count the number of slots passed. A count of 90 makes one revolution. Disc with 90 equally spaced slots Hsu/Youssefi

Optical Shaft Encoder StartEncoder ( 2 ) ; The following statement is used to start the encoder counting. StartEncoder ( 2 ) ; This number indicates that the encoder is connected to interrupt port # 2 on the VEX controller Hsu/Youssefi

Optical Shaft Encoder The following statement is used to get the present count value from the encoder. Count = GetEncoder ( 2 ) ; Interrupt port # 2 to which the Encoder is connected A variable named “count” into which the present count value will be stored Hsu/Youssefi

Write a program to make the robot move for 1 meter and then stop. PresetEncoder ( 2, 20) ; This statement is used to make the encoder start counting from a given number (here 20) instead of from zero. Example Write a program to make the robot move for 1 meter and then stop. Assume 5 turns of the wheel = 1 meter Hsu/Youssefi

Program to make the robot move forward for 1 meter Presetting the encoder to 20. Count value starts from 20. if count reaches 470 the robot stops. 470 = 450 (count for 5 turns x 90) + 20 (initial value) Hsu/Youssefi