Difference between revisions of "Joystick and Gamepad"

From Wiki
(Debug mode)
(Gamepad on embedded control removed)
 
(4 intermediate revisions by the same user not shown)
Line 30: Line 30:
 
** top: select next command (since V13-030)
 
** top: select next command (since V13-030)
  
= Button binding configuration =
+
 
 +
= Configuring buttons via iRC/CPRog =
 +
From V14-003 the functions of the gamepad button can be easily configured within iRC. If you are using an older version please read the section on manual configuration.
 +
 
 +
You can find the gamepad configuration by clicking "File" -> "Configure Interfaces" -> "Gamepad". The following sections explain the functions and parameters.
 +
 
 +
== General section ==
 +
In the general section you find the following settings:
 +
* Use standard layout: Setting this resets the custom button configuration.
 +
* Enable debug mode: Some gamepads send button presses by a different button ID than what iRC expects. Check this and click apply and open the log view below the 3D view. When you push buttons their IDs are written to the log. Find this ID in the gamepad configuration. Disable debug mode when you do not need it.
 +
* Default bias: This sets the dead zone of the thumbsticks / joysticks to decrease drift when not pushed. When using a custom configuration this value can be overwritten for each axis.
 +
 
 +
== Thumbsticks / Joysticks section ==
 +
This section allows configuring up to 3 analog thumbstick / joystick axes (even if your gamepad has 4 or more directions only 3 are reported to iRC).
 +
 
 +
If a stick drifts you can set the bias instead of the default bias.
 +
 
 +
To add a function select one in the selection box and click Add function. If you assign more than one function all are called at once. For jog motion note the selection box "When alternative is selected" - this only applies the motion if the box is not checked and the alternative is not selected (see function "Switch Alternative Joints") or if it is checked and the alternative is selected.
 +
 
 +
== Buttons section ==
 +
This section allows configuring the digital buttons. You may assign more than one function to a button.
 +
 
 +
== Available functions ==
 +
=== Switch Alternative Joints ===
 +
Switches between standard and alternative axis for jog motion. E.g. to make a stick normally move A1 but if the alternative joints button is pressed move A4 instead. This allows using three joystick axes for moving a robot with up to 6 axes, or to switch between cartesian translation and rotation.
 +
 
 +
=== Digital Output ===
 +
Changes a digital output. This can be toggled, set high/low or temporarily held high/low and fall back to the opposite when released.
 +
 
 +
=== Global Signal ===
 +
Same as digital output but for global signals
 +
 
 +
=== Jog Motion ===
 +
Jogs an axis depending on the selected motion mode (joint, cart base, cart tool, platform). If "When alternative is selected" box is checked the motion is only done when the alternative is selected (see function "Switch Alternative Joints") or the other way. You can set a joint, a cartesian axis and a mobile platform axis - use the "Change Jog Mode" function to change the jog mode.
 +
 
 +
=== Change Reference Frame ===
 +
Changes the reference frame (base or tool coordinates) or user frame. This affects jog motion when mode "Cartesian Base" is selected or #base in the ribbon above the 3D view is selected.
 +
 
 +
=== Change Jog Mode ===
 +
Changes the jog mode between joints, cartesian base, cartesian tool and mobile platform (if available). See the jog mode selection above the 3D view.
 +
 
 +
=== Change Velocity ===
 +
Changes the motion velocity. See the velocity override (0-100%) above the 3D view.
 +
 
 +
=== Control Program ===
 +
This function allows starting, stopping and pausing a program.
 +
 
 +
=== Edit Program ===
 +
This function is intended for teach-in programming. Depending on the selected mode it will change the command that is selected in the program editor, add joint or linear commands or delete the selected command.
 +
 
 +
= Manual button binding configuration on PC =
 
Since version 13-031 the configuration can be changed via the project configuration file.
 
Since version 13-031 the configuration can be changed via the project configuration file.
  
Line 131: Line 181:
 
Selects the alternative axis assignment. If toggle is false the standard set is re-selected after the button is released.
 
Selects the alternative axis assignment. If toggle is false the standard set is re-selected after the button is released.
  
= Debug Mode =
+
== Bias and Thumb Stick Drift ==
 +
It is common that the analog thumb sticks return to a rest position that differs from 0 which can lead to axes seemingly move on their own. The bias parameters solve this by defining a threshold within which the stick position is considered exactly 0.
 +
 
 +
The bias can be set in two places:
 +
* The Joypad line defines the bias for all axes that do not explicitly set a different value:
 +
  <Joypad Bias="10.0">
 +
* The Analog lines define the axis specific bias. If the value is less than 0 the default value is used.
 +
  <Analog Num="1" Bias="-1">
 +
 
 +
A bias of 10 should work for most gamepads but since it differs between devices you may need to try higher values. The maximum bias is 128.
 +
 
 +
== Debug Mode ==
 
If enabled the debug mode writes button events to the log (see the log tab at the bottom left of CPRog/iRC). This is useful for finding the number of a button.
 
If enabled the debug mode writes button events to the log (see the log tab at the bottom left of CPRog/iRC). This is useful for finding the number of a button.
  
 
Debug mode is available since V13-040.
 
Debug mode is available since V13-040.
  
[[Category:CPRog]]
+
To enable the debug mode change the parameter "Debug" to "True":
 +
  <Joypad Bias="10.0" Debug="True">
 +
 
 +
Note that some buttons may not show. E.g. the direction keys may be handled in a different way than the other buttons, in which case you should try numbers 1000-1003 as mentioned in the previous section.
 +
 
 +
[[Category:Configuration]][[Category:CPRog]][[Category:TinyCtrl]]

Latest revision as of 08:54, 28 June 2024

Most PC compatible joysticks and gamepads can be used as a cheap and simple solution for moving a robot. This is useful for quickly teaching positions.

Required are:

  • DirectX compatible gamepad or joystick
  • PC with CPRog or iRC connected to the robot

Earlier versions of CPRog/iRC have a static button binding. While version 13-030 and later can be configured. This article explains both.

Default button binding

The following button binding is used on versions up to 13-030 and in later versions when no custom bindings are defined: (read the stick assignment as joint/cartesian/platform)

  • Left thumb stick horizontal: A1/Y/X; alternative A4/B/X
  • Left thumb stick vertical: A2/X/Y; alternative A5/A/Y
  • Right thumb stick vertical: A3/Z/Ori; alternative A6/C/Ori
  • Right thumb stick horizontal: velocity override (not assigned since V13-030)
  • L1 and R1: velocity override (since V13-030)
  • L2: Change motion mode (joints, cart base, cart tool, platform)
  • R2: Alternative assignment of thumb sticks while pressed
  • right buttons:
    • top: touch-up (since V13-030)
    • right: add joint command
    • bottom: add linear command
    • left: remove selected command (since V13-030)
  • left buttons:
    • top: select previous command (since V13-030)
    • top: select next command (since V13-030)


Configuring buttons via iRC/CPRog

From V14-003 the functions of the gamepad button can be easily configured within iRC. If you are using an older version please read the section on manual configuration.

You can find the gamepad configuration by clicking "File" -> "Configure Interfaces" -> "Gamepad". The following sections explain the functions and parameters.

General section

In the general section you find the following settings:

  • Use standard layout: Setting this resets the custom button configuration.
  • Enable debug mode: Some gamepads send button presses by a different button ID than what iRC expects. Check this and click apply and open the log view below the 3D view. When you push buttons their IDs are written to the log. Find this ID in the gamepad configuration. Disable debug mode when you do not need it.
  • Default bias: This sets the dead zone of the thumbsticks / joysticks to decrease drift when not pushed. When using a custom configuration this value can be overwritten for each axis.

Thumbsticks / Joysticks section

This section allows configuring up to 3 analog thumbstick / joystick axes (even if your gamepad has 4 or more directions only 3 are reported to iRC).

If a stick drifts you can set the bias instead of the default bias.

To add a function select one in the selection box and click Add function. If you assign more than one function all are called at once. For jog motion note the selection box "When alternative is selected" - this only applies the motion if the box is not checked and the alternative is not selected (see function "Switch Alternative Joints") or if it is checked and the alternative is selected.

Buttons section

This section allows configuring the digital buttons. You may assign more than one function to a button.

Available functions

Switch Alternative Joints

Switches between standard and alternative axis for jog motion. E.g. to make a stick normally move A1 but if the alternative joints button is pressed move A4 instead. This allows using three joystick axes for moving a robot with up to 6 axes, or to switch between cartesian translation and rotation.

Digital Output

Changes a digital output. This can be toggled, set high/low or temporarily held high/low and fall back to the opposite when released.

Global Signal

Same as digital output but for global signals

Jog Motion

Jogs an axis depending on the selected motion mode (joint, cart base, cart tool, platform). If "When alternative is selected" box is checked the motion is only done when the alternative is selected (see function "Switch Alternative Joints") or the other way. You can set a joint, a cartesian axis and a mobile platform axis - use the "Change Jog Mode" function to change the jog mode.

Change Reference Frame

Changes the reference frame (base or tool coordinates) or user frame. This affects jog motion when mode "Cartesian Base" is selected or #base in the ribbon above the 3D view is selected.

Change Jog Mode

Changes the jog mode between joints, cartesian base, cartesian tool and mobile platform (if available). See the jog mode selection above the 3D view.

Change Velocity

Changes the motion velocity. See the velocity override (0-100%) above the 3D view.

Control Program

This function allows starting, stopping and pausing a program.

Edit Program

This function is intended for teach-in programming. Depending on the selected mode it will change the command that is selected in the program editor, add joint or linear commands or delete the selected command.

Manual button binding configuration on PC

Since version 13-031 the configuration can be changed via the project configuration file.

The following example represents the standard configuration as described in the previous article:

<ProjectFile>
[...]
<Environment>
<Joypad Bias="10.0" Debug="False">
	<Button Num="0"><ProgramEdit Change="TouchUp" /></Button>
	<Button Num="1"><ProgramEdit Change="AddJoint" /></Button>
	<Button Num="2"><ProgramEdit Change="AddLinear" /></Button>
	<Button Num="3"><ProgramEdit Change="Remove" /></Button>
	<Button Num="4"><Override Change="Lower" /></Button>
	<Button Num="5"><Override Change="Higher" /></Button>
	<Button Num="6"><JogMode Mode="Next" /></Button>
	<Button Num="7"><AltJoints Toggle="False" /></Button>
	<Button Num="1000"><ProgramEdit Change="Prev" /></Button>
	<Button Num="1002"><ProgramEdit Change="Next" /></Button>
	<Analog Num="0" Bias="-1">
		<Jog Alternative="False" Joint="0" Cartesian="Y" Platform="X" InvertJoint="True" InvertJointAlt="True" InvertCartesian="True" InvertPlatform="True" />
		<Jog Alternative="True"  Joint="3" Cartesian="B" Platform="X" InvertJoint="True" InvertJointAlt="True" InvertCartesian="True" InvertPlatform="True" />
	</Analog>
	<Analog Num="1" Bias="-1">
		<Jog Alternative="False" Joint="1" Cartesian="X" Platform="Y" InvertJoint="True" InvertJointAlt="True" InvertCartesian="True" InvertPlatform="True" />
		<Jog Alternative="True"  Joint="4" Cartesian="A" Platform="Y" InvertJoint="True" InvertJointAlt="True" InvertCartesian="True" InvertPlatform="True" />
	</Analog>
	<!-- The right stick vertical axis can be one of the following IDs, so set all to support most gamepads -->
	<Analog Num="3" Bias="-1">
		<Jog Alternative="False" Joint="2" Cartesian="Z" Platform="Rot" InvertJoint="True" InvertJointAlt="True" InvertCartesian="True" InvertPlatform="True" />
		<Jog Alternative="True"  Joint="5" Cartesian="C" Platform="Rot" InvertJoint="True" InvertJointAlt="True" InvertCartesian="True" InvertPlatform="True" />
	</Analog>
	<Analog Num="4" Bias="-1">
		<Jog Alternative="False" Joint="2" Cartesian="Z" Platform="Rot" InvertJoint="True" InvertJointAlt="True" InvertCartesian="True" InvertPlatform="True" />
		<Jog Alternative="True"  Joint="5" Cartesian="C" Platform="Rot" InvertJoint="True" InvertJointAlt="True" InvertCartesian="True" InvertPlatform="True" />
	</Analog>
	<Analog Num="5" Bias="-1">
		<Jog Alternative="False" Joint="2" Cartesian="Z" Platform="Rot" InvertJoint="True" InvertJointAlt="True" InvertCartesian="True" InvertPlatform="True" />
		<Jog Alternative="True"  Joint="5" Cartesian="C" Platform="Rot" InvertJoint="True" InvertJointAlt="True" InvertCartesian="True" InvertPlatform="True" />
	</Analog>
</Joypad>
[...]
</Environment>
[...]
</ProjectFile>

The Button entries describe the digital buttons, identified by a number: <Button Num="0"></Button> The button and thumb stick assignment might differ depending on the model of the gamepad. The following show the numbers of generic gamepad:

  • 0: right buttons, top
  • 1: right buttons, right
  • 2: right buttons, bottom
  • 3: right buttons, left
  • 4: L1
  • 5: R1
  • 6: L2
  • 7: R2
  • 8: Select
  • 9: Start
  • 1000: left buttons, top
  • 1001: left buttons, right
  • 1002: left buttons, bottom,
  • 1003: left buttons, left

The Analog entries describe the thumbsticks or joystick, also identified by a number (see below). An individual bias can be set to prevent drift, otherwise the default bias set in the <Joypad Bias="10.0"> entry is used.

  • 0: left stick horizontal
  • 1: left stick vertical
  • 2: right stick horizontal
  • 3-5: right stick vertical (try what works for you or set them all like in the example above)

One or more functions can be assigned to each button or analog input. If multiple functions are assigned they will all be executed.

The following actions are available:

  • Jog
 <Jog Alternative="False" Joint="1" Cartesian="X" Platform="Y" InvertJoint="True" InvertJointAlt="True" InvertCartesian="True" InvertPlatform="True" />

Jogs an axis depending on the selected motion mode (joint, cart base, cart tool, platform). "Alternative" can be set for an alternative set of buttons which is switched by the AlternativeJoints action. First robot joint is 0, first external axis is 6, -1 for none; values for Cartesian are X,Y,Z,A,B,C,None; values for Platform are X,Y,Z,Rot,None

  • JogMode
 <JogMode Mode="Next" />

Changes the motion mode: joint -> cart base -> cart tool -> platform; Values for Mode are: Next, Prev, Joint, CartBase, CartTool, Platform.

  • DOut
 <DOut Num="20" Mode="Toggle" />

Changes the digital output specified by the number (DOut1 is number 0 etc). Values for Mode are: Toggle, SetHigh, SetLow, HoldHigh, HoldLow. Hold will reset to the opposite value after the button is released.

  • GSig
 <GSig Num="0" Mode="Toggle" />

Changes a global signal. see DOut.

  • ProgramControl
 <ProgramControl Mode="Start" />

Starts, pauses or stops a program. Values for Mode are: Start, Pause, Stop.

  • ProgramEdit
 <ProgramEdit Change="AddJoint" />

Program editor actions: Values for Change are: First, Last, Next, Prev, TouchUp, AddJoint, AddLinear, Remove, Save. First, last, next and prev change the selected command and thereby the position at which new commands are added. TouchUp updates the selected command. Remove removes the selected command. Save saves the program.

  • MissionEdit
 <MissionEdit Change="AddPosOri" />

Mission sequence actions: Values for Change are: AddPos, AddPosOri, Remove, Save. The add commands add a waypoint at the current position. Currently no navigation like ProgramEdit is available.

  • Override
 <Override Change="Higher" />

Changes the velocity override. Values for Change are: Higher, Lower.

  • AlternativeJoints
 <AltJoints Toggle="False" />

Selects the alternative axis assignment. If toggle is false the standard set is re-selected after the button is released.

Bias and Thumb Stick Drift

It is common that the analog thumb sticks return to a rest position that differs from 0 which can lead to axes seemingly move on their own. The bias parameters solve this by defining a threshold within which the stick position is considered exactly 0.

The bias can be set in two places:

  • The Joypad line defines the bias for all axes that do not explicitly set a different value:
 <Joypad Bias="10.0">
  • The Analog lines define the axis specific bias. If the value is less than 0 the default value is used.
 <Analog Num="1" Bias="-1">

A bias of 10 should work for most gamepads but since it differs between devices you may need to try higher values. The maximum bias is 128.

Debug Mode

If enabled the debug mode writes button events to the log (see the log tab at the bottom left of CPRog/iRC). This is useful for finding the number of a button.

Debug mode is available since V13-040.

To enable the debug mode change the parameter "Debug" to "True":

 <Joypad Bias="10.0" Debug="True">

Note that some buttons may not show. E.g. the direction keys may be handled in a different way than the other buttons, in which case you should try numbers 1000-1003 as mentioned in the previous section.