FIRST Robot Simulator - JoystickObject


What Is Simulated

JoystickObject simulates an analog joystick similar to the one suppied with the 2004 FIRST Robotic kit. It has two analog outputs for x and y. It also has four buttons.


Where Used

JoystickObject.tcl will typically be sourced in OperatorInterface.tcl. One or more declarations for Joystick_new will then typically be created in OperatorInterface.tcl.


GUI View

The knob of the joystick is manipulatable by the user by click-and-drag with his mouse. Clicking on a button will toggle it. In this image, the joystick has been shifted up and a little to the right.

The variable names for x and y (truncated) and their values are shown on the bottom right of the image. In the example shown, joystick x is controlling the variable oi_an08 and is currently set to decimal 94 based on the position of the joystick knob.

The variable names for the switches are shown to the right of their buttons. In the example shown, all are set to 0 except for joy_trig4 which is 1.


Programmers View

There are two proc[eedures] in JoystickObject.tcl. The first few lines of each proc lists the parameters required.

  proc Joystick_new { {JoystickName} {NameOnCanv} \
		      {joyX} {joyY} {joy_trig} {joy_top} {joy_aux1} {joy_aux2}
		      {Fg} {Bg} } \
  {
      # $joyX and $joyY = names of the variables controlled by the joystick.
      # $joy_trig = name of the joystick trig button.
      # $joy_top = name of the joystick top button.
      # $joy_aux1 and $joy_aux2 = names of two more joystick buttons.
      # $Fg and $Bg = Foreground and background colors for the joystick.
  

The parameters JoystickName and NameOnCanv are constants. The parameters joyX, joyY, joy_trig, joy_top, joy_aux1, and joy_aux2 are the names of variables that you provide to JoystickObject. It will set those variables based on the operator's interactions with the joystick on the GUI of the simulator.

   # Joystick_update does not need to be explicitly called by the
   # user.  That is handled by the bindings in side of Joystick_new.
  proc Joystick_update { {JoystickName} {ScreenX} {ScreenY} } \
  {
      # ScreenX,ScreenY = Screen coordinates of the mouse.
  

As the comment implies, we really don't have to do anything special with Joystick_update. It will be called by the bind in Joystick_new when that is appropriate.


Example

We can put a joystick against the right side of a frame using code like this:

  frame .oper_interf.joygroup
  Joystick_new joy4 .oper_interf.joygroup.joy4 \
      {::oi_an08} {::oi_an04} \
      {::joy_trig4} {::joy_top4} {::joy_aux41} {::joy_aux42} \
      {#000000} {#8f8f33}
  pack .oper_interf.joygroup.joy4 -side right
  

The double colons in front of each variable name makes them operate at the root namespace of the Tcl program.

Foreground is black, {#000000}, Background is off green, {#8f8f33}.


Caveats



Last modified 4 Apr 2004