Ejemplo n.º 1
0
    def __init__(self, directions={}):
        import platypush.plugins.gpio.zeroborg.lib as ZeroBorg

        self.directions = directions
        self.auto_mode = False
        self._direction = None

        self.zb = ZeroBorg.ZeroBorg()
        self.zb.Init()
        self.zb.SetCommsFailsafe(True)
        self.zb.ResetEpo()
Ejemplo n.º 2
0
    def __init__(self, directions: Dict[str, List[float]] = None, **kwargs):
        """
        :param directions: Configuration for the motor directions. A direction is basically a configuration of the
            power delivered to each motor to allow whichever object you're controlling (wheels, robotic arms etc.) to
            move in a certain direction. In my experience the ZeroBorg always needs a bit of calibration, depending on
            factory defaults and the mechanical properties of the load it controls.

        Example configuration that I use to control a simple 4WD robot::

            directions = {
                "up": [
                    0.4821428571428572,   # Motor 1 power
                    0.4821428571428572,   # Motor 2 power
                    -0.6707142857142858,  # Motor 3 power
                    -0.6707142857142858   # Motor 4 power
                ],
                "down": [
                    -0.4821428571428572,
                    -0.4821428571428572,
                    0.825,
                    0.825
                ],
                "left": [
                    -0.1392857142857143,
                    -0.1392857142857143,
                    -1.0553571428571429,
                    -1.0553571428571429
                ],
                "right": [
                    1.0017857142857143,
                    1.0017857142857143,
                    0.6214285714285713,
                    0.6214285714285713
                ]
            }

        """

        if directions is None:
            directions = {}

        import platypush.plugins.gpio.zeroborg.lib as ZeroBorg
        super().__init__(**kwargs)

        self.directions = directions
        self._direction = None
        self._drive_thread = None
        self._motors = [0, 0, 0, 0]

        self.zb = ZeroBorg.ZeroBorg()
        self.zb.Init()
        self.zb.SetCommsFailsafe(True)
        self.zb.ResetEpo()
Ejemplo n.º 3
0
import time

import platypush.plugins.gpio.zeroborg.lib as ZeroBorg

no_msg_timeout = 0.37
last_msg = None
last_msg_timestamp = None
auto_mode = False

ZB = ZeroBorg.ZeroBorg()
ZB.Init()

while True:
    ZB.GetIrMessage()
    if ZB.HasNewIrMessage():
        message = ZB.GetIrMessage()
        print('Received message: {}'.format(message))

        last_msg = message
        last_msg_timestamp = time.time()

# vim:sw=4:ts=4:et:

Ejemplo n.º 4
0
    def __init__(self, directions=None, **kwargs):
        """
        :param directions: Configuration for the motor directions. A direction is basically a configuration of the
            power delivered to each motor to allow whichever object you're controlling (wheels, robotic arms etc.) to
            move in a certain direction. In my experience the ZeroBorg always needs a bit of calibration, depending on
            factory defaults and the mechanical properties of the load it controls.

        Example configuration that I use to control a simple 4WD robot::

            directions = {
                "up": {
                    "motor_1_power": 0.4821428571428572,
                    "motor_2_power": 0.4821428571428572,
                    "motor_3_power": -0.6707142857142858,
                    "motor_4_power": -0.6707142857142858
                },
                "down": {
                    "motor_1_power": -0.4821428571428572,
                    "motor_2_power": -0.4821428571428572,
                    "motor_3_power": 0.825,
                    "motor_4_power": 0.825
                },
                "left": {
                    "motor_1_power": -0.1392857142857143,
                    "motor_2_power": -0.1392857142857143,
                    "motor_3_power": -1.0553571428571429,
                    "motor_4_power": -1.0553571428571429
                },
                "right": {
                    "motor_1_power": 1.0017857142857143,
                    "motor_2_power": 1.0017857142857143,
                    "motor_3_power": 0.6214285714285713,
                    "motor_4_power": 0.6214285714285713
                },
                "auto": {
                    "sensors": [
                        {
                            "plugin": "gpio.sensor.distance",
                            "threshold": 400.0,
                            "timeout": 2.0,
                            "above_threshold_direction": "up",
                            "below_threshold_direction": "left"
                        }
                    ]
                }
            }

        Note that the special direction "auto" can contain a configuration that allows your device to move autonomously
            based on the inputs it gets from some sensors.  In this case, I set the sensors configuration (a list) to
            periodically poll a GPIO-based ultrasound distance sensor plugin. ``timeout`` says after how long a poll
            attempt should fail. The plugin package is specified through ``plugin`` (``gpio.sensor.distance``) in this
            case, note that the plugin must be configured as well in order to work). The ``threshold`` value says
            around which value your logic should trigger. In this case, threshold=400 (40 cm). When the distance value
            is above that threshold (``above_threshold_direction``), then go "up" (no obstacles ahead). Otherwise
            (``below_threshold_direction``), turn "left" (avoid the obstacle).

        :type directions: dict
        """

        if directions is None:
            directions = {}

        import platypush.plugins.gpio.zeroborg.lib as ZeroBorg
        super().__init__(**kwargs)

        self.directions = directions
        self.auto_mode = False
        self._direction = None

        self.zb = ZeroBorg.ZeroBorg()
        self.zb.Init()
        self.zb.SetCommsFailsafe(True)
        self.zb.ResetEpo()
Ejemplo n.º 5
0
 def __init__(self, no_message_timeout=0.37, **kwargs):
     super().__init__(**kwargs)
     self.no_message_timeout = no_message_timeout
     self.zb = ZeroBorg.ZeroBorg()
     self.zb.Init()
     self.logger.info('Initialized Zeroborg infrared sensor backend')