コード例 #1
0
class AgentStopInFrontOfWall(Agent):
    def __init__(self):
        Agent.__init__(self)
        self.motors = StepMotorRawControl()
        self.hz = 0

    def setup(self):
        print >> sys.stderr, "setup"

    def ready(self):
        print >> sys.stderr, "ready"
        self.hz = 0

    def loop(self):
        self.hz += 20
        if self.hz > 2500:
            self.hz = 2500

        self.lightsensors.update()
        values = self.lightsensors.get_values()
        th = sum(values)

        if th > 100:
            self.hz = 0
            self.motors.set_values(0, 0)
            return

        self.motors.set_values(self.hz, self.hz)
        time.sleep(0.02)
コード例 #2
0
class AgentGoStraight(Agent):
    def __init__(self):
        Agent.__init__(self)
        self.yaw = Yaw()
        self.motors = StepMotorRawControl()

    def setup(self):
        print >> sys.stderr, "setup"
        self.yaw.off()

    def ready(self):
        print >> sys.stderr, "ready"
        self.yaw.on()

    def loop(self):
        direction = self.yaw.get_value()
        print direction

        #example of how to get the angular velocity
        #vel = self.yaw.get_velocity()
        #print direction, vel

        p_gain = 10.0
        diff = 20*direction / 9 * p_gain
        self.motors.set_values(diff, - diff)

        time.sleep(0.02)
コード例 #3
0
class AgentGoStraight(Agent):
    def __init__(self):
        Agent.__init__(self)
        self.yaw = Yaw()
        self.motors = StepMotorRawControl()

    def setup(self):
        print >> sys.stderr, "setup"
        self.yaw.off()

    def ready(self):
        print >> sys.stderr, "ready"
        self.yaw.on()

    def loop(self):
        direction = self.yaw.get_value()
        print direction

        #example of how to get the angular velocity
        #vel = self.yaw.get_velocity()
        #print direction, vel

        p_gain = 10.0
        diff = 20 * direction / 9 * p_gain
        self.motors.set_values(diff, -diff)

        time.sleep(0.02)
コード例 #4
0
class AgentStopInFrontOfWall(Agent):
    def __init__(self):
        Agent.__init__(self)
        self.motors = StepMotorRawControl()
        self.hz = 0

    def setup(self):
        print >> sys.stderr, "setup"

    def ready(self):
        print >> sys.stderr, "ready"
        self.hz = 0

    def loop(self):
        self.hz += 20
        if self.hz > 2500:
            self.hz = 2500

        self.lightsensors.update()
        values = self.lightsensors.get_values()
        th = sum(values)

        if th > 100:
            self.hz = 0
            self.motors.set_values(0,0)
            return

        self.motors.set_values(self.hz, self.hz)
        time.sleep(0.02)
コード例 #5
0
class AgentGoStraight(Agent):
    def __init__(self):
        Agent.__init__(self)
        self.yaw = Yaw()
        self.motors = StepMotorRawControl()
        self.hz = 0

    def setup(self):
        print >> sys.stderr, "setup"
        self.yaw.off()

    def ready(self):
        print >> sys.stderr, "ready"
        self.yaw.on()
        self.hz = 0

    def loop(self):
        direction = self.yaw.get_value()
        #print direction

        if abs(direction) > 5.0:
            self.hz = 0

        self.hz += 10
        if self.hz > 3500:
            self.hz = 3500

        p_gain = 10.0
        diff = 20 * direction / 9 * p_gain
        if diff > 400.0: diff = 400.0
        elif diff < -400.0: diff = -400.0

        self.motors.set_values(self.hz + diff, self.hz - diff)

        time.sleep(0.02)
コード例 #6
0
class AgentGoStraight(Agent):
    def __init__(self):
        Agent.__init__(self)
        self.yaw = Yaw()
        self.motors = StepMotorRawControl()
        self.hz = 0

    def setup(self):
        print >> sys.stderr, "setup"
        self.yaw.off()

    def ready(self):
        print >> sys.stderr, "ready"
        self.yaw.on()
        self.hz = 0

    def loop(self):
        direction = self.yaw.get_value()
        #print direction

        if abs(direction) > 5.0:
            self.hz = 0

        self.hz += 10
        if self.hz > 3500:
            self.hz = 3500

        p_gain = 10.0
        diff = 20*direction / 9 * p_gain
        if diff > 400.0:    diff = 400.0
        elif diff < -400.0: diff = -400.0

        self.motors.set_values(self.hz + diff, self.hz - diff)

        time.sleep(0.02)
コード例 #7
0
class AgentRunRandom(Agent):
    def __init__(self):
        Agent.__init__(self)
        self.motors = StepMotorRawControl()
        self.hz = 0

    def setup(self):
        print >> sys.stderr, "setup"

    def ready(self):
        print >> sys.stderr, "ready"
        self.hz = 0

    def loop(self):
        self.hz += 20
        if self.hz > 2500:
            self.hz = 2500

        self.lightsensors.update()
        values = self.lightsensors.get_values()
        [leftfront, leftside, rightside, rightfront] = values

        if leftfront + rightfront > 100:
            self.hz = 0
            self.motors.set_values(0, 0)
            time.sleep(0.5)
            if leftfront + leftside > rightfront + rightside:
                self.motors.set_values(300, -300)
            else:
                self.motors.set_values(-300, 300)
            time.sleep(0.5)
            return

        if leftside < 50 and rightside < 50:
            self.motors.set_values(self.hz, self.hz)
            time.sleep(0.02)
            return

        #1cm近づくとだいたい50値が増える
        error = (leftside - rightside) / 50.0
        #1cmあたり3度/秒変化をつける
        direction = error * 3
        diff = 20 * direction / 9

        self.motors.set_values(self.hz + diff, self.hz - diff)
        time.sleep(0.02)
コード例 #8
0
class AgentRunRandom(Agent):
    def __init__(self):
        Agent.__init__(self)
        self.motors = StepMotorRawControl()
        self.hz = 0

    def setup(self):
        print >> sys.stderr, "setup"

    def ready(self):
        print >> sys.stderr, "ready"
        self.hz = 0

    def loop(self):
        self.hz += 20
        if self.hz > 2500:
            self.hz = 2500

        self.lightsensors.update()
        values = self.lightsensors.get_values()
        [leftfront,leftside,rightside,rightfront] = values

        if leftfront + rightfront > 100:
            self.hz = 0
            self.motors.set_values(0,0)
            time.sleep(0.5)
            if leftfront + leftside > rightfront + rightside:
                self.motors.set_values(300,-300)
            else:
                self.motors.set_values(-300,300)
            time.sleep(0.5)
            return

        if leftside < 50 and rightside < 50:
            self.motors.set_values(self.hz,self.hz)
            time.sleep(0.02)
            return

        #1cm近づくとだいたい50値が増える
        error = (leftside - rightside)/50.0
        #1cmあたり3度/秒変化をつける
        direction = error * 3
        diff = 20*direction / 9

        self.motors.set_values(self.hz + diff, self.hz - diff)
        time.sleep(0.02)
コード例 #9
0
class AgentGoStraight(Agent):
    def __init__(self):
        Agent.__init__(self)
        self.yaw = Yaw()
        self.motors = StepMotorRawControl()
        self.hz = 0

    def setup(self):
        print >> sys.stderr, "setup"
        self.yaw.off()

    def ready(self):
        print >> sys.stderr, "ready"
        self.yaw.on()

    def loop(self):
        direction = self.yaw.get_value()
        print direction

        diff = 20 * direction / 9
        self.motors.set_values(diff, -diff)
        time.sleep(1.0)
コード例 #10
0
class AgentGoStraight(Agent):
    def __init__(self):
        Agent.__init__(self)
        self.yaw = Yaw()
        self.motors = StepMotorRawControl()
        self.hz = 0

    def setup(self):
        print >> sys.stderr, "setup"
        self.yaw.off()

    def ready(self):
        print >> sys.stderr, "ready"
        self.yaw.on()

    def loop(self):
        direction = self.yaw.get_value()
        print direction

        diff = 20 * direction / 9
        self.motors.set_values(diff, -diff)
        time.sleep(1.0)
コード例 #11
0
class AgentGoAlongWall(Agent):
    def __init__(self):
        Agent.__init__(self)
        self.motors = StepMotorRawControl()
        self.hz = 0

    def setup(self):
        print >> sys.stderr, "setup"

    def ready(self):
        print >> sys.stderr, "ready"
        self.hz = 0

    def loop(self):
        self.hz += 20
        if self.hz > 2500:
            self.hz = 2500

        self.lightsensors.update()
        values = self.lightsensors.get_values()
        leftside = values[1]

        if leftside < 10:
            self.motors.set_values(self.hz, self.hz)
            time.sleep(0.02)
            return

        target = 200
        #1cm近づくとだいたい50値が増える
        error = (target - leftside) / 50.0
        #1cmあたり3度/秒変化をつける
        direction = error * 3
        diff = -20 * direction / 9

        self.motors.set_values(self.hz + diff, self.hz - diff)
        time.sleep(0.02)
コード例 #12
0
class AgentGoStraight(Agent):
    def __init__(self):
        Agent.__init__(self)
        self.yaw = Yaw()
        self.motors = StepMotorRawControl()
        self.hz = 0

    def setup(self):
        print >> sys.stderr, "setup"
        self.yaw.off()

    def ready(self):
        print >> sys.stderr, "ready"
        self.yaw.on()
        self.hz = 0

    def loop(self):
        self.hz += 10
        if self.hz > 3500:
            self.hz = 3500

        self.motors.set_values(self.hz, self.hz)

        time.sleep(0.02)
コード例 #13
0
class AgentGoStraight(Agent):
    def __init__(self):
        Agent.__init__(self)
        self.yaw = Yaw()
        self.motors = StepMotorRawControl()
        self.hz = 0

    def setup(self):
        print >> sys.stderr, "setup"
        self.yaw.off()

    def ready(self):
        print >> sys.stderr, "ready"
        self.yaw.on()
        self.hz = 0

    def loop(self):
        self.hz += 10
        if self.hz > 3500:
            self.hz = 3500

        self.motors.set_values(self.hz, self.hz)

        time.sleep(0.02)
コード例 #14
0
class AgentGoAlongWall(Agent):
    def __init__(self):
        Agent.__init__(self)
        self.motors = StepMotorRawControl()
        self.hz = 0

    def setup(self):
        print >> sys.stderr, "setup"

    def ready(self):
        print >> sys.stderr, "ready"
        self.hz = 0

    def loop(self):
        self.hz += 20
        if self.hz > 2500:
            self.hz = 2500

        self.lightsensors.update()
        values = self.lightsensors.get_values()
        leftside = values[1]

        if leftside < 10:
            self.motors.set_values(self.hz, self.hz)
            time.sleep(0.02)
            return

        target = 200
        #1cm近づくとだいたい50値が増える
        error = (target - leftside)/50.0
        #1cmあたり3度/秒変化をつける
        direction = error * 3
        diff = -20*direction / 9

        self.motors.set_values(self.hz + diff, self.hz - diff)
        time.sleep(0.02)
コード例 #15
0
 def __init__(self):
     Agent.__init__(self)
     self.yaw = Yaw()
     self.motors = StepMotorRawControl()
コード例 #16
0
 def __init__(self):
     Agent.__init__(self)
     self.yaw = Yaw()
     self.motors = StepMotorRawControl()