1 / 48

Programming in RobotC

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?

armina
Download Presentation

Programming in RobotC

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Programming in RobotC

  2. Setting Menu Level Open Up the Advanced Options

  3. Setting Platform Type

  4. Connecting Bluetooth

  5. Connecting Bluetooth

  6. Connecting Bluetooth 1234

  7. Connecting Bluetooth

  8. Connecting Bluetooth

  9. What is a Firmware Download? When to download the firmware? Needed: USB Connection to the laptop Battery Power Firmware Download

  10. Downloading the Firmware Select the firmware file From this next screen

  11. Name your NXT to your Team # Renaming your NXT

  12. NXT and motor controller

  13. Motors and Sensor Setup Robot ->Motors and Sensor Setup

  14. Pragma Configurations

  15. Sample Programs 1) RobotC: File -> Open Sample Program 2) Say Watt: http://github.com/SayWatt

  16. Autonomous • The First Program (Move Forward) • Go Forward & Turn • Light Detection w/ Light Sensor • Ultrasound

  17. First Program Let’s make the robot move! task main() { motor[leftMotor] = 100; motor[rightMotor] = 100; wait1Msec(2000); motor[leftMotor] = 0; motor[rightMotor] = 0; }

  18. task main() { Tells RobotC: Start Here!

  19. motor[leftMotor] = 100;motor[rightMotor] = 100; Make leftMotor and rightMotor go forward at full speed.

  20. wait1Msec(2000); Wait 2000 milliseconds. (2 seconds)

  21. motor[leftMotor] = 0;motor[rightMotor] = 0; Make leftMotor and rightMotor stop.

  22. } Tells RobotC: We’re done.

  23. Go Forward & Turn - Timer task main() { motor[leftMotor] = 100; motor[rightMotor] = 100; wait1Msec(2000); motor[leftMotor] = 75; motor[rightMotor] = -75; wait1Msec(1000); }

  24. Up Next: Ultrasound

  25. while(SensorValue(mysonar) > 20) { Checks this “Keep looping through this until the value of ‘mysonar’ is less than 20.”

  26. Line Detection with Light Sensor

  27. 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; • }

  28. Wait For Start #include “JoystickDriver.c” in beginning of code

  29. General Programming • Function • Passing Values

  30. Functions

  31. Basic Functions void startMotors() { motor[leftMotor] = 100; motor[rightMotor] = 100; } void stopMotors() { motor[leftMotor] = 0; motor[rightMotor] = 0; }

  32. Passing Values void setMotors(int speed) { motor[leftMotor] = speed; motor[rightMotor] = speed; } Examples: or setMotors(100); setMotors(0);

  33. Teleop

  34. Analog Sticks joystick.joy1_y1; joystick.joy1_x1; joystick.joy1_y2; …..

  35. Buttons Returns a bool. joy1Btn(1); joy1Btn(2); …

  36. Basic Joystick Code #include "JoystickDriver.c" task main() { while(true) { getJoystickSettings(joystick); motor[leftMotor] = joystick.joy1_y1; motor[rightMotor] = joystick.joy1_y2; wait1Msec(20); } }

  37. Running Joystick Programs

  38. “Joystick Drift”

  39. Fixing Drift intleftMotorValue = joystick.joy1_y1; intrightMotorValue = joystick.joy1_y2; if(abs(leftMotorValue) < 20) { leftMotorValue = 0; } if(abs(rightMotorValue) < 20) { rightMotorValue = 0; }

  40. Wait For Start #include “JoystickDriver.c” in beginning of code

  41. Wait For Start

  42. Advanced Autonomous Built-in Encoder Home in on with IR Seeker Standard Servo Manipulation

  43. Built-In Encoder nMotorEncoder[motorA] = 0; while (nMotorEncoder[motorA] < 720) /* wait til movement is complete */ { motor[motorA] = 100; motor[motorB] = 100; }

  44. 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; } } }

  45. Standard Servo Manipulation

  46. Advanced Teleop Continuous Rotation Servo w/ Joystick

  47. Continuous Rotation Servo

  48. Other Resources • www.saywatt.org • www.robotc.net • www.hitechnic.com • www.chiefdelphi.com

More Related