Example #1
0
 def __init__(self, brickConfiguration, usedSensors=None):
     self.cfg = brickConfiguration
     dir = os.path.dirname(__file__)
     self.font_s = ImageFont.load(os.path.join(dir, 'ter-u12n_unicode.pil'))
     self.font_x = ImageFont.load(os.path.join(dir, 'ter-u18n_unicode.pil'))
     self.lcd = ev3dev.Screen()
     self.led = ev3dev.Leds
     self.keys = ev3dev.Button()
     self.sound = ev3dev.Sound
     (self.font_w, self.font_h) = self.lcd.draw.textsize('X',
                                                         font=self.font_s)
     self.timers = {}
     self.sys_bus = None
     self.bt_server = None
     self.bt_connections = []
Example #2
0
 def __init__(self, brickConfiguration, usedSensors=None):
     self.cfg = brickConfiguration
     dir = os.path.dirname(__file__)
     # char size: 6 x 12 -> num-chars: 29.666667 x 10.666667
     self.font_s = ImageFont.load(os.path.join(dir, 'ter-u12n_unicode.pil'))
     # char size: 10 x 18 -> num-chars: 17.800000 x 7.111111
     # self.font_s = ImageFont.load(os.path.join(dir, 'ter-u18n_unicode.pil'))
     self.lcd = ev3dev.Screen()
     self.led = ev3dev.Leds
     self.keys = ev3dev.Button()
     self.sound = ev3dev.Sound
     (self.font_w, self.font_h) = self.lcd.draw.textsize('X',
                                                         font=self.font_s)
     # logger.info('char size: %d x %d -> num-chars: %f x %f',
     #     self.font_w, self.font_h, 178 / self.font_w, 128 / self.font_h)
     self.timers = {}
     self.sys_bus = None
     self.bt_server = None
     self.bt_connections = []
     self.lang = 'de'
Example #3
0
    def run(self):
        global c, plotter
        buttons = ev.Button()
        right_or_up_pressed_earlier = False
        left_or_down_pressed_earlier = False

        while running:

            if type(c) == dict:
                # We got settings
                if 'kp' in c:
                    #We got pid settings
                    plotter.Kp = c['kp']
                    plotter.Ti = c['ti']
                    plotter.Td = c['td']
                    plotter.cm_to_deg = int(c['cm_to_deg'])
                    wsSend("PID parameters set")

                if 'll' in c:
                    #we got rope length settings
                    plotter.l_rope_0 = c['ll']
                    plotter.r_rope_0 = c['lr']
                    plotter.att_dist = c['aw']
                    plotter.r_step = float(c['rs'])
                    wsSend("Plotter settings set")
                c = ''

            # Socket commands
            if c == 'left-fwd':
                plotter.left_fwd()

            elif c == 'left-back':
                plotter.left_back()

            elif c == 'right-fwd':
                plotter.right_fwd()

            elif c == 'right-back':
                plotter.right_back()

            elif buttons.right:
                plotter.left_fwd()
                right_or_up_pressed_earlier = True

            elif buttons.up:
                plotter.left_back()
                right_or_up_pressed_earlier = True

            elif buttons.down:
                plotter.right_fwd()
                left_or_down_pressed_earlier = True

            elif buttons.left:
                plotter.right_back()
                left_or_down_pressed_earlier = True

            elif not (buttons.left
                      and buttons.down) and left_or_down_pressed_earlier:
                plotter.right_stop()
                left_or_down_pressed_earlier = False

            elif not (buttons.right
                      and buttons.up) and right_or_up_pressed_earlier:
                plotter.left_stop()
                right_or_up_pressed_earlier = False

            elif c == 'right-stop':
                plotter.right_stop()
                c = ''

            elif c == 'left-stop':
                plotter.left_stop()
                c = ''

            elif c == 'pu':
                plotter.pen_up()
                c = ''

            elif c == 'pd':
                plotter.pen_down()
                c = ''

            elif c == 'stop':
                plotter.left_stop()
                plotter.right_stop()
                c = ''

            elif c == 'reload':
                plotter.reload_chalk()

            elif c == 'testdrive':
                plotter.test_drive()
                c = ''

            elif c == 'plot':
                start_time = time.time()
                # c stays 'plot' until another command is sent trough the socket
                plot_action = plotter.plot_from_file('uploads/coords.csv')
                c = 'plotting'

            elif c == 'plotting':
                try:
                    pct_done = next(plot_action)
                    wsSend(str(pct_done))
                    #wsSend("[ {0:.2f}V ] Plot {1:.2f}% done".format(plotter.battery.measured_voltage/1000000.0, pct_done))
                except StopIteration:
                    c = ''
                    if start_time:
                        elapsed = time.time() - start_time
                        elapsed_str = time.strftime("%Hh %Mm %Ss",
                                                    time.gmtime(elapsed))
                        wsSend("Done plotting after " + elapsed_str)

            elif c == 'zero':
                wsSend("zero motor positions")
                plotter.set_control_zeroes()
                c = ''
            elif c == 'plotcircles':
                start_time = time.time()
                wsSend("Plotting circles")
                # c stays 'plot' until another command is sent trough the socket
                plot_action = plotter.optimized_etch()
                c = 'plotting'
            elif c == 'plotwaves':
                wsSend("Plotting waves")
                # c stays 'plot' until another command is sent trough the socket
                plot_action = plotter.plot_circle_waves()
                c = 'plotting'

            # Button commands
            if buttons.backspace:
                tornado.ioloop.IOLoop.instance().stop()
                # Close all sockets
                for ws in websockets:
                    ws.close()

            self.throttle.throttle()  # Don't go too fast.

        # Stopped running. Shutting down all motors.
        plotter.stop_all_motors()
        plotter_log.info("Socket thread stopped")
Example #4
0
#!/usr/bin/env python3

import ev3dev.auto as ev3
import time
import ev3dev.fonts as fonts

TOTAL_IDS = 16
DEG_PER_ID = 20

dial = ev3.Motor(ev3.OUTPUT_C)
screen = ev3.Screen()
btn = ev3.Button()

try:
    from id import MY_ID
except:
    MY_ID = 0

dial.position = MY_ID * DEG_PER_ID + DEG_PER_ID // 2
while not btn.enter:
    p = dial.position
    id = (p % (TOTAL_IDS * DEG_PER_ID)) // DEG_PER_ID
    screen.clear()
    screen.draw.text((70, 50), str(id), font=fonts.load('luBS24'))
    screen.update()
    time.sleep(0.01)

id_file = open("id.py", 'w')
id_file.write("MY_ID = {0}\n".format(id))