Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is...

27
Programming - Motion Intro to Robotics

description

Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose ROBOT, then MOTORS AND SENSORS SETUP.

Transcript of Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is...

Page 1: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Programming - Motion

Intro to Robotics

Page 2: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.
Page 3: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Motors and Sensors SetupThe first thing we need to do is tell ROBOTC that we have motors on our robot.

Choose ROBOT , then MOTORS AND SENSORS SETUP.

Page 4: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Motors and Sensors SetupYou will notice that there are THREE tabs. One for Motors, Analog Sensors, and Digital Sensors.

Choose the Motors Tab.

In port 2 “Name” type in Rmotor and for ports 3 type in Lmotor.

Then select MOTOR EQUIPPED from the type drop down menu.Click APPLY , then OK.

Page 5: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Motor CommandThe motor command tells the robot to run a motor at a given power level. The example below sets the motor on port 3 to run at full power forwards. Remember, every command ends with a semicolon.

Page 6: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Wait Command

The comment wait1Msec tells the robot to wait before it executes the next command, for a given time in milliseconds. The value in parenthesis is the amount of time you want the robot to wait. 3000Ms is equal to 3 seconds.

Page 7: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Let’s Begin

You will notice that at the top there are PRAGMA statements. These are automatically generated configuration statements and will ALWAYS be at the very top of the program.

Page 8: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Let’s compileIf it asks you to save, call it motion lesson 1.

WHAT HAPPENED?

Page 9: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Compile ErrorsErrors have different colors and are displayed next to the code line number where there is a problem. Here we see a problem in line 9.

Errors are explained in a little bit more detail below. If you have no errors, then the program compiled correctly.

Page 10: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Compiled Correctly

Page 11: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Attaching to a PC

Use a USB cable to connect the robot to the PC. It is often an ORANGE cable.

Turn the Cortex on.

Page 12: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Check the platform type

Page 13: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Check the download method

Page 14: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Compile and download

Possible errors:•Cortex power on? If not, RobotC may ask you to turn on the battery.•Can’t find the COM port? If not, unplug the USB cable with the cortex powered on, then re-insert and try again.

Page 15: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.
Page 16: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

What happened????

Page 17: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Motors and Sensors Setup

Page 18: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Motors and Sensors Setup

Check here! (or port 3?)

RobotC will make the change in the #PRAGMA statement.

Page 19: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.
Page 20: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.
Page 21: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Modify this code. Since we are moving at half power lets double our time.

Page 22: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Modify the code, then compile and download. Note what happens.

Page 23: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Modify the code below, then compile and download each time. Note what happens.

Page 24: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.
Page 25: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Manual Straightening To compensate for the differences between the motors, we

could either speed up the slower motor or slow down the faster one. Let’s slow down the faster one.

Page 26: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Save your code

Save the code with a filename you will remember in your MY DOCUMENTS folder.

Page 27: Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.

Challenge

Using what you have learned, write a program that will allow you navigate the labyrinth in the arena. You MUST use comments to explain in the code what you are doing. Place group member names in the comments at the bottom of the code.