Introduction to RobotC and Tetrix with Lego Mindstorms

Similar documents
CONTENTS. What is ROBOTC? Section I: The Basics

Additional Guides. TETRIX Getting Started Guide NXT Brick Guide

TETRIX Add-On Extensions. Encoder Programming Guide (ROBOTC )

How To Program An Nxt Mindstorms On A Computer Or Tablet Computer

understanding sensors

Programming LEGO NXT Robots using NXC

Line Tracking Basic Lesson

YOSEMITE REGIONAL OCCUPATIONAL PROGRAM COURSE OUTLINE. COURSE TITLE: Robotics Engineering I ROP S1 Robotics Engineering I ROP S2

Tutorial for Programming the LEGO MINDSTORMS NXT

C.I. La chaîne d information LES CAPTEURS. Page 1 sur 5

EasyC. Programming Tips

ROBOTC Software Inspection Guide with Additional Help Documentation

Speed Based on Volume Values & Assignment (Part 1)

What Is an Electric Motor? How Does a Rotation Sensor Work?

Building Instructions: Maze Robot

North Texas FLL Coaches' Clinics. Beginning Programming October Patrick R. Michaud republicofpi.org

EV3 Programming. Overview for FLL Coaches. A very big high five to Tony Ayad

2/26/2008. Sensors For Robotics. What is sensing? Why do robots need sensors? What is the angle of my arm? internal information

Getting Started Manual

ROBOTC Programming Competition Templates

Lego Robot Tutorials Touch Sensors

Classroom Activities for the Busy Teacher: EV3

How To Turn On A Robot On A Computer On A Black Box On A Pc Or Macbook

ROBOTC Natural Language - VEX Cortex Reference:

Quick Start Guide to computer control and robotics using LEGO MINDSTORMS for Schools

Advanced Programming with LEGO NXT MindStorms

The second goal is to provide a list of tips, tricks, and best known methods that have been discovered over the life span of the course.

The Basics of Robot Mazes Teacher Notes

Questions: Does it always take the same amount of force to lift a load? Where should you press to lift a load with the least amount of force?

Best Robotics Sample Program Quick Start

The NXT Generation. A complete learning solution

Introduction WELCOME TO LEGO MINDSTORMS EDUCATION

Introduction to programming moway

Introduction WELCOME TO LEGO MINDSTORMS EDUCATION

NXT Robot Challenge. Introduction. Educational Goals. References

Downloading a Sample Program over USB

Robotics. Lecture 3: Sensors. See course website for up to date information.

Six-servo Robot Arm. DAGU Hi-Tech Electronic Co., LTD Six-servo Robot Arm

Programming the VEX Robot

Next Gen Platform: Team & Mentor Guide

Using the VEX Cortex with ROBOTC

Arduino Lesson 16. Stepper Motors

Rubber Band Race Car

CHAPTER 12 NXT Remote Control

Teacher Answer Key: Measured Turns Introduction to Mobile Robotics > Measured Turns Investigation

ROBOTICS AND AUTONOMOUS SYSTEMS

Workshop NXT Programming For Beginners

Building Robots with NXT and LEJOS. Introduc<on. What is the NXT Robot Michael Wooldridge liv.ac.uk)

The Fibonacci Sequence

Building a Better Robot

RobotC Tutorial Packet I

LEARNING MOBILE ROBOTICS USING LEGO MINDSTORMS

What You ll Learn. CHAPTER 12 Robot Remote. The BluetoothClient component for connecting to the NXT

Tutorial 1. Introduction to robot

Modern Robotics, Inc Core Device Discovery Utility. Modern Robotics Inc, 2015

SharePoint Wiki Redirect Installation Instruction

Set up and using the WinTV v7 application with HD PVR 2

After: bmotorreflected[port2]= 1; //Flip port2 s direction

SE05: Getting Started with Cognex DataMan Bar Code Readers - Hands On Lab Werner Solution Expo April 8 & 9

House Design Tutorial

Dr Robot C# Advance Sputnik Demo Program

Autonomous Advertising Mobile Robot for Exhibitions, Developed at BMF

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Service Bulletin Trucks Date Group No. Page

LEGO MINDSTORMS EV3 Teacher s Guide. Introduction to Programming

Transfer of Energy Forms of Energy: Multiple Transformations

How to Build a Simple Pac-Man Game

Greetings Keyboard Mastery Keyboarding Students! Teacher: Mrs. Wright

CREATING A 3D VISUALISATION OF YOUR PLANS IN PLANSXPRESS AND CORTONA VRML CLIENT

Electric Landing Gear controllers and sequencer LGC12 / LGC 13C

e d u c a t i o n NXT Solar Station

Infrared Sensor. Color Sensor. Touch Sensor. Programmable brick. 3 Interactive Servo Motors. Makes your robot see. Makes. your robot.

SolidWorks Tutorial 4 CANDLESTICK

How to Create Custom Sound Effects for NXT Robots.

Servo Motors (SensorDAQ only) Evaluation copy. Vernier Digital Control Unit (DCU) LabQuest or LabPro power supply

How to set up Outlook Anywhere on your home system

LEGO NXT-based Robotic Arm

Tooling List 17mm Socket 17mm Wrench 24mm Wrench 26mm Wrench 3/8 Drive Ratchet Torque Wrench

LCD MONITOR TOUCH PANEL DRIVER 2 OPERATION MANUAL. for Mac. Version 1.0 PN-L703A/PN-70TA3/PN-L703B/PN-70TB3/PN-L603A/PN-60TA3/PN-L603B/PN-60TB3

Can Traffic Accidents be eliminated by Robots?

Applications of Robotics

FUNDAMENTALS OF ROBOTICS

Herzog Keyboarding Grades 3 through 5. Overarching Essential Questions

DRAFT COPY: CONTENTS SUBJECT TO CHANGE. FTC Training Manual. JAVA Programming for the Next Gen Controller. FIRST Tech Challenge 8/3/2015

Potential vs. Kinetic Energy

Arduino Lesson 13. DC Motors. Created by Simon Monk

EasyPen i405x. MousePen i608x. User Manual For Windows 7/Vista/XP

Turtle Power. Introduction: Python. In this project, you ll learn how to use a turtle to draw awesome shapes and patterns. Activity Checklist

Self-Balancing Robot Project Proposal Abstract. Strategy. Physical Construction. Spencer Burdette March 9, 2007

Activities for LEGO WeDo in Scratch 1.4+ Barb Ericson

G-100/200 Operation & Installation

Congratulations for making the decision to become one of the many proud KT-X robot owners.

Motion. Table of Contents: Introduction to the Motion Subsystem 3.2. Concepts to Understand 3.8. Subsystem Interactions Motion.

Courtney Pinnell. Dr. Can (John) Saygin. Edward E. Whitacre Jr. College of Engineering

Introduction to SketchUp

Objects in Alice: Positioning and Moving Them

Blender Notes. Introduction to Digital Modelling and Animation in Design Blender Tutorial - week 9 The Game Engine

Transcription:

Introduction to RobotC and Tetrix with Lego Mindstorms These lessons will introduce writing autonomous robot programs in RobotC using the Tetrix Building system and the Lego Mindstorms Robotics Kit. Topics will cover: Selecting the Type of Robotics Platform Configuring the Motors, Servos, and Sensors using the RobotC Setup Option. Basic Forward and Reverse Program using Motor Blocks and Wait commands. How to create methods (reusable sections of Code) Creating Methods with Sensors and using While Loops: TouchStop with Touch Sensor NearStop with UltraSonic Sensor Dark Stop with Light Sensor Using the Timer More advanced methods: (Application) Minimum Distance Seeker Proportional Wall Following with UltraSonic Proportional Line Following 2011 Mr. Michaud / www.nebomusic.net 1

Lesson 1: Setting up the Robot Platform and Configuring the Motors, Servos, and Sensors. This tutorial uses the "ICEBot" frame with the left and right drive wheels being on the front of the robot. The NXT Brick is configured as follows: Sensor Ports: 1 = Motor and Servo Controller for the Tetrix motors and servos 2 = NXT Touch Sensor 3 = NXT Light Sensor 4 = NXT UltraSonic Sensor Motor Ports: C = NXT Motor to control the "Hand" ICEBot with Michaud Modifications Images: 2011 Mr. Michaud / www.nebomusic.net 2

2011 Mr. Michaud / www.nebomusic.net 3

2011 Mr. Michaud / www.nebomusic.net 4

2011 Mr. Michaud / www.nebomusic.net 5

When you start programming in RobotC, you will need to define all the motor, servo, and sensor connections. This is like defining the "objects" in a program before you start creating instructions and methods. RobotC has two menu driven tools to accomplish this configuration. Steps: 1. Start RobotC and Select File-New to start a new program. 2. Select "Robot->Platform Type" from the menu bar and select "NXT+Tetrix". 3. Select "Robot->Motors and Sensors Setup" 2011 Mr. Michaud / www.nebomusic.net 6

4. Select the "TETRIX Controllers" tab and select the second option: "Standard Configuration. One motor controller, one servo controller on sensor port S1." (Though in more advanced robot designs, you can set up your own configuration) 5. Click "Apply" 2011 Mr. Michaud / www.nebomusic.net 7

6. Click the "Motors" tab. Name the motors as shown below. Note that I used the name "Hand" for "motorc." By convention, motors "A, B, and C" are the NXT motors. Motors "D and E" are the Tetrix DC motors. (12V). Make sure you select "Reversed" for motore. This allows motors to rotate "forward" and "backward" in vehicle type robots. Note that you can give the Motors names. Choose names that make sense for the robot's purpose. This will make your Code easier to understand later. 7. Click "Apply." 2011 Mr. Michaud / www.nebomusic.net 8

8. Click the "Servos" tab. Name servo1 "Arm" and select "Standard Servo". Note that I also have servo2 named "Sonic." 9. Click "Apply." 2011 Mr. Michaud / www.nebomusic.net 9

10. Click the "Sensors" tab. Set Sensors S2, S3, and S4 as shown below. Make sure to select "Touch", "Reflected Light", and "Sonar." in "Type." 11. Click "Apply." 12. Click "OK." 13. Note that the first 10 lines of your program now contain auto generated code that configures the Hubs, Sensors, Motors, and Servos. (The "pragma config") These define the robot objects in the program. 14. Save your program as Tetrix Train 2011 Mr. Michaud / www.nebomusic.net 10

Lesson 2: Beginning to Drive: The "Forward - Stop" The most basic element of robot programming follows the format of "Start the Task -> Wait for a condition -> Stop the Task" In this program, we will: 1. Start the motors 2. Wait for 2 seconds 3. Stop the motors In your program - type the following code: To run your program: 1. Save your Program (File->Save). Name it Tetrix Training. 2. Select "Robot -> Compile and Download Program." Then close the "Debugger" and select and Run the program on the NXT Brick. A few notes of Caution: 1. Always run your robot on the floor or a walled table. Tetrix robots are heavy and can do some serious damage to you or other objects. 2. Keep your fingers away from the metal gears. All RobotC programs start with the "task main." Inside the curly brackets are the instructions: Here is a breakdown: 2011 Mr. Michaud / www.nebomusic.net 11

Now try the following program "Out and Back" Extras: There are two types of Turns: 1. Swing Turn: One wheel rotates and the other stays still 2. Point Turn: One wheel turns forward while the other wheel turns backward. How would you program the robot to do Swing and Point turns? 2011 Mr. Michaud / www.nebomusic.net 12

Lesson 3: Setting the Servo Positions The Tetrix Servos act like motors that you can lock in positions ranging from 0 to 255. You set these positions like setting a variable. Example: (Moves the Front Arm Up and Down with 1 second delays) I suggest in each of your programs, put a "servo[servo1] = 0;" before each program to lift up your arm. 2011 Mr. Michaud / www.nebomusic.net 13

Lesson 4: Making methods One of the main goals of programming is to create re-usable pieces of directions that make sense to the human reading your Code, and save time and space (not having to re-type long series of commands over and over again.) Thus we are going to start making a series of "Methods" that do common tasks. A "Method" is a block of instructions that you can call in the Main Task over and over again. We will make two methods: "drivestraight" and "stopmotors." Type the following above your "task main()": Note: 1. We use the term "void" before the Method because the method does not return a value. (It only directs action.) 2. The "int power" is a parameter for the drivestraight method. This allows the programmer to define how much power will go to the motors. The "int" means "integer." Type the following into the task main() to run these methods: Note that the main task now uses three lines of code to do what took us 5 lines earlier. 2011 Mr. Michaud / www.nebomusic.net 14

Exercises: 1. Make the Robot Drive Forward and Backward using the drivestraight and stopmotors methods. Hint: Negative numbers will make the motors turn backwards. 2. Create a Method for Turning the Robot Left and Right. Then program your Robot to Drive in a Square. 2011 Mr. Michaud / www.nebomusic.net 15

Lesson 5: Methods using Sensors and While Loops Because Tetrix DC motors do not have encoders or rotation sensors, we will need to use other Sensors such as Touch, Light, and Sonar to help guide the robot through the world. These series of methods follow this basic robot pattern: "While a Condition is True: Do an Action. When the Condition is not true: Stop the motors or Action" Add the following method and edit the main task in your program for "TouchStop." Save, Compile and test the program: (Remember, you will need to keep the Methods drivestraight and stopmotors in your program. Notes: 1. We use the parameter "int power" again to let the programmer define how fast the robot should go. 2. The "while loop" tells the program to run the "drivestraight" method until the touch sensor is touched. 3. "SensorValue[Touch]!= 1" means: "Touch Sensor does not equal 1" or "Touch Sensor Not Pressed." 4. Translation of method: "While the Touch Sensor is not pressed, Drive Straight. When the Touch sensor is pressed, stop the motors." 2011 Mr. Michaud / www.nebomusic.net 16

Try these methods for UltraSonic Stop and Light Stop: Notes: 1. In the "nearstop" method, note the two parameters: "distance" and "power." This allows the user to define the distance in centimeters for the stop and the speed of the robot. 2. In the "darkstop" program the parameters "dark" and "power" allow the user to specify the darkness the robot is looking for and the speed of the motors. We can also reduce the basic Forward for Time type program with this method: 2011 Mr. Michaud / www.nebomusic.net 17

Exercise: 1. Using the nearstop method, create a program that will allow your robot to drive straight and stop if it nears any obstacle. Then direct the robot to turn to a new direction and keep moving. 2011 Mr. Michaud / www.nebomusic.net 18

Lesson 6: More Advanced Programs - using variables and methods we have already created. Example 1: The Nearest Object program. This example spins the robot around. While the robot is spinning, it is seeking out the nearest object using the UltraSonic Sensor. When it is finished spinning, it points back to the nearest object and travels up to the object and stops. Extras: Make the back up and then seek the next nearest object 2011 Mr. Michaud / www.nebomusic.net 19

Example 2: Proportional Line Following Variables for Line Following Notes: 1. Kp is the Constant of Proportion. Multiply the "error" to increase the "sensitivity" of the Line follower. 2. offset is the threshold value for dark. Where the robot will travel straight. 3. Tp is the Constant for Power. This is the baseline power for the Left and Right wheels. Method for Line Following: Main Task for Line Following: 2011 Mr. Michaud / www.nebomusic.net 20

Example 3: Wall Following. Using a proportional type algorithm, have the robot track along the wall and maintain a distance of about 40 centimeters. Use a timer and a while loop similar to Line Following to have the Wall Follow work in the main method. Extras: Make the robot stop and scan forward to check for walls and corners. 2011 Mr. Michaud / www.nebomusic.net 21