ROBOTC

Custom Joystick Controls

From ROBOTC API Guide
Jump to: navigation, search
General Programming ? Custom Joystick Control


Custom Joystick configuration options are included in ROBOTC 3.61 BETA and higher.

Contents

 [hide
Color Key
Function:
Variable:


[edit] Custom Joystick Controls

Starting with ROBOTC 3.61 BETA, users now have the option to create custom joystick configurations inside of ROBOTC. This allows a wider variety of joysticks to be used with ROBOTC (such as the XBOX 360 controller) and also allows users to set custom configurations for existing controllers. This functionality can be used with the VEX Cortex, Lego NXT/TETRIX, and Virtual Worlds.

Note that the custom controller configuration options cannot be used in an FTC competition, due to the way the Field Control System (FCS) handles joystick controls.

Also note that the joystick settings are currently universal across all joysticks and changes made to one particular joystick's configuration may not work for other joysticks.


[edit] Setting the Menu Level

Before you are able to configure a custom joystick layout, ROBOTC's menu level will need to be set to 'Expert' or 'Super User' level. You can change this setting from the 'Window -> Menu Level' menu in ROBOTC.
Menu Level Super.png


[edit] Creating a Custom Configuration

Once the menu level is set, there will be a new option in the 'Window' menu in ROBOTC called 'Configure Joysticks'.
Window Config Joysticks.png

Clicking on this menu option will bring up the Controller Configuration Utility window, which will be used to configure a custom controller layout.
Config Joysticks Main.png

To start configuring the joystick settings, make sure the joystick you wish to configure appears in the 'Current Controller' field. If the joystick does not appear in the field automatically, click the 'Refresh' button to search for the joystick again.
Configure Joysticks Refresh.png

After the correct joystick is selected, check the 'Custom Joystick Config' box to enable custom configuration options for the joystick. Unchecking this box will revert the joystick settings to the ROBOTC defaults. Remember, the joystick settings are universal across all joysticks, so changes made to one particular joystick's configuration may not work for another joystick. You can view the values ROBOTC will receive for the selected settings by viewing the 'Current Value' fields.
Configure Joysticks Checkbox.png

The ROBOTC Name field displays the name used by ROBOTC when using the joystick values in a program. In the example below, the left X axis is assigned to the joy1_x1 axis. When the joy1_x1 axis is subsequently called in a program, it will then use values from the left X axis. For more information on how to program a joystick by using the custom configuration, see the example below under the 'Programming with the custom layout' section.
Configure Joysticks Settings.png

You can also view the values returned by the different buttons, which are shown under the 'Buttons' section. To save the settings, simply click the OK button.
Configure Joysticks Buttons.png

[edit] Programming with the custom layout

You can use the custom controller values to program your robot in ROBOTC by using the existing joystick commands: there are no special functions or commands that are needed for a customer controller configuration. For example, let's assume we have an Xbox 360 controller set up as shown below:
Configure Joysticks Setup.png

Using the '2 Joystick Drive with Threshold.c' program (found in the 'Remote Control' Sample Programs folder'), we can see that the 'joystick.joy1_y2' command will use values returned from the Right Y Axis and the 'joystick.joy1_y1' command will use values returned from the Left Y Axis.
#pragma debuggerWindows("joystickSimple");
#include "JoystickDriver.c"
 
task main()
{
  //Integer variable that allows you to specify a "deadzone" where values (both positive or negative)
  //less than the threshold will be ignored.
  int threshold = 10;
 
  //Loop Forever
  while(1 == 1)
  {
    //Get the Latest joystick values
    getJoystickSettings(joystick);
    if(abs(joystick.joy1_y2) > threshold)     // If the right analog stick's Y-axis readings are either above or below the threshold...
    {
      motor[rightMotor] = joystick.joy1_y2;   // ...the right motor is assigned a power level equal to the right analog stick's Y-axis reading.
    }
    else                                      // Else the readings are within the threshold, so
    {
      motor[rightMotor] = 0;                  // ...the right motor is stopped with a power level of 0.
    }
 
 
    if(abs(joystick.joy1_y1) > threshold)     // If the left analog stick's Y-axis readings are either above or below the threshold...
    {
      motor[leftMotor] = joystick.joy1_y1;    // ...the left motor is assigned a power level equal to the left analog stick's Y-axis reading.
    }
    else                                      // Else if the readings are within the threshold...
    {
      motor[leftMotor] = 0;                   // ...the left motor is stopped with a power level of 0.
    }
  }
}