Programming in RobotC<br />Introduction to<br />
Installing RobotC<br />http://robotc.net/<br />3.0 Mindstorms<br />License ID: 60857910<br />Password: S9WY95<br />
Setting Menu Level<br />Open Up the Advanced Options<br />
Connecting Bluetooth<br />
Connecting Bluetooth<br />
Connecting Bluetooth<br />1234<br />
Connecting Bluetooth<br />
Connecting Bluetooth<br />
Sample Programs<br />RobotC: File -> Open Sample Program<br />Say Watt: http://github.com/SayWatt<br />
First Program<br />Let’s make the robot move!<br />task main() {<br />	motor[leftMotor] = 100;<br />	motor[rightMotor] = 1...
task main() {<br />Tells RobotC:  Start Here!<br />
motor[leftMotor] = 100;motor[rightMotor] = 100;<br />Make leftMotor and<br />rightMotor go forward<br />at full speed.<br />
wait1Msec(2000);<br />Wait 2000 milliseconds.<br />(2 seconds)<br />
motor[leftMotor] = 0;motor[rightMotor] = 0;<br />Make leftMotor and<br />rightMotor stop.<br />
}<br />Tells RobotC: We’re done.<br />
Up Next: Touch Sensor<br />task main() {<br />	motor[leftMotor] = 100;<br />	motor[rightMotor] = 100;<br />	while(SensorVa...
while(SensorValue(touch) != 1) {<br />Checks this<br />“Keep looping through this<br />until the value of<br />‘touch’ equ...
What’s Next?<br />Try to make these changes:<br />Move backwards for 2 sec.<br />	after the button is pressed.<br />Try tu...
Light Sensor<br />task main() {<br />  motor[leftMotor] = 100;<br />  motor[rightMotor] = 100;<br />  while(SensorValue(li...
Functions<br />
Basic Functions<br />void startMotors() {<br />  motor[leftMotor] = 100;<br />  motor[rightMotor] = 100;<br />}<br />void ...
Passing Values<br />void setMotors(int speed) {<br />  motor[leftMotor] = speed;<br />  motor[rightMotor] = speed;<br />}<...
Light Sensor Function<br />True / False<br />boolcheckLightSensor() {<br />  if(SensorValue(light) <= 45) {<br />    retur...
Line Following<br />Use the light sensor<br />to follow a white<br />line.<br />
Joysticks<br />
3.00 Joystick Bug<br />Open the JoystickDriver.c<br />Change line 123 to:<br />const intkMaxSizeOfMessage = 19;<br />
Analog Sticks<br />joystick.joy1_y1;<br />joystick.joy1_x1;<br />joystick.joy1_y2;<br />…..<br />
Buttons<br />Returns a bool.<br />joy1Btn(1);<br />joy1Btn(2);<br />…<br />
Basic Joystick Code<br />task main() {<br />  while(true) {<br />getJoystickSettings(joystick);<br />    motor[leftMotor] ...
“Joystick Drift”<br />
Fixing Drift<br />intleftMotorValue = joystick.joy1_y1;<br />intrightMotorValue = joystick.joy1_y2;<br />if(abs(leftMotorV...
Wait For Start<br />
Upcoming SlideShare
Loading in …5
×

Introduction to RobotC

3,043 views
2,842 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

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,043
On SlideShare
0
From Embeds
0
Number of Embeds
1,262
Actions
Shares
0
Downloads
39
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Introduction to RobotC

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

×