Changes between Version 15 and Version 16 of ControlSystems/SoftwareTeam/Training/GettingStarted/IntroRobotJava
- Timestamp:
- Oct 16, 2019, 12:44:06 AM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/IntroRobotJava
v15 v16 53 53 * Even though the program is running on the robot, you can set breakpoints, step through code, examine and change variables, etc. from your laptop. 54 54 55 * Extra credit: extend the program to print a message or display a value on the Smart Dashboard when a button is pressed on the xbox controller. 56 55 57 == Second program: Ultrasonic Rangefinder 58 59 Robots often need to sense the environment around them, particularly when driving autonomously. Ultrasonic sensors are like the sonar used by bats. They emit a chirp of sound and measure the time it takes to hear an echo of that chirp. The longer the time, the further the sound traveled. Since sound travels at a particular speed through air, we can use the echo delay to calculate how far away the object was that reflected the sound. You can read more about ultrasonic sensors [https://wpilib.screenstepslive.com/s/currentCS/m/java/l/599715-ultrasonic-sensors-measuring-robot-distance-to-a-surface here] 56 60 57 61 Create another program using the !TimedRobot java template and name it !UltrasonicTest. Modify the generated code as follows: … … 72 76 Run the program and observe the "Front range" value in the [https://wpilib.screenstepslive.com/s/currentCS/m/java/l/599724-displaying-data-on-the-ds-dashboard-overview Smart Dashboard] as you move the robot towards and away from the wall. 73 77 78 Notice that the measurements aren't always perfect; the sensor may receive echos from multiple surfaces. 79 74 80 == Third program: Servo Motor Control 81 82 Robots must be able to interact with the environment around them too. Many types of actuators are used in FRC robotics; one of them is the [https://wpilib.screenstepslive.com/s/currentCS/m/java/l/599703-repeatable-low-power-movement-controlling-servos-with-wpilib Servo Motor]. A servo motor is a special type of motor that can rotate to a precise position, usually between 0 and 180 degrees. They come in a variety of sizes and strengths. You can connect a servo motor to any of the PWM ports on the !RoboRIO. Examine the PWM ports and identify which row of pins are ground ([[Image(https://incompliancemag.com/wp-content/uploads/2012/01/1201_OnYourMark_5019.png, 50px)]], +6V, and Signal (S). Make sure you connect them to the proper pins on the Servo motor: black or brown goes to Ground, red or orange goes to +6V, yellow/white/blue goes to Signal. You can read more about servo motors [https://learn.sparkfun.com/tutorials/servo-trigger-hookup-guide/all here] 75 83 76 84 Create another program using the !TimedRobot java template and name it !ServoTest. Modify the generated code as follows: … … 104 112 105 113 Connect a Servo motor to PWM port 1 on the roboRIO and run your program. You'll need to press the Enable button on the driver station to put the robot in Teleop mode so that teleopPeriodic() is called repeatedly. 114 115 * Extra credit: use buttons on the Xbox controller to set the servo to a specific position (e.g. 45-degrees, 90-degrees, 135-degrees). 106 116 107 117 == Fourth program: DC Motor Control