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. It is up to your FRC code to translate phases into distance.
|
Quadrature encoders provide sufficient information to determine direction as well as distance. |
EncoderwheelObject.tcl will typically be sourced in TheRobot.tcl. The declaration for ::Encoderwheel::new will then also be created in TheRobot.tcl.
The number in red at the top is the fault count. This is incremented any time the encoder changes by two or more phases in one mini-cycle. (A mini-cycle is either a slow cycle or a fast cycle.) When this happens it is not possible to know for sure which direction the encoder was rotating. If your system reads the encoders by polling once each mini-cycle in the FRC, this will indicate problems when you try to navigate. If you read the encoders in the FRC using interrupts, this may not be a problem.
|
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 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 new { {EncoderwheelName} {NameOnCanv} \
{MotionExpr} {TickDist} \
{P1Expr} {P1Bit} {P2Expr} {P2Bit} \
{BackColor} {Comment} } \
{
  # EncoderwheelName = Unique name for the Encoderwheel.
  # NameOnCanv = Graphic path to the Encoderwheel object.
  # MotionExpr = Signed value indicating how far the wheel has moved this cycle.
  # TickDist = Distance between encoder wheel state changes.
  # P1Expr/P2Expr = Bit to set for Phase1/Phase2 of the encoder.
  # BackColor = Background color the encoderwheel sits on.
The parameters EncoderwheelName and NameOnCanv are constants.
MotionExpr is a variable or expression that needs to report what distance has been traveled. See TractortankObject. TickDist calibrates EncoderObject by telling it how to translate distance from MotionExpr into phase changes.
P1Expr and P2Expr are variables to be controlled. P1Bit and P2Bit are the bits that can be controlled in those variables.
proc update { {EncoderwheelName} }\
{
::Encoderwheel::update needs to be called, typically by Notify using a structure like this:
::Notify::Subscribe Cycle ::Encoderwheel::update encodername
We can put two idlewheels side by side below a tractor using code like this:
source {EncoderwheelObject.tcl}
set labelname [::Canvas::IncludeObject robot ::Canvas::UpdateAll idlers]
::Canvas::new idlers $labelname $Bg $Fg {}
pack $labelname -side top
set labelname [::Canvas::IncludeObject idlers ::Encoderwheel::update idleL]
::Encoderwheel::new idleL $labelname {$::leftdist} {0.5*$::INCH} \
{::portbb} {2} {::portbb} {3} "#7f8f7f" "Left"
pack $labelname -side left
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. I assume here that the global variable ::leftdist will be kept up-to-date by TractortankObject.
This encoder is built to have a phase change every 1/2 inch.
The outputs of the encoder are bits 2 and 3 of portbbits.
Since the encoders have been declared as part of the CanvasObject "idlers" they will be updated every time that CanvasObject is.