430 likes | 622 Views
College of Southern Maryland Vex Robotics Workshop EasyC Tutorial. Presented By: Willy Hamel Stewart Smith August 2012. Methods of Control. Driver Control Autonomous Programming Without Sensors With Sensors Sample Programs Competition Templates. Driver Control.
E N D
College of Southern MarylandVex Robotics Workshop EasyC Tutorial Presented By: Willy Hamel Stewart Smith August 2012
Methods of Control • Driver Control • Autonomous Programming • Without Sensors • With Sensors • Sample Programs • Competition Templates
Driver Control • Choosing a joystick channel • Selecting method of control • Motor direction and power • While loop
Choosing a Channel Ch5 Ch6 Ch7 Ch8 Ch3 Ch2 + Ch4 Ch1 - + -
Methods of Control • Arcade Drive • Tank Drive • Holonomic Drive • Single Motor Control • Stick control • Button control • Variable control (Advanced)
Arcade Drive Single stick control Two motor arcade drive is depicted left, however, a four motor block also exists.
Tank Drive Two stick control Two motor tank drive is depicted left, however, a four motor block also exists.
Holonomic Drive Two-stick control A holonomic drive enables greater range of motion at the expense of available power in any one direction
Joystick to Motor This block will map a motor’s power to the joystick. The joystick channel dictates which way the stick must be pushed to power the motor
Joystick Digital to Motor This block will map a motor’s power to a button on the controller. You must choose a channel as well as how much power the motor will receive when the button is pressed.
Variable control (Advanced) This block will map a motor’s power to a defined variable. The motor will then no longer necessarily be controlled by the joystick, but by whatever the variable is equal to.
Motor Direction and Power 127 0 -127 0 = Stop
While Loop A while loop will repeat the commands within it until the condition in parenthesis is no longer met. An infinite loop, a while loop that is always true, is needed in any Driver code to constantly update the motor commands.
Autonomous Coding • Programming Logic • Motor Control • Sensors • Sample Programs • Competition Templates • Timed • Field Control
Programming Logic • Variables • If • Else-If and Else • Operators • While • Wait • Print to Screen • Comment
Variables Variables are placeholder for values within the program. They can be used to hold sensor input values for later use within the code.
If Statement An if statement will perform its commands only if the condition in parenthesis is true. If false, the statement will just be skipped and not read. An if statement can be used to prevent an unwanted action from occurring or to respond to a sensor input.
Else-If and Else Statements An else-if statement is a logical branch that enables more control than a single if statement. An else statement is a catchall statement used to define an action if the preceding if/if-else statements are false
Operators Operators are symbols that represent a logical function. They can be used in while loops and if statements to ensure the desired action/function occurs.
While Loop A while loop will repeat the commands within it until the condition in parenthesis is no longer met. A while loop that that contains a get sensor value block allows you to constantly update the sensor value and make decisions based on your sensor values.
Wait Statement A wait statement will cause the robot to wait a certain number of milliseconds before performing the next command . (Warning, this pauses ALL functions in the program!) A wait statement is typically used to control motors in the absence of sensors.
Print to Screen Print to screen is a command that can be used to find the current value of a variable. It will be shown in the terminal window. This feature can be used to trouble shoot your sensors.
Comments A comment is a line of text left by the user. Use it to keep track of what your code is doing.
Motor Control Use output blocks to control individual motors. You must declare power and direction.
Motor Control Control the duration of movement using wait blocks. You can also give motors commands based on sensors.
Sensors • Potentiometers • Ultrasonic Rangefinders • Limit switches/Bumpers • Optical Shaft Encoders • Line Followers
Potentiometers • Used for precise angle measurement • Maximum rotation of 250⁰ • This angle is divided into 1024 increments Potentiometer
Ultrasonic Rangefinder • Used for measuring distance from an object • Maximum range of 115 inches (approx. 9.6 feet) Ultrasonic Rangefinder
Limit Switches/Bumpers • Used for detecting contact • Differ in ability to take different contact forces. Limit Switch. Sensitive, but a little fragile. Bumper Bumper Switch. Less sensitive, but can take a beating.
Shaft Encoder D = 2*π*r r = radius of wheel D = distance traveled in one revolution π = 3.14159~ • Used for counting rotations made and finding distance traveled • Capable of unlimited 3600 rotation (free spinning) Shaft Encoder
Line Follower • Used for detecting color differences • Useful for following or detecting lines Line Follower
Programming Sensors • Inputs • Wait Until
Programming Sensors These blocks measure a sensor value and record it in a variable so it can be called later in the code. They are used in conjunction with logic statements to control the robot.
Programming Sensors Potentiometer
Programming Sensors These blocks are similar to Wait blocks. The robot will not proceed to the next action until the condition is met. These blocks do not require a variable in order to function.
Programming Sensors Bumper Wait Until Block
Programming Sensors Ultrasonic Wait Until Block
Sample Programs Sample Programs demonstrate how to set up and use vex sensors as well as other programming techniques.
Competition Templates These are code templates that allow you to simulate or play in a Vex Robotics Competition.
Template Types • Field control • Timed (in seconds)
Resources • http://www.robotc.net/vex_full/ • http://www.education.rec.ri.cmu.edu/roboticscurriculum/vex_online/hardware/index.htm