@(#) $Header: /usr/local/scalawags_cvs/Scalawags/Simulator2006/TheRobot.wc,v 1.1 2006/03/13 23:15:57 abrown Exp $
TheRobot is the user written file for describing the robot. This description should match reality so that the FRC code will behave the same in simulation as on the real robot. So for instance it is important that the simulated motors are driven by the same PWMs, and in the same direction, as the actual robot.
TheRobot.tcl is sourced in RoboSystem.tcl along with TheField.tcl and TheOperatorInterface.tcl.
|
Since TheRobot.tcl is written by the user it can vary considerably. Here is an example of a robot created for the 2006 competition season. There are 4 toggle switches across the top for choosing different autonomous tasks. The left two switches are TogglecoObject and the right two are ToggleObject There is an Actuator (in pink) below the row of switches. The Tractortank is the next block of the screen, in green. The top of Tractortank is used to monitor the two PWMs that control the motors: pwm16 and pwm15. The black "arrows" indicate the input power. The red arrows indicate what the wheels are actually doing. The two green boxes at the bottom are the Encoderwheels They display the number of state transitions the quadrature encoders have seen. A mimimal robot will not need this much. It may be sufficient to start with just a Tractortank. |
The user will program TheRobot first by defining the window ".robot" and the playing robot in it .robot.robot.
source {ActuatorObject.tcl}
source {TractortankObject.tcl}
source {PowertransferObject.tcl}
source {EncoderwheelObject.tcl}
source {ToggleObject.tcl}
toplevel .robot; wm group .robot .
After sourcing the object definitions we will be using we define the window ".robot".
frame .robot.switches
::Toggleco::new plan3 .robot.switches.plan3 ::portjb \
128 128 0 128 vertical bit18 "#000000" "#7f8f7f"
::Toggleco::new plan2 .robot.switches.plan2 ::portjb \
64 64 0 64 vertical bit17 "#000000" "#7f8f7f"
::Toggle::new plan1 .robot.switches.plan1 ::portjb \
32 32 0 vertical bit16 "#000000" "#7f8f7f"
::Toggle::new plan0 .robot.switches.plan0 ::portjb \
16 16 0 vertical bit15 "#000000" "#7f8f7f"
pack .robot.switches.plan3 .robot.switches.plan2 -side left
pack .robot.switches.plan1 .robot.switches.plan0 -side left
pack .robot.switches -side top
A frame is an invisible box on a window or canvas that can contain widgets. This allows the frame to contain switches packed horizontally while the window is packed vertically.
set Fg {#ffffff}
set Bg {#202020}
::Canvas::new robot .robot.r $Bg $Fg {}
pack .robot.r -side top
::Notify::Subscribe Cycle ::Canvas::UpdateAll robot
A CanvasObject is defined to hold the actuator, tractor, and encoders. We subscribe this canvas to the NotifyObject system so that it is updated every cycle.
set labelname [::Canvas::IncludeObject robot ::Canvas::UpdateAll actuates]
::Canvas::new actuates $labelname $Bg $Fg {}
pack $labelname -side top
set labelname [::Canvas::IncludeObject actuates ::Actuator::update actuateL]
::Actuator::new actuateL $labelname 190 5 {($::pwm08-127)/18.0} \
{$::fastratio} horizontal "#af7f7f" "L" {{::Actuator::Measure_update actmeasL}}
pack $labelname -side left
::Actuator::Measure_new actmeasL actuateL \
{($PositionValue*1.65)+25} ::rc_ana_in01 "#3f7f7f"
The actuator is defined next. If you will be simulating an actuator you should study the documentation for ActuatorObject since there is too much to go into here.
set labelname [::Canvas::IncludeObject robot ::Canvas::UpdateAll motors]
::Canvas::new motors $labelname $Bg $Fg {}
pack $labelname -side top
set labelname [::Canvas::IncludeObject motors ::Tractortank::update tractor1]
::Powertransfer::new {leftpower} \
{0.7*[ifibyte2fract $::pwm16 -1] \
+0.3*[ifibyte2fract $::pwm15 1]} \
1 2
::Powertransfer::new {rightpower} \
{0.3*[ifibyte2fract $::pwm16 -1] \
+0.7*[ifibyte2fract $::pwm15 1]} \
1 2
::Tractortank::new tractor1 $labelname 120 256 20 \
{$::pwm16} {$::pwm15} \
{[ifibyte2fract $::pwm16 -1]} {[ifibyte2fract $::pwm15 1]} \
{[::Powertransfer::update {leftpower}]} \
{[::Powertransfer::update {rightpower}]} \
{::leftdist} {::rightdist} {5} {5} \
{$::simseconds} "#7f8f7f" "pwm16 pwm15"
pack $labelname -side left
A sub-canvas is defined to hold the Tractortank . Powertransfer objects are used to control the motors of the tractor.
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
set labelname [::Canvas::IncludeObject idlers ::Encoderwheel::update idleR]
::Encoderwheel::new idleR $labelname {$::rightdist} {0.5*$::INCH} \
{::portbb} {4} {::portbb} {5} "#7f8f7f" "Right"
pack $labelname -side left
Two quadrature encoders are defined, one for each side of the robot. They are specified to change state every 0.5 inch. The outputs of the left one are bits 2 and 3 of portbbits.