Exemple #1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import logging
import time
import signal
import sys

from epuck import Controller, WrongCommand

c = Controller('/dev/rfcomm0', asynchronous=True)

bias = 200
too_close = 2000
max_speed = 1000
min_speed = -1000


# Signal handler to cleanup after shutdown
def handle_signal(signum, frame):
    r = c.set_speed(0, 0)
    r.join()
    sys.exit(0)


# SIGINT is interrupt signal sent by CTRL+C
signal.signal(signal.SIGINT, handle_signal)

while True:
    # Read values from proximity sensors
    r = c.get_proximity_sensors()
Exemple #2
0
#!/usr/bin/python

import functools
import Image as Img

from Tkinter import *
from ImageTk import PhotoImage
from epuck import Controller

c = Controller('/dev/rfcomm0', asynchronous=True)
c.set_camera(Controller.RGB565_MODE, 40, 40, 8)

root = Tk()
img_camera = Label(root)
img_camera.pack()
img_modified = Label(root)
img_modified.pack()


def hue(r, g, b):
    M = max(r, g, b)
    m = min(r, g, b)
    C = M - m

    if C == 0:
        return None
    if M == r:
        h = float(g - b) / C % 6
    elif M == g:
        h = float(b - r) / C + 2
    elif M == b:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import logging
import time
import signal
import sys

from epuck import Controller, WrongCommand

c = Controller('/dev/rfcomm0', asynchronous=True)

bias = 200
too_close = 2000
max_speed = 1000
min_speed = -1000

# Signal handler to cleanup after shutdown
def handle_signal(signum, frame):
    r = c.set_speed(0,0)
    r.join()
    sys.exit(0)

# SIGINT is interrupt signal sent by CTRL+C
signal.signal(signal.SIGINT, handle_signal)

while True:
    # Read values from proximity sensors
    r = c.get_proximity_sensors()
    r = r.get_response()
class Disco(object):
    """Test leds.

    Tests few effects with leds. The effect can be changed with turning selector.

    Turning selector values:

        0 -- Two rotating lights.
        1 -- Two rotating light in opposite directions.
        2 -- Blinking front led.
        15 -- Turn the effects off.

    """
    def __init__(self):
        logging.basicConfig(level=logging.WARNING)
        self.c = Controller('/dev/rfcomm0', asynchronous=True)
        self.state_request = None
        # Get first state
        self.state = self.c.get_turning_selector().get_response()

    def init_vars(self):
        """Initialize vars used for effects."""
        self.prev_i, self.i = 0, 0
        self.prev_j, self.j = 4, 4

    def init_state(self):
        """Initialize state."""
        self.init_vars()
        # Turn off all leds
        self.c.stop()
        self.c.set_front_led(0)

    def get_state(self):
        """Get the value of turning selector."""
        # The get_state has been called for the first time
        if self.state_request is None:
            self.state_request = self.c.get_turning_selector()
        # The response has been received
        elif self.state_request.response_received():
            new_state = self.state_request.get_response()
            # New state
            if new_state != self.state:
                self.state = new_state
                self.init_state()
            # Check the turning selector
            self.state_request = self.c.get_turning_selector()

    def run(self):
        """Do a step in the chosen effect."""
        if self.state == 0 or self.state == 1:
            self.c.set_led(self.prev_i, 0)
            self.c.set_led(self.i, 1)
            self.c.set_led(self.prev_j, 0)
            self.c.set_led(self.j, 1)
        elif self.state == 2:
            self.c.set_front_led(self.i)

    def update(self):
        """Update the vars used for chosen effect."""
        if self.state == 0:
            self.prev_i = self.i
            self.prev_j = self.j
            self.i = (self.i + 1) % 8
            self.j = (self.j + 1) % 8
        if self.state == 1:
            self.prev_i = self.i
            self.prev_j = self.j
            self.i = (self.i + 1) % 8
            self.j = (self.j - 1) % 8
        elif self.state == 2:
            self.i = 0 if self.i else 1

    def main_loop(self):
        """Main loop."""
        self.init_vars()
        while self.state != 15:
            # Update the state.
            self.get_state()
            # Do a step in the effect.
            self.run()
            # Update the effect.
            self.update()
            # Wait.
            time.sleep(0.1)

        # Turn off all leds.
        self.init_state()
 def __init__(self):
     logging.basicConfig(level=logging.WARNING)
     self.c = Controller('/dev/rfcomm0', asynchronous=True)
     self.state_request = None
     # Get first state
     self.state = self.c.get_turning_selector().get_response()
#!/usr/bin/python

import functools
import Image as Img

from Tkinter import *
from ImageTk import PhotoImage
from epuck import Controller

c = Controller('/dev/rfcomm0', asynchronous=True)
c.set_camera(Controller.RGB565_MODE, 40, 40, 8)

root = Tk()
img_camera = Label(root)
img_camera.pack()
img_modified = Label(root)
img_modified.pack()

def hue(r, g, b):
    M = max(r, g, b)
    m = min(r, g, b)
    C = M - m

    if C == 0:
        return None
    if M == r:
        h = float(g-b)/C % 6
    elif M == g:
        h = float(b-r)/C + 2
    elif M == b:
        h = float(r-g)/C + 4