예제 #1
0
from robot.controller import BotController
import config
import time

if __name__ == '__main__':

    SPEED = 40.0
    ctrl = BotController(config)
    ctrl.start()

    torque = 0

    data = []

    for _ in range(300):
        time.sleep(0.01)
        ctrl.on_timer()

        data.append((ctrl.timer, ctrl.actual_speed[0], ctrl.actual_speed[1],
                     ctrl.ticks[0], ctrl.ticks[1], ctrl._left.torque,
                     ctrl._right.torque, torque))

        if _ == 50:
            torque = SPEED
            ctrl.run(SPEED, SPEED)

        if _ == 150:
            torque = -SPEED
            ctrl.run(-SPEED, -SPEED)

        if _ == 250:
예제 #2
0
class QB(object):
    """
    Wraps BotController and presents to the user command-level API (high-level).

    Supported commands are:

    set_speed(speed_left, speed_right)

    get_ir()

    get_ticks()
    reset_ticks()

    get_speed()

    Recommended sampling frequency is 100Hz.
    """
    def __init__(self, config):
        self._bot = BotController(config)
        self._ticks_origin_left = 0
        self._ticks_origin_right = 0
        self._ir_calibration = config.IR_CALIBRATION

    def start(self):
        self._bot.start()

    def stop(self):
        self._bot.stop()

    def on_timer(self):
        self._bot.on_timer()

    def set_speed(self, speed_left, speed_right):
        self._bot.run(speed_left, speed_right)

    def get_ir(self):
        return tuple(self._bot.values)

    def get_ir_distances(self):
        return tuple(self._ir_calibration / x for x in self._bot.values)

    def get_ticks(self):
        ticks_left, ticks_right = self._bot.ticks

        return ticks_left - self._ticks_origin_left, ticks_right - self._ticks_origin_right

    def reset_ticks(self):
        self._ticks_origin_left, self._ticks_origin_right = self._bot.ticks

    def get_speed(self):
        return self._bot.actual_speed

    @classmethod
    def run(cls, config, behavior):

        qb = QB(config)
        try:

            qb.start()

            while True:
                time.sleep(0.01)
                qb.on_timer()
                behavior(qb)

        finally:
            qb.stop()
예제 #3
0
 def __init__(self, config):
     self._bot = BotController(config)
     self._ticks_origin_left = 0
     self._ticks_origin_right = 0
     self._ir_calibration = config.IR_CALIBRATION
예제 #4
0
class QB(object):
    """
    Wraps BotController and presents to the user command-level API (high-level).

    Supported commands are:

    set_speed(speed_left, speed_right)

    get_ir()

    get_ticks()
    reset_ticks()

    get_speed()

    Recommended sampling frequency is 100Hz.
    """

    def __init__(self, config):
        self._bot = BotController(config)
        self._ticks_origin_left = 0
        self._ticks_origin_right = 0
        self._ir_calibration = config.IR_CALIBRATION

    def start(self):
        self._bot.start()

    def stop(self):
        self._bot.stop()

    def on_timer(self):
        self._bot.on_timer()

    def set_speed(self, speed_left, speed_right):
        self._bot.run(speed_left, speed_right)

    def get_ir_distances(self):
        return tuple( self._ir_calibration / x for x in self._bot.values )

    def get_ticks(self):
        ticks_left, ticks_right = self._bot.ticks

        return ticks_left - self._ticks_origin_left, ticks_right - self._ticks_origin_right

    def reset_ticks(self):
        self._ticks_origin_left, self._ticks_origin_right = self._bot.ticks

    def get_speed(self):
        return self._bot.actual_speed

    @classmethod
    def run(cls, config, behavior):

        qb = QB(config)
        try:

            qb.start()

            while True:
                time.sleep(0.01)
                qb.on_timer()
                behavior(qb)

        finally:
            qb.stop()
예제 #5
0
 def __init__(self, config):
     self._bot = BotController(config)
     self._ticks_origin_left = 0
     self._ticks_origin_right = 0
     self._ir_calibration = config.IR_CALIBRATION
예제 #6
0
from robot.controller import BotController
import config
import time

if __name__ == '__main__':

	SPEED = 40.0
	ctrl = BotController(config)
	ctrl.start()

	torque = 0

	data = []

	for _ in range(300):
		time.sleep(0.01)
		ctrl.on_timer()

		data.append((ctrl.timer, 
			ctrl.actual_speed[0],
			ctrl.actual_speed[1],
			ctrl.ticks[0],
			ctrl.ticks[1],
			ctrl._left.torque,
			ctrl._right.torque,
			torque))

		if _ == 50:
			torque = SPEED
			ctrl.run(SPEED, SPEED)