FIRST Robot Simulator - Writing the Tcl Operator Interface

Click on a thumbnail sketch to see the full size picture.

Intro

This page will provide an introduction to the process of writing the Tcl Operator Interface part of the Robot System Simulator.

For the purposes of simulation the operator interface doesn't need to consist of anything more than a few joysticks and some LEDs. But in practice it is best if the simulated operator interface actually resembles the real unit that will be used by the drivers.

Frames and Canvasses

Tcl works with frames and canvasses. (The CanvasObject that I provide is a third possibility that is built on top of a canvas.) If you are simply placing graphic objects, the two are the equivalent. I will use frames for these examples.

Graphic objects can be stacked vertically or horizontally in a frame. For more complex arrangements of objects we use combinations of frames. For instance, if we want two columns of objects, then we can do this using two frames.

    toplevel .oper_interf; wm group .oper_interf .; # Do not change this line.
    frame .oper_interf.left
    frame .oper_interf.right
  

We can now put objects into the left or in the right column.

    set canvasname [Canvas_new led .oper_interf.left \
		      {#7f6f7f} {#000000}  {Led Monitor}]
    pack .oper_interf.left -side left

    Joystick_new joy4 .oper_interf.right.joy4 \
      {::oi_an08} {::oi_an04} {::joy_trig4} {::joy_top4} {::joy_aux41} {::joy_aux42} \
      {#000000} {#8f8f33}
    Joystick_new joy2 .oper_interf.right.joy2 \
      {::oi_an06} {::oi_an02} {::joy_trig2} {::joy_top2} {::joy_aux21} {::joy_aux22} \
      {#000000} {#6f6f33}
    pack .oper_interf.right.joy4 -side top
    pack .oper_interf.right.joy2
    pack .oper_interf.right -expand 1
  

This results in a canvas object named "led" on the left side of the window "oper_interf". The right side of the window contains a frame containing a column of two joysticks. "joy4" is on top and "joy2" is below it.

Now lets take a closer look at the objects we are putting into the window.


Joystick

The simulator currently does not have an interface to a physical joystick. Instead the joystick is simulated in Tcl with a graphic object, [shown at right].

There are actually advantages to this. You have more control over a simulated joystick. Plus the simulated joystick gives useful information about what values it is handing off to the program.

For more details on the Joystick Object, click here. That page describes how to add a joystick and shows an example.


A block of LEDs

The example OperatorInterface.tcl file that comes with the simulator provides a block of LEDs, simulating the LEDs visible on the radio interface box [shown at right]. It isn't necessary to add any more LEDs. But you may choose to add LEDs to the real operator interface anyway in order to more clearly send a message to the operator. We can simulate these additional LEDs.

For more details on the Led Object, click here. This link shows how to put down LEDs inside a canvas.


Potentiometer

Joysticks provide potentiometers. And for simulation purposes that may be enough. But if you are simulating the operator interface, it may be desirable to more closely match the planned hardware.

All of the objects I have provided so far were written by me to support the FIRST Robotic effort. But the slider pot in this example is a Tcl builtin called a "scale". I am not aware of a rotary dial pot. Maybe I will write one someday. In the meantime we can use the scale.

Lets create an example slider pot. We will drive the variable oi_an03.

	  scale .oper_interf.right.top.pot3 -showvalue true -from 0 -to 255 \
	      -variable {::oi_an03} -label {::oi_an03} -orient horiz
	  pack .oper_interf.right.top.pot3 -side right
	

The options "-from 0 -to 255" tells the scale the range of output values this potentiometer can output. We can ask for a vertical pot with "-orient vert". But I find that the vertical scales tend to take too much screen space, so I always use horizontal ones.


Push Button

A common need is a button. This is another object provided by native Tcl.

In the example here we will control the variable joy_aux31. In the image at right, the button has been pushed, so the value store in joy_aux31 is 1.

	  checkbutton .oper_interf.right.top.joy_aux31 \
	      -text "joy_aux31" -variable {::joy_aux31} -offvalue 0 -onvalue 1
	  pack .oper_interf.right.top.joy_aux31 -side left
	

The variable joy_aux31 is a temporary. The checkbutton is only capable of setting its value to 0 or 1. As a result, we will need to combine its value with the other bits before outputing them all to a port such as oi_swA. In the Toggle Switch below we will see a more capable interface.


Toggle Switch

A center-off toggle switch is a three position switch. It drives two binary bits. If we wire it so that the center terminal is grounded and the two bits are pulled up, then the three states are "one high", "the other high", "both high".

The Toggleco Object can easily simulate this. And it can control individual bits in an existing variable without disturbing the other bits.

Lets wire our switch to bits 0 and 2 of oi_swA. We need to make a mask which covers those bits. In binary the mask will look like 00000101. That is decimal 5. When we set the switch to the left, we want to output bit 2 only. That is 00000100, or decimal 4. And when the switch is to the right the output will be 1.

	  Toggleco_new oi_swA1 .oper_interf.right.top.oi_swA ::oi_swA \
	    5 4 5 1 horizontal oi_swA {#000000} {#7f8f7f}
	  pack .oper_interf.right.top.oi_swA
	

The parameters "5 4 5 1" respectively define the mask, left, middle, and right. The last three parameters define the label, the foreground color, and the background color.



Next Customizing the Robot in Tcl

Last modified 26 Aug 2006
http://brown.armoredpenguin.com/~abrown/contact.html
_URL_