@(#) $Header: /usr/local/scalawags_cvs/Scalawags/Simulator2006/TheOperatorInterface.wc,v 1.1 2006/03/13 23:15:57 abrown Exp $
TheOperatorInterface is the user written file for control the operator interface such as joysticks and switches.
TheOperatorInterface.tcl is sourced in RoboSystem.tcl along with TheRobot.tcl and TheField.tcl.
|
Since TheOperatorInterface.tcl is written by the user it can vary considerably. Here is an example of a operator interface created for the 2006 competition season. There is a stack of LEDs on the left edge. There are two JoystickObjects in green. There are two switches and a potentiometer across the top. |
The user will program TheOperatorInterface first by defining the window ".oper_interf".
source {LedObject.tcl}
source {JoystickObject.tcl}
source {TogglecoObject.tcl}
toplevel .oper_interf; wm group .oper_interf .; # Do not change this line.
Since we will be using LedObject , JoystickObject and TogglecoObject objects we include their definitions.
Next define a separate canvas for the LEDs on the left. These LEDs are vertically stacked in their canvas.
  # ---- LEDs -------------
::Canvas::new led .oper_interf.left {#7f6f7f} {#000000} {Led Monitor}
::Notify::Subscribe Cycle ::Canvas::UpdateAll led
  #::Led::new {LedName} {NameOnCanv} {expression} {Xs} {Ys} {ColorOn} {ColorOff}
set labelname [::Canvas::IncludeObject led ::Led::Update red3But]
::Led::new red3But $labelname {$::LED_byte1 & 0x80} 7 3 "#ff0000" "#600000"
pack $labelname -side top
set labelname [::Canvas::IncludeObject led ::Led::Update red2But]
::Led::new red2But $labelname {$::LED_byte1 & 0x40} 7 3 "#ff0000" "#600000"
pack $labelname -side top
set labelname [::Canvas::IncludeObject led ::Led::Update red1But]
::Led::new red1But $labelname {$::LED_byte1 & 0x20} 7 3 "#ff0000" "#600000"
pack $labelname -side top
set labelname [::Canvas::IncludeObject led ::Led::Update red0But]
::Led::new red0But $labelname {$::LED_byte1 & 0x10} 7 3 "#ff0000" "#600000"
pack $labelname -side top
set labelname [::Canvas::IncludeObject led ::Led::Update green3But]
::Led::new green3But $labelname {$::LED_byte1 & 0x08} 7 3 "#00ff00" "#006000"
pack $labelname -side top
set labelname [::Canvas::IncludeObject led ::Led::Update green2But]
::Led::new green2But $labelname {$::LED_byte1 & 0x04} 7 3 "#00ff00" "#006000"
pack $labelname -side top
set labelname [::Canvas::IncludeObject led ::Led::Update green1But]
::Led::new green1But $labelname {$::LED_byte1 & 0x02} 7 3 "#00ff00" "#006000"
pack $labelname -side top
set labelname [::Canvas::IncludeObject led ::Led::Update green0But]
::Led::new green0But $labelname {$::LED_byte1 & 0x01} 7 3 "#00ff00" "#006000"
pack $labelname -side top
Now define three frames within .oper_interf. These will create a column of invisible boxes next to the column of LEDs. The top one will contain the two switches and potentiometer. The bottom one will contain the joysticks.
frame .oper_interf.right
frame .oper_interf.right.top
frame .oper_interf.right.bottom
The joysticks are connected to the variables the control.
  # ---- oi_analog01 and oi_analog02 ------------
  # ::Joystick::new {JoystickName} {NameOnCanv}
  # {joyX} {joyY} {joy_trig} {joy_top} {joy_aux1} {joy_aux2} {Fg} {Bg}
::Joystick::new joy1 .oper_interf.right.bottom.joy1 \
{::oi_analog05} {::oi_analog01} \
{::joy_trig1} {::joy_top1} {::joy_aux11} {::joy_aux12} \
{#000000} {#8f8f33}
::Joystick::new joy2 .oper_interf.right.bottom.joy2 \
{::oi_analog06} {::oi_analog02} \
{::joy_trig2} {::joy_top2} {::joy_aux21} {::joy_aux22} \
{#000000} {#6f6f33}
pack .oper_interf.right.bottom.joy1 -side left
pack .oper_interf.right.bottom.joy2 -side right
Scale is a TK/TCL builtin. It isn't always as good a fit for what we do. In the case of a standalone potentiometer (connected to a joystick port) it is a pretty good widget.
scale .oper_interf.right.top.pot3 -showvalue true -from 0 -to 255 \
-variable {::oi_analog03} -label {::oi_analog03} -orient horiz
Checkbutton is another TK/TCL builtin. Toggleco rounds out our operator interface.
checkbutton .oper_interf.right.top.joy_aux31 \
-text "joy_aux31" -variable {joy_aux31} -offvalue 0 -onvalue 1
::Toggleco::new oi_swA1 .oper_interf.right.top.oi_swA ::oi_swA \
5 4 5 1 horizontal oi_swA {#000000} {#7f8f7f}
All of the frames and widgets need to be packed so the TK/TCL gui manager knows about them.
pack .oper_interf.right.top.pot3 -side right
pack .oper_interf.right.top.joy_aux31 -side left
pack .oper_interf.right.top.oi_swA
pack .oper_interf.right.top -side top
pack .oper_interf.right.bottom -side bottom
pack .oper_interf.right -expand 1
pack .oper_interf.left -side left
It should be clear from this page and from the individual documentation pages for the objects used here how to extend this example. Or to remove things you don't want. The exception is the TK/TCL builtins. For that I suggest downloading tclhelp. http://stuff.mit.edu/afs/sipb/project/tcl/linuxbin/tclhelp or accessing one of the online TCL help pages. http://markhobley.yi.org:8000/TclHelp or http://tclhelp.net/mirror/tcl8.5a1/html/Keywords/contents.htm