TractorObject simulates the two motors of a tank steered robot base. It takes two analog inputs, one for each of the two motor channels.
TractorObject.tcl will typically be sourced in TheRobot.tcl. The declaration for Tractor_new will then also be created in TheRobot.tcl.
|
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. |
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.
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.
Since TractorObject uses Victor884 internally, any time TractorObject.tcl is sourced, Victor884.tcl should also be sourced.
Victor884 simulates the observed behaviour of the Victor motor speed control units. At inputs close to 128, output is zero. Once the input gets strong enough for the Victor to recognize it, the victor's output jumps well above zero output. Thus there is no way to get a near-zero output.
Inputs to the Victor which are above about 230 all drive the output to full forward. Inputs to the Victor which are below about 41 all drive the output to full reverse.
In summary the output of the victor is nonlinear and discontinuous. This behaviour is simulated.