Difference between revisions of "Joystick and Gamepad"

From Wiki
m
(Bias and Thumb Stick Drift)
 
(9 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
Earlier versions of CPRog/iRC have a static button binding. While version 13-030 and later can be configured. This article explains both.
 
Earlier versions of CPRog/iRC have a static button binding. While version 13-030 and later can be configured. This article explains both.
  
= Static and default button binding =
+
= Default button binding =
  
The following button binding is used on versions up to 13-030 and when no custom bindings are defined:
+
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)
 
(read the stick assignment as joint/cartesian/platform)
 
* Left thumb stick horizontal: A1/Y/X; alternative A4/B/X
 
* Left thumb stick horizontal: A1/Y/X; alternative A4/B/X
Line 31: Line 31:
  
 
= Button binding configuration =
 
= Button binding configuration =
Since version 13-030 the configuration can be changed via the project configuration file.
+
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:
 
The following example represents the standard configuration as described in the previous article:
 
<syntaxhighlight lang="XML">
 
<syntaxhighlight lang="XML">
<Joypad Bias="10.0">
+
<ProjectFile>
 +
[...]
 +
<Environment>
 +
<Joypad Bias="10.0" Debug="False">
 
<Button Num="0"><ProgramEdit Change="TouchUp" /></Button>
 
<Button Num="0"><ProgramEdit Change="TouchUp" /></Button>
 
<Button Num="1"><ProgramEdit Change="AddJoint" /></Button>
 
<Button Num="1"><ProgramEdit Change="AddJoint" /></Button>
Line 53: Line 56:
 
<Jog Alternative="False" Joint="1" Cartesian="X" Platform="Y" InvertJoint="True" InvertJointAlt="True" InvertCartesian="True" InvertPlatform="True" />
 
<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" />
 
<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>
 
<Analog Num="5" Bias="-1">
 
<Analog Num="5" Bias="-1">
Line 59: Line 71:
 
</Analog>
 
</Analog>
 
</Joypad>
 
</Joypad>
 +
[...]
 +
</Environment>
 +
[...]
 +
</ProjectFile>
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
The Button entries describe the digital buttons, identified by a number: <Button Num="0"></Button>
 
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
 
* 0: right buttons, top
 
* 1: right buttons, right
 
* 1: right buttons, right
Line 81: Line 98:
 
* 1: left stick vertical
 
* 1: left stick vertical
 
* 2: right stick horizontal
 
* 2: right stick horizontal
* 3-4: unused(?)
+
* 3-5: right stick vertical (try what works for you or set them all like in the example above)
* 5: right stick vertical
 
  
 
One or more functions can be assigned to each button or analog input. If multiple functions are assigned they will all be executed.
 
One or more functions can be assigned to each button or analog input. If multiple functions are assigned they will all be executed.
Line 105: Line 121:
 
   <ProgramEdit Change="AddJoint" />
 
   <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.
 
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'''
 
   <Override Change="Higher" />
 
   <Override Change="Higher" />
Line 111: Line 130:
 
   <AltJoints Toggle="False" />
 
   <AltJoints Toggle="False" />
 
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.
 +
 +
= 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.
  
 
[[Category:CPRog]]
 
[[Category:CPRog]]

Latest revision as of 13:49, 7 February 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)

Button binding configuration

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.