FIRST Robot Simulator - TractorObject


What Is Simulated

TractorObject simulates the two motors of a tank steered robot base. It takes two analog inputs, one for each of the two motor channels.


Where Used

TractorObject.tcl will typically be sourced in TheRobot.tcl. The declaration for Tractor_new will then also be created in TheRobot.tcl.


GUI View

The tractor motors are represented by arrows and by the numbers below them. The value 127 is zero power. When a motor channel receives a number greater than 127, up to 255, the arrow extends up. When a motor channel receives a number less than 127, down to 0, the arrow extends down.


Programmers View

There are several proc[edures] in TractorObject.tcl. We are interested in two of them. The first few lines of each proc lists the parameters required.

  proc Tractor_new { {TractorName} {NameOnCanv} {Xs} {Ys} \
		     {tractInL} {tractInR} {tractL} {tractR} \
		     {BackColor} {Comment} } \
  {
     # TractorName = Unique name for the Tractor.
     # NameOnCanv = Graphic path to the tractor object.
     # Xs and Ys = Size of Tractor.
     # tractInL and tractInR = 1/-1 -> normal/invert.
     # tractL and tractR = expression controlling the motor channel.
     # BackColor = Background color the tractor sits on.
     # Comment = Text to be displayed on the tractor image.
  

The parameters TractorName and NameOnCanv are constants. Xs and Ys determine the size of the tractor image on the screen. The parameters tractInL and tractInR are multipliers allowing the corresponding channel to be inverted to represent a motor that has to run backwards to make the tractor go forward. The parameters tractL and tractR are expressions which represent the inputs to the motor control circuits. Typically these are pwm channels.

  proc Tractor_update { {TractorName} }\
  {
    variable $TractorName
  

Tractor_update needs to be called, typically in Updates.tcl.


Example

We can put a tractor against the top side of a frame using code like this:

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

  toplevel .robot; wm group .robot .
  Tractor_new tractor .robot.tractor 256 256 \
    {1} {1} {$::pwm01} {$::pwm02} {#7f8f7f} "Tractor Wheels"
  pack .robot.tractor -side top
  

The declaration above is in TheRobot.tcl. The double colons in front of each variable name makes them operate at the root namespace of the Tcl program. In this example, both motors run forward.

  Tractor_update tractor
  

The update code above is in Updates.tcl. Each time it is called, the Tractor image is updated based on the values of the root scope variables $::pwm01 and $::pwm02.


Caveats



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