Skip to content

1. Basics of robot.xml

Pelle edited this page Apr 18, 2023 · 1 revision

Introduction

The robot.xml is an XML document that describes the configuration of a robot's subsystems. The document contains information about the type of subsystems, the motors, encoders, and PID controllers associated with them. The document is written in XML format and follows a specific syntax.

Syntax

The root element of this XML document is "robot". Within the "robot" element, there are several "subsystem" elements. Each "subsystem" element has a "type" attribute and an "id" attribute. The "type" attribute specifies the type of subsystem, while the "id" attribute provides a unique identifier for the subsystem.

<?xml version="1.0"?>
<robot>
    <subsystem type="Motor" id="armChain">

    </subsystem>

</robot>

Subsystem Element

Each subsystem element has a type attribute that specifies the type of subsystem it is, and an id attribute that uniquely identifies the subsystem. Within each subsystem element, there is a motor or motor group element, which represents the motor(s) that make up the subsystem. To use the motor element, you can include it as a child element of a subsystem element, which groups motors and other components that work together.

The list of Subsystem Types include:

  • Motor
  • Solenoid
  • SwerveDrive
  • TankDrive

Motor Subsystem

The motor element should have the following attributes:

  • id: A unique identifier for the motor.
  • controller: The type of motor controller being used (in this case, sparkmax).
  • port: The port number on the motor controller to which the motor is connected.
  • inverted (optional): A boolean value that specifies whether the motor output is inverted or not.
  • idleMode (optional): The idle mode of the motor, which can be set to break or coast.
  <subsystem type="Motor" id="wrist" >
        <motor id="wrist_motor" controller="sparkmax" port="13" idleMode="break">

        </motor>
    </subsystem>

Encoder Element

The motor element can also contain one or more encoder elements and a pid element. encoder element defines an encoder connected to the motor. It can have the following attributes:

  • id: A unique identifier for the encoder.
  • port: The port number on the motor controller to which the encoder is connected.
  • type (optional): The type of encoder being used, which can be set to relative or absolute.
  • inverted (optional): A boolean value that specifies whether the encoder output is inverted or not.
  • vendor (optional): The vendor or manufacturer of the encoder.
  • port_one (optional): The first port number of the encoder if there are multiple ports.
 <subsystem type="Motor" id="wrist" >
        <motor id="wrist_motor" controller="sparkmax" port="13" idleMode="break">
            <encoder id="wrist_encoder" type="relative" port="encoder"/>
            <encoder id="wrist_hexencoder" type="absolute" port="data" inverted="false"  />
        </motor>
    </subsystem>

PID Element

pid element defines a PID controller for the motor. It can have the following attributes:

  • id: A unique identifier for the PID controller.
  • encoderPort (optional): The encoder port is the port that the encoder is plugged into(data or encoder) this is only used when it is a child element of a motor
  • kp: The proportional gain of the PID controller.
  • ki (optional): The integral gain of the PID controller.
  • kd (optional): The derivative gain of the PID controller.
  • kf (optional): The feedforward gain of the PID controller.
  • kMinOutput (optional): The minimum output of the PID controller.
  • kMaxOutput (optional): The maximum output of the PID controller.
  • distance_per_pulse (optional): The distance traveled by the motor per encoder pulse.
  • setPositionPIDWrappingEnabled (optional): A boolean value that specifies whether the PID controller should wrap setpoints.
  • setPositionPIDWrappingMinInput (optional): The minimum input value for wrapping.
  • setPositionPIDWrappingMaxInput (optional): The maximum input value for wrapping.
<subsystem type="Motor" id="wrist" >
        <motor id="wrist1" controller="sparkmax" port="13" idleMode="break">
            <encoder id="wrist_encoder" type="relative" port="encoder"/>
            <encoder id="wrist_hexencoder" type="absolute" port="data" inverted="false"  />
            <pid id="PID" encoderPort="data" kp="6" ki="0" kd="0" kf="0" kMinOutput="-1.0" kMaxOutput="1.0" distance_per_pulse="6.283185307179586"
                    setPositionPIDWrappingEnabled="true" setPositionPIDWrappingMinInput="0" setPositionPIDWrappingMaxInput="6.283185307179586"/>
        </motor>
    </subsystem>

Solenoid Subsystem

The subsystem element can contain one or more solenoid elements, which are used to define solenoids within the subsystem. The solenoid element can have the following attributes:

  • id: A unique identifier for the solenoid.
  • vendor: The vendor or manufacturer of the solenoid controller (in this case, CTREPCM).
  • port: The port number on the solenoid controller to which the solenoid is connected.
  • type: The type of solenoid being used, which can be set to single or double.
  • inverted (optional): A boolean value that specifies whether the solenoid output is inverted or not.
<subsystem type="Solenoid" id="Solenoid_Subsyststem" >
        <solenoid id="solenoid1" vendor="CTREPCM" port="7" type="single" inverted="true"/>
    </subsystem>

TankDrive Subsystem

The element in this XML code represents a tank drive subsystem, which is commonly used in robotics to control a two-wheel drivetrain. The subsystem consists of two separate motor groups, one for the left side and one for the right side of the drivetrain.

Each motor group is defined by the element and includes one or more motors. In this example, each motor group includes only one motor, which is defined by the element.

 <subsystem type="TankDrive" id="TankDrive">
        <motorgroup id="left">
            <motor id="left1" side="left" controller="sparkmax" port="2" />
        </motorgroup>
        <motorgroup id="right">
            <motor id="right1" side="right" controller="sparkmax" port="8" />
        </motorgroup>
    </subsystem>

SwerveDrive Subsystem

SwerveDrive