Xander Soldaat wrote:
Hi there,

I'm using the 2D TkSimulator together with a Pioneer robot for my virtual robot project. I am trying to create a circular room, rather than the standard box shaped one. I tried using just sim.drawOval(0,0, 4,4), but that doesn't seem to work the same as a bounding box. I have also tried using drawOval() after calling addBox() with the same dimensions. The canvas does show a perfect circle that fits exactly inside the box, but it totally ignores the circle.

My question is how do I create a circular bounding area with the same properties as the sim.addBox() function?

Xander,

You're right that there are two lists in the Python simulator: wall segments (sim.world) and other decorations that are drawn but don't interact with the sensors (sim.shapes).

If you want to draw a round room (or any other shape) you need to construct the walls out of segments (eg, straight lines). Here is a world that draws a robot in a round room using geometry to rotate the segments, and offset them to a center of (2, 2):

from pyrobot.simulators.pysim import *
import math
def INIT():
    # (width, height), (offset x, offset y), scale:
    sim = TkSimulator((357,486), (38,397), 57.838547)
    # x1, y1, x2, y2 in meters:
    x, y = 2, 2 # center of circle
    length = 1.0 # length of segment
    parts = 20 # number of sides, larger = more circular
    ds = (math.pi * 2)/parts
    for i in range(0, 360, 360/parts):
        d = i * math.pi/180
        x1, y1 = x + math.cos(d) * length, y + math.sin(d) * length
x2, y2 = x + math.cos(d + ds) * length, y + math.sin(d + ds) * length
        sim.addWall(x1, y1, x2, y2)

    # port, name, x, y, th, bounding Xs, bounding Ys, color
    # (optional TK color name):
    sim.addRobot(60000, TkPioneer("RedPioneer",
                                  2.0, 2.0, 6.28,
                                  ((.225, .225, -.225, -.225),
                                   (.175, -.175, -.175, .175)),
                                  "red"))
    # add some sensors:
    sim.robots[0].addDevice(Pioneer16Sonars())
    return sim

Hope that helps,

-Doug

Thanks,
Xander

--
| mail: mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
|
| What the world needs is more geniuses
| with humility, there are so few of us left.


------------------------------------------------------------------------

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

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

Reply via email to