Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# Introduction to RobotC

2,676
views

Published on

An introduction to RobotC given by the Say Watt robotics team. The example files shown here are also posted online: http://github.com/SayWatt

An introduction to RobotC given by the Say Watt robotics team. The example files shown here are also posted online: http://github.com/SayWatt

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
2,676
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
36
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. Programming in RobotC
Introduction to
• 2. Installing RobotC
http://robotc.net/
3.0 Mindstorms
• 4. Connecting Bluetooth
• 5. Connecting Bluetooth
• 6. Connecting Bluetooth
1234
• 7. Connecting Bluetooth
• 8. Connecting Bluetooth
• 9. Sample Programs
RobotC: File -> Open Sample Program
Say Watt: http://github.com/SayWatt
• 10. First Program
Let’s make the robot move!
motor[leftMotor] = 100;
motor[rightMotor] = 100;
wait1Msec(2000);
motor[leftMotor] = 0;
motor[rightMotor] = 0;
}
Tells RobotC: Start Here!
• 12. motor[leftMotor] = 100;motor[rightMotor] = 100;
Make leftMotor and
rightMotor go forward
at full speed.
• 13. wait1Msec(2000);
Wait 2000 milliseconds.
(2 seconds)
• 14. motor[leftMotor] = 0;motor[rightMotor] = 0;
Make leftMotor and
rightMotor stop.
• 15. }
Tells RobotC: We’re done.
• 16. Up Next: Touch Sensor
motor[leftMotor] = 100;
motor[rightMotor] = 100;
while(SensorValue(touch) != 1) {
wait1Msec(50);
}
motor[leftMotor] = 0;
motor[rightMotor] = 0;
}
• 17. while(SensorValue(touch) != 1) {
Checks this
“Keep looping through this
until the value of
‘touch’ equals 1.”
• 18. What’s Next?
Try to make these changes:
Move backwards for 2 sec.
after the button is pressed.
Try turning around and going
the other way.
• 19. Light Sensor
motor[leftMotor] = 100;
motor[rightMotor] = 100;
while(SensorValue(light) <= 45) {
wait1Msec(50);
}
motor[leftMotor] = 0;
motor[rightMotor] = 0;
}
• 20. Functions
• 21. Basic Functions
void startMotors() {
motor[leftMotor] = 100;
motor[rightMotor] = 100;
}
void stopMotors() {
motor[leftMotor] = 0;
motor[rightMotor] = 0;
}
• 22. Passing Values
void setMotors(int speed) {
motor[leftMotor] = speed;
motor[rightMotor] = speed;
}
Examples:
or
setMotors(100);
setMotors(0);
• 23. Light Sensor Function
True / False
boolcheckLightSensor() {
if(SensorValue(light) <= 45) {
return true;
}else {
return false;
}
}
• 24. Line Following
Use the light sensor
line.
• 25. Joysticks
• 26. 3.00 Joystick Bug
Open the JoystickDriver.c
Change line 123 to:
const intkMaxSizeOfMessage = 19;
• 27. Analog Sticks
joystick.joy1_y1;
joystick.joy1_x1;
joystick.joy1_y2;
…..
• 28. Buttons
Returns a bool.
joy1Btn(1);
joy1Btn(2);

• 29. Basic Joystick Code
while(true) {
getJoystickSettings(joystick);
motor[leftMotor] = joystick.joy1_y1;
motor[rightMotor] = joystick.joy1_y2;
wait1Msec(20);
}
}
• 30. “Joystick Drift”
• 31. Fixing Drift
intleftMotorValue = joystick.joy1_y1;
intrightMotorValue = joystick.joy1_y2;
if(abs(leftMotorValue) < 20) {
leftMotorValue = 0;
}
if(abs(rightMotorValue) < 20) {
rightMotorValue = 0;
}
• 32. Wait For Start
• 33. Wait For Start