EncoderwheelObject simulates an encoder that measures the distance traveled by (typically) one side of the tractor. This may be an idler (driven by the field) or may be linked directly to the drive train. It takes one analog input, the motor channel.
EncoderwheelObject outputs two digital bits. The bits are the quadrature phase of the idle wheel. Thus the rotation of the idler is represented as its change in phase.
EncoderwheelObject displays a clock face to indicate how far the idler has gone. Note that this is just for convenience since the idler does not give any distance output, only phase.
EncoderwheelObject.tcl will typically be sourced in TheRobot.tcl. The declaration for Encoderwheel_new will then also be created in TheRobot.tcl.
|
The number at the top is the fault count. The text in the middle is simply a comment. (Typically it is used to indicate the left or right size.) The number at the bottom represents the total (directional) number of ticks (i.e. phase changes). The fault count is incremented each time the phase changes more than one tick per fast cycle. This is simply for the programmers convenience in debug since there is no actual output of this sort. The hands of the clock are sized according to the magnitude of the digits they encode. The biggest hand only moves when the distance number has gotten fairly large. The smallest hand moves with every phase change. |
There are two proc[edures] in EncoderwheelObject.tcl. The first few lines of each proc lists the parameters required.
proc Encoderwheel_new { {EncoderwheelName} {NameOnCanv} \
{SpeedExpr} {P1Expr} {P1Bit} {P2Expr} {P2Bit} \
{ErrorMag} {fastratio} {BackColor} {Comment} } \
{
  # EncoderwheelName = Unique name for the Encoderwheel.
  # NameOnCanv =
  # SpeedExpr = Signed value indicating how fast the wheel should move.
  # P1Expr/P2Expr = Bit to set for Phase1/Phase2 of the encoder.
  # ErrorMag =
  # BackColor = Background color the idlewheel sits on.
The parameters EncoderwheelName and NameOnCanv are constants.
SpeedExpr is the power to the idler. If SpeedExpr is positive, the idler rotates clockwise. If SpeedExpr is negative, the idler rotates counter-clockwise.
P1Expr and P2Expr are variables to be controlled. P1Bit and P2Bit are the bits that can be controlled in those variables.
ErrorMag is reserved for future use. fastratio determines the sensitivity of the idler to the power input. Comment is displayed just below the center of the clock hands.
proc Encoderwheel_update { {EncoderwheelName} }\
{
Encoderwheel_update needs to be called, typically in Updates.tcl.
We can put two idlewheels side by side below a tractor using code like this:
source {EncoderwheelObject.tcl}
toplevel .robot; wm group .robot .
frame .robot.idlers
Encoderwheel_new idleL .robot.idlers.idleL {127-$::pwm09} \
{::portbb} {1} {::portbb} {2} {0.01} {3} "#7f8f7f" "L"
Encoderwheel_new idleR .robot.idlers.idleR {$::pwm11-127} \
{::portbb} {4} {::portbb} {3} {0.01} {3} "#7f8f7f" "R"
pack .robot.idlers.idleL .robot.idlers.idleR -side left
pack .robot.motors .robot.idlers -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, the left motor runs backward; the right forward.
Encoderwheel_update idlewheel
The update code above is in Updates.tcl. Each time it is called, the Encoderwheel image is updated based on the values of the root scope variables $::pwm09 and $::pwm11.