I have 2 frc programming question

hey guys. i have two frc programming problems.

  1. we are using a VersaPlanetary Integrated Encoder that connects directly to a TalonSRX motor, however we don’t know where to find the corresponding channel numbers on the phoenix tuner. i want to watch it on the shuffle board. where can i find it and can anyone provide me with some java example code?

  2. we are using the ultrasonic sensors, but i don’t know where to find the ping channel and echo channel. what i merely known is that there are 3 pins to connect on roboRio to power up the sensors (Volt power, Ground, Analog Output). i need ping channel and echo channel so that i can programming them in java.

I could be wrong, but regarding the ultrasonic question, most of the ultrasonic sensors I have used do the processing of the ping and echo delta on-board (as in, literally on the board of the ultrasonic). In other words, the sensor simply outputs an analog value that correlates to the time difference between the two.


Not 100% sure how to help here, but this line in the CTRE Example Code shows setting up an auxiliary sensor on an SRX, and this line in the same file shows reading the sensor value back out. It might not exactly be what you need, but they do have other similar examples?

Ultrasonic Sensor

There are a number of different ultrasonic models. All work fundamentally by sending out a pulse of sound, and measuring the duration for the echo to return. Assuming the speed of sound is known, you can calculate distance.

Many do this calculation with onboard processing, like the Maxbotix devices that are often donated to FRC teams.

Other, cheaper ones rely on the host processor (the RIO) to do that processing.


OP - got any info on what specific sensor you have? Usually Brand and Part-Number is good enough to uniquely identify the model, though pictures help too. That in turn can inform how to wire and program it.

1 Like

Similar to what @gerthworm said regarding the Talon SRX, there are more ways to do it.

Set up the Talon SRX and call the configSelectedFeedbackSensor method to connect that Talon SRX and the magnetic encoder it uses.

Once you finish there, you can call the “getter” method as needed. I recommend using something similar to the following:

WPI_TalonSRX  myTalon = new WPI_TalonSRX(0);                   // Create the talon object.
double position = myTalon.getSelectedSensorPosition();         // Get the position of the talon object.

This should be the correct Java code. Java is not my “first language”!

Anyway, the shuffleboard application relies on network table values. Assuming you have a table created (if it’s commandbased I recommend that you have a table per subsystem), you can call something similar to the following:

// In the constructor:
NetworkTable table = inst.getTable("drivetrain");
double p = table.getEntry("position");
// Later in the code:

The code above would, in theory, populate a network table entry with a key of “position” and a value of the encoder reading.

The shuffleboard application can use this with something similar to the following:

SmartDashboard.putNumber("Encoder position", p.setDouble(myTalon.getSelectedSensorPosition()));

I hope this provides some clarity. You can read more about smart dashboard here!

Feel free to respond with any more questions!

As far as the ultrasonic goes, I am pretty certain that @Cyberphil was correct with this one. We could help a bit more if you post the model, but usually when an Ultrasonic sensor has an analog out, it is processing the signal and trigger for you (I think the Maxbotics pieces can be wired either way). So the voltage changes based on the distance. I would take some measurements at known distances and then use that to determine ranges. Many manufacturers publish distances and readings.

As a side note, the analog sensors are great with the Romi as the echo trigger ones do not work well.

we are prgramming it in java (timed robot). we are using MB1043 module. this is the current code i have done.

Ultrasonic rearUltrasonic = new Ultrasonic(rearUltrasonicPingChannel, rearUltrasonicEchoChannel);

  public void robotInit() {

  public void robotPeriodic() {
    SmartDashboard.putNumber("rearUltrasonic", rearUltrasonic.getRangeInches());

i still don’t know where to find the ping channel and echo channel.

Looking at this, it seems like the ultrasonic sensor outputs a single analog and/or PWM signal. Check out the Analog Section on WPILib Docs: Ultrasonics - Software — FIRST Robotics Competition documentation.
Or you can use the PWM class: PWM (Documentation - Beta API)
the Counter class: Counters — FIRST Robotics Competition documentation

EDIT: Thanks @Joe_Ross for pointing out my mistake.

The PWM class is for generating PWM signals for motor controllers, not for reading PWM signals. Depending on how the signal is constructed it may be possible to use the Counter class or DutyCycleEncoder class. But using the Analog pin with AnalogInput would be much simpler.

1 Like

The Maxbotix type ultrasonic sensors can be bought really cheaply off Alibaba.

My friend got a couple for like 2 dollars a piece for a project once, just had like 2-3 weeks shipping time.

1 Like


As others have suggested, connect these three pins to an analog input on the RIO.

1 Like

Last year we got a lot of these from First Choice. They work really well with the Romi, and we were able to send them home with students. I will find their datasheet. There have already been many excellent posts about how to set them up, but if you have other questions, I may be able to help with coding issues.

Edit: I think this page may help. The WPI code just sends the voltage (from v+) and reads the return (on the analog in channel) so it only needs the one cable.

Look at the first tutorial. It gives the formula.

[(Vcc/1024) = Vi]
Vcc = Supplied Voltage
Vi = Volts per 5 mm (Scaling)

Example 1: Say you have an input voltage of +5.0V the formula would read:

[(5.0V/1024) = 0.004883V per 5 mm = 4.883mV per 5 mm]

This is another good article they link to.