FIRST Robot Simulator - Writing the Tcl Robot Simulator

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 Robot part of the Robot System Simulator.

Tcl Code for a simple Robot

A very simple robot using tank steering might consist of nothing more than two motors. Let's look at the tcl code to simulate that simple robot.

    source {TractorObject.tcl}
    source {Victor884.tcl}; # Used by TractorObject.

    toplevel .robot; wm group .robot .

      # Tractor_new {TractorName} {NameOnCanv} {Xs} {Ys} \
      #		{tractInL} {tractInR} {tractL} {tractR} \
      #		{BackColor} {Comment}
      Tractor_new tractor .robot.tractor {256} {256} \
        {1} {1} {$::pwm01} {$::pwm02} \
        {#7f8f7f} "Rear Tractor Wheels"

      pack .robot.tractor -side top
  

The first two lines define two objects that we will use. We are concerned with the Tractor object. That is the was we simulate the drive motors.

The next line defines a window called ".robot". The tractor, and any other functions we add to the robot will live in this window on the computer screen.

Next we instanciate the Tractor. The comment lines I have included hint at the purpose of each of the parameters. For a more detailed description you should study TractorObject.tcl . Most of the parameters should be straightforward.

I want to call special attention to how the motor speed is passed into the Tractor object. The simulation declares a full set of PWM variables. To have the Tractor monitor the variable, it needs to be specified in the format shown: {$::pwm01}.

Last in the file is the "pack" line. This tells Tk to shrink (or grow) the computer window to fit around the Tractor graphic. The result will looks something like this on your screen:

In this image the motors are being driven with "127", which is no power. If the motors were on the red arrows would be pointing up or down. The arrows lengthen to indicate how hard the motors are being driven.


Adding Features To The Simple Robot

What other objects are we likely to want to include in our Robot?

If we add the ToggleObject to our robot code we need to add one declaration:

      # Toggleco_new { {TogglecoName} {NameOnCanv} {variable}
      #   {mask} {upleft} {mid} {downright} {shape} {text} {Fg} {Bg}
      Toggleco_new autodir .robot.autodir {::portjb} \
        3 2 0 1 horizontal autodir {#000000} {#7f8f7f}
  

And the "pack" line in the file above needs to also list the object we just declared:

      pack .robot.tractor .robot.autodir -side top
  

You can see a single toggle switch on the bottom of the window.


Next Customizing the C code

Last modified 10 Dec 2006
http://brown.armoredpenguin.com/~abrown/contact.html
http://brown.armoredpenguin.com/~abrown/first/first2005/SimulatorDocs/TheRobot.html