FIRST Robot Simulator - CanvasObject


What Is Simulated

CanvasObject is used as an intelligent container for other robotic simulation objects. In itself, it does nothing.


Where Used

CanvasObject.tcl can be used anywhere a group of managable objects will be instanciated. A prime example of this is an array of LEDs.


GUI View

An empty Canvas isn't much. All it shows is the title.


Programmers View

There are several proc[edures] in CanvasObject.tcl. We are interested in three of them.

  proc Canvas_new { {CanvasObject} {NameOfCanv} {canvcolor} 
		      {textcolor} {title} } \
  {
     # CanvasObject = Unique name for the canvas object.
     # NameOfCanv = Graphical name of object.
     # canvcolor = Color of the background.
     # textcolor = Color of the title.
     # title = Text that shows in the canvas.
  

The parameters CanvasName and NameOnCanv are constants.

  proc Canvas_IncludeObject { {CanvasObject} {objecthandler} {objectname} } \
  {
     # CanvasObject = Name for this canvas object.
     # objecthandler = Method for updating $objectname.
     # objectname = name of object to update.
  

Once you have created a CanvasObject using Canvas_new, you can hand it objects to manage. That is done with Canvas_IncludeObject. Objecthandler is a statement that will update the object. Usually it is little more than "ThisThing_update MyObject".

   # Update all objects that have been registered for CanvasObject.
  proc Canvas_UpdateAll { {CanvasObject} } \
  {
     # CanvasObject = Name for this canvas object.
  

When Canvas_UpdateAll is called, it calls each of the objecthandlers for the objects it has been asked to manage.


Example

First we declare a CanvasObject using Canvas_new.

  set canvasname [Canvas_new led .oper_interf.left \
                      {#7f6f7f} {#000000}  {Led Monitor}]
  

We can now declare one or more objects to be managed by it.

  set labelname [Canvas_IncludeObject led Led_Update green0But]
  Led_new green0But $labelname {$::LED_byte1 & 0x01} 7 3 "#00ff00" "#006000"
  pack $labelname -side top
  

The object to managed is green0But. It's objecthandler is Led_Update.

  Canvas_UpdateAll led
  

When Canvas_UpdateAll is called for this canvas object (here named led), it will call each objecthandler for each object. In this example there is only one object. So a single call is made:

  Led_Update green0But
  

Caveats

None.



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