![]() |
Code for Ultrasonic Sensor
We have our sensor set up as digital but we are having trouble understanding how to use it. Could someone give us a run down on how to use it? Thanks :D
|
Re: Code for Ultrasonic Sensor
In general, an ultrasonic sensor gives you a number. The number corresponds to distance. You can use that distance to (for example) calculate how far the robot needs to move, then move that distance.
For more specific instructions, it might be helpful if you specified which ultrasonic sensor you are using. |
Re: Code for Ultrasonic Sensor
Quote:
|
Re: Code for Ultrasonic Sensor
I'm assuming that your sensor is a MaxBotix MB1013 and that the following is the data sheet for your sensor.
http://www.maxbotix.com/documents/HR..._Datasheet.pdf Assuming that is your sensor, I would recommend that you start with pins 3, 6 and 7 on the sensor and connect them to an analog input on the roboRIO (refer to the data sheet to determine how they should be connected). The following class could then be used to display readings from the sensor on the SmartDashboard to help you determine how the voltage output from the sensor corresponds to distance. You will need to determine the constant (VOLTS_TO_DIST) to convert the voltage to a real world distance (if you want to work in real world units instead of voltage). Code:
package org.usfirst.frc.team868.robot.sensors; |
Re: Code for Ultrasonic Sensor
This is a great example, thank you!
in a command based situation, would you add this code as its own class, like a subsystem or would you add this to an existing class...? |
Re: Code for Ultrasonic Sensor
In a command based robot, I would be tempted to refactor the example into its own Subsystem.
However, this could be thought of as a special "read only" type of subsystems. Commands that made use of this subsystem would not need to require() it in their constructors as there isn't a problem if multiple commands take distance measurements at the same time. If two commands both want to get distance measurements, it isn't a problem like it is if two commands both want to manipulate drive motors. Alternatively, I might be tempted to leave it as its own stand alone class (not make it a subsystem) and just use it as is. |
Re: Code for Ultrasonic Sensor
Quote:
Quote:
You can do digital via RS232, but it is much easier to do analog. |
| All times are GMT -5. The time now is 15:35. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi