XRP
  • Experiential Robotics Platform (XRP)
    • Building the XRP Robo
    • Programming Raspberry Pi Pico W
    • Programming with XRPCode IDE
    • Programming with wpilib
      • Hardware
      • Imaging and Setup
      • Creating an XRP Program
    • Programming with ROS
  • Hardware Components
    • Different Types of Motors
      • Brushed DC Motors
      • Brushless Motor
      • Stepper Motor
      • Servo Motors
    • Key Characteristics of DC Motors
    • Encoders
  • Motor Control Theory
    • What use in FRC
    • PID control (Proportional-Integral-Derivative control)
    • Field Oriented Control (FOV)
  • Use XRP to practice
    • Plotting Fix
    • Reading from the Encoder
    • Measure position
    • Control the motor
    • Tuning PID
  • Use XRP with Micropython
    • Setup Envirrment
    • Use the Shell
    • XRP library
  • Connect with Wifi
Powered by GitBook
On this page
  1. Experiential Robotics Platform (XRP)
  2. Programming with wpilib

Creating an XRP Program

PreviousImaging and SetupNextProgramming with ROS

Last updated 8 months ago

Creating a new program for an XRP is like creating a normal FRC program, similar to the programming steps.

WPILib comes with two templates for XRP projects, including one based on TimedRobot, and a Command-Based project template. Additionally, an example project is provided that showcases some of the built-in functionality of the XRP and shows how to use the vendordep exposed XRP classes. This article will walk through creating a project from this example.

Note

To program the XRP using C++, a compatible C++ desktop compiler must be installed. See .

Creating a New WPILib XRP Project

Bring up the Visual Studio Code command palette with Ctrl+Shift+P, and type “New project” into the prompt. Select the “Create a new project” command:

This will bring up the “New Project Creator Window”. From here, click on “Select a project type (Example or Template)”, and pick “Example” from the prompt that appears:

Next, a list of examples will appear. Scroll through the list to find the “XRP Reference” example:

Fill out the rest of the fields in the “New Project Creator” and click “Generate Project” to create the new robot project.

Running an XRP Program

Once the robot project is generated, it is essentially ready to run. The project has a pre-built Drivetrain class and associated default command that lets you drive the XRP around using a joystick.

One aspect where an XRP project differs from a regular FRC robot project is that the code is not deployed directly to the XRP. Instead, an XRP project runs on your development computer and leverages the WPILib simulation framework to communicate with the XRP.

To run an XRP program, first, ensure that your XRP is powered on. Next, connect to XRP-<IDENT> WiFi network broadcast by the XRP. If you change the XRP network settings (for example, to connect it to your own network), you may change the IP address that your program uses to connect to the XRP. To do this, open the build.gradle file and update the wpi.sim.envVar line to the appropriate IP address.

//Sets the XRP Client Host
wpi.sim.envVar("HALSIMXRP_HOST", "192.168.42.1")
wpi.sim.addXRPClient().defaultEnabled = true

Now to start your XRP robot code, open the WPILib Command Palette (type Ctrl+Shift+P) and select “Simulate Robot Code”, or press F5.

If all goes well, you should see the simulation GUI pop up and see the gyro and accelerometer values updating.

Your XRP code is now running!

Compatible Classes

All classes listed here are supported by the XRP. If a class is not listed here, assume that it is not supported and will not work.

  • Encoder

  • AnalogInput

  • DigitalInput

  • DigitalOutput

  • BuiltInAccelerometer

Here is Robot Simulation:

Here's an example using AnalogInput to return values from the range finder and the reflectance sensor:

  1. Add the import statements for AnalogInputin Drivetrain.java

import edu.wpi.first.wpilibj.AnalogInput;
  1. Define sensor and range finder

private final AnalogInput m_leftSensor = new AnalogInput(0);
private final AnalogInput m_rightSensor = new AnalogInput(1);
private final AnalogInput m_rangefinder = new AnalogInput(2)
  1. Read the values from the three AnalogInput's

  public double getLeftReflectanceValue() {
    return m_leftSensor.getVoltage() / 5.0;
  }

  public double getRightReflectanceValue() {
    return m_rightSensor.getVoltage() / 5.0;
  }

  public double getDistanceMeters() {
    return (m_rangefinder.getVoltage() / 5.0) * 4.0;
  }
  
  public double getDistanceInches() {
    return Units.metersToInches(getDistanceMeters());
  }

By adding this code and running "Simulate Robot Code," you should be able to view the AnalogInput data by clicking on "Hardware" and checking "Analog Inputs."

Now, you should be able to view the data from "Analog Inputs."

The PWM motor controller classes (e.g. Spark) and Servo are not supported. The XRP requires use of specialized XRPMotor and XRPServo classes.

The following classes are provided by the XRP Vendordep (built-in to WPILib).

  • XRPGyro

  • XRPMotor

  • XRPServo

  • XRPOnBoardIO

Zero To Robot
Robot Simulation - Additional C++ Dependency
As can be seen from the image, you'l be able to view all sorts of values like the values from your controller, encoders, analog inputs, and the gyroscope. Also, make sure to set the robot status to teleoperated to actually enable the code.
How to enable monitoring of Analog Inputs