480 likes | 689 Views
Introduction to. Programming in RobotC. Setting Menu Level. Open Up the Advanced Options. Setting Platform Type. Connecting Bluetooth. Connecting Bluetooth. Connecting Bluetooth. 1234. Connecting Bluetooth. Connecting Bluetooth. What is a Firmware Download?
E N D
Introduction to Programming in RobotC
Setting Menu Level Open Up the Advanced Options
Connecting Bluetooth 1234
What is a Firmware Download? When to download the firmware? Needed: USB Connection to the laptop Battery Power Firmware Download
Downloading the Firmware Select the firmware file From this next screen
Name your NXT to your Team # Renaming your NXT
Motors and Sensor Setup Robot ->Motors and Sensor Setup
Sample Programs 1) RobotC: File -> Open Sample Program 2) Say Watt: http://github.com/SayWatt
Autonomous • The First Program (Move Forward) • Go Forward & Turn • Light Detection w/ Light Sensor • Ultrasound
First Program Let’s make the robot move! task main() { motor[leftMotor] = 100; motor[rightMotor] = 100; wait1Msec(2000); motor[leftMotor] = 0; motor[rightMotor] = 0; }
task main() { Tells RobotC: Start Here!
motor[leftMotor] = 100;motor[rightMotor] = 100; Make leftMotor and rightMotor go forward at full speed.
wait1Msec(2000); Wait 2000 milliseconds. (2 seconds)
motor[leftMotor] = 0;motor[rightMotor] = 0; Make leftMotor and rightMotor stop.
} Tells RobotC: We’re done.
Go Forward & Turn - Timer task main() { motor[leftMotor] = 100; motor[rightMotor] = 100; wait1Msec(2000); motor[leftMotor] = 75; motor[rightMotor] = -75; wait1Msec(1000); }
while(SensorValue(mysonar) > 20) { Checks this “Keep looping through this until the value of ‘mysonar’ is less than 20.”
Line Detection with Light Sensor • // Go until see line • task main() • { • while(SensorValue[S4] < 45) • { • motor[leftMotor] = 50; • motor[rightMotor] = 50; • } • motor[leftMotor] = 0; • motor[rightMotor] = 0; • }
Wait For Start #include “JoystickDriver.c” in beginning of code
General Programming • Function • Passing Values
Basic Functions void startMotors() { motor[leftMotor] = 100; motor[rightMotor] = 100; } void stopMotors() { motor[leftMotor] = 0; motor[rightMotor] = 0; }
Passing Values void setMotors(int speed) { motor[leftMotor] = speed; motor[rightMotor] = speed; } Examples: or setMotors(100); setMotors(0);
Analog Sticks joystick.joy1_y1; joystick.joy1_x1; joystick.joy1_y2; …..
Buttons Returns a bool. joy1Btn(1); joy1Btn(2); …
Basic Joystick Code #include "JoystickDriver.c" task main() { while(true) { getJoystickSettings(joystick); motor[leftMotor] = joystick.joy1_y1; motor[rightMotor] = joystick.joy1_y2; wait1Msec(20); } }
Fixing Drift intleftMotorValue = joystick.joy1_y1; intrightMotorValue = joystick.joy1_y2; if(abs(leftMotorValue) < 20) { leftMotorValue = 0; } if(abs(rightMotorValue) < 20) { rightMotorValue = 0; }
Wait For Start #include “JoystickDriver.c” in beginning of code
Advanced Autonomous Built-in Encoder Home in on with IR Seeker Standard Servo Manipulation
Built-In Encoder nMotorEncoder[motorA] = 0; while (nMotorEncoder[motorA] < 720) /* wait til movement is complete */ { motor[motorA] = 100; motor[motorB] = 100; }
IR Sensor #pragmaconfig(Sensor, S2, IR, sensorHiTechnicIRSeeker1200) #include "drivers/HTIRS2-driver.h" task main() { while(true) { if(SensorValue[IR] == 5) { motor[leftMotor] = 0; //Stop when facing IR motor[rightMotor] = 0; } if(SensorValue[IR] > 5) { motor[leftMotor] = -100; motor[rightMotor] = 100; // turn right } if(SensorValue[IR] < 5) { motor[leftMotor] = 100; // turn left motor[rightMotor] = -100; } } }
Advanced Teleop Continuous Rotation Servo w/ Joystick
Other Resources • www.saywatt.org • www.robotc.net • www.hitechnic.com • www.chiefdelphi.com