Matthew Studley wrote:
HI Doug,
our students tried the correct interface (using setBrightness(n)) but
got a similar error.

The problem seems to be as below:

AttributeError: BulbDevice instance has no attribute '__getitem__'

We're using a TkPioneer which is a subclass of TkRobot, subclassing
SimRobot.  SimRobot has a method addDevice, which we use:

   sim.addRobot(60000, TkPioneer("RedPioneer",
                                  4.99, 1.32, 6.28,
                                  ((.225, .225, -.225, -.225),
                                   (.175, -.175, -.175, .175)),
                                  "red"))
    # add some sensors:
    sim.robots[0].addDevice(PioneerFrontSonars())
    sim.robots[0].addDevice(BulbDevice(0.226, 0))

This works ok!  We get a little robot with a light on his head!

Adding the device used the method addDevice in class SimRobot:

def addDevice(self, dev):
        self.devices.append(dev)
        if dev.type not in self.builtinDevices:
            self.builtinDevices.append(dev.type)
        if dev.type == "bulb":
            self.simulator.lights.append( dev )
            dev.robot = self
            self.bulb = dev
<snip>  etc...

But when we try to do this:
print "bulb is",    sim.robots[0].bulb[0]

we get the error :

    print "bulb is",    sim.robots[0].bulb[0]
AttributeError: BulbDevice instance has no attribute '__getitem__'


Now, the Device class has a __getitem__ method but looking in pysim.py
shows that class BulbDevice is a child of class Light.  And class Light
ISN'T a child of class Device.

I'm confused!  Where do I go from here?

Ok, I think that you might be talking about two different interfaces:

1) the server-side simulator
2) the client-side robot

The client-side robot doesn't have an interface to the simulator (well, not directly... you have to use the robot.simulation[0] device). BUT, your code sample shows that you are combing sim with .bulb[0].

If you want to set the bulb brightness on the server side, then you would use something like:

sim.robots[0].bulb.brightness

[We should make the two sides of the interface parallel... sigh... next time!] Only one bulb per robot, it appears.

-Doug

regards

Matt

_______________________________________________
Pyro-users mailing list
[email protected]
http://emergent.brynmawr.edu/mailman/listinfo/pyro-users



--
Douglas S. Blank
Director, Institute for Personal Robots in Education (IPRE)
http://www.roboteducation.org
Chair, and Associate Professor, Computer Science, Bryn Mawr College
http://cs.brynmawr.edu/~dblank  (610)526-6501
_______________________________________________
Pyro-users mailing list
[email protected]
http://emergent.brynmawr.edu/mailman/listinfo/pyro-users

Reply via email to