def __init__(self, draw_gui=False, intrusion=None): """ Ctor """ object.__init__(self) self._has_gui = draw_gui self._gui_size = 0 self._frame_count = 0 self._gui_output = None # Initialise background (500 x 500) self._background = [[ Rgb(DEFAULT_BG_R, DEFAULT_BG_G, DEFAULT_BG_B) for _ in range(0, 500) ] for _ in range(0, 500)] self._turtles = {} self._id_counter = 0 self._update_interval = None rospy.set_param("background_r", DEFAULT_BG_R) rospy.set_param("background_g", DEFAULT_BG_G) rospy.set_param("background_b", DEFAULT_BG_B) rospy.loginfo("Starting turtle frame with parent node %s", rospy.get_name()) trt_x = random.randrange(0, self.get_width()) trt_y = random.randrange(0, self.get_height()) self._spawn_turtle(trt_x, trt_y) # Colouring the background # Window is 500 x 500, starting bottom left at 0,0 and ending top right at 499,499 # Top left: Pastel purple self._draw_area(Rgb.pastel_purple(), Point(0, 250), Point(249, 499)) # Top right: Pastel yellow self._draw_area(Rgb.pastel_yellow(), Point(250, 250), Point(499, 499)) # Bottom left: Pastel green self._draw_area(Rgb.pastel_green(), Point(0, 0), Point(249, 249)) # Bottom right: Pastel blue self._draw_area(Rgb.pastel_blue(), Point(250, 0), Point(499, 249)) # Intrusion zone (middle): Red self._draw_red(intrusion) # Initialise GUI (if requested) self._redraw() # Initialise update timer (16 msec) self._update_interval = rospy.Duration(0.016) rospy.Timer(self._update_interval, self._update_turtles)
def _get_output_letter(rgb): """ Produce a letter for the given Rgb. Returns "?" for unknown colours. """ if rgb == Rgb.pastel_purple(): return "p" elif rgb == Rgb.pastel_yellow(): return "y" elif rgb == Rgb.pastel_green(): return "g" elif rgb == Rgb.pastel_blue(): return "b" elif rgb == Rgb.strong_red(): return " " return "?"
def rgb_init(num_led=io_conf.get('ws'), pin=None): # default autoinit ws if pinout.WS_LED_PIN is None: print("Warning: WS LED not supported on this board") return if num_led is None or num_led == 0: print("Warning: Number of WS LED is 0") return from util.rgb import Rgb # setupNeopixel ws = Rgb(pin, num_led) return ws
def _draw_red(self, intrusion): """ Draw a red area in the center based on the intrusion level. """ if intrusion is None: return if intrusion not in self.POSSIBLE_INTRUSION_LEVELS: raise ValueError( "Given value [{}] for argument \"intrusion\" is invalid". format(intrusion)) from_point = Point(0, 0) to_point = Point(0, 0) colour = Rgb() assert (len(self.POSSIBLE_INTRUSION_LEVELS) == 3) # Easy: 40 % strong_red / 316 * 316 if intrusion == self.POSSIBLE_INTRUSION_LEVELS[0]: from_point = Point(92, 92) to_point = Point(407, 407) colour = Rgb.strong_red() # Medium: 20 % med_red / 224 * 224 elif intrusion == self.POSSIBLE_INTRUSION_LEVELS[1]: from_point = Point(138, 138) to_point = Point(361, 361) colour = Rgb.med_red() # Hard: 5 % light_red / 112 * 112 elif intrusion == self.POSSIBLE_INTRUSION_LEVELS[2]: from_point = Point(194, 194) to_point = Point(305, 305) colour = Rgb.light_red() else: raise NotImplementedError( "draw_red: Intrusion level not implemented") # TODO TEMP Currently intruded means ALL is red! from_point = Point(0, 0) to_point = Point(499, 499) self._draw_area(colour, from_point, to_point)
# octopusLAB simple example # ESP32board with "RGB WS LED" # run: import examples.rgb_blink from util.rgb import Rgb # from util.octopus import led # short way from util.pinout import set_pinout pinout = set_pinout() # set board pinout from util.io_config import get_from_file io_conf = get_from_file() ws = Rgb(pinout.WS_LED_PIN, io_conf.get('ws')) print("---examples/rgb_blink.py---") # start main loop while True: ws.simpleTest()
print("This is simple Micropython example | ESP32 & octopusLAB") speed = 900 from util.shell.terminal import getUid uID5 = getUid(short=5) from time import sleep from util.pinout import set_pinout pinout = set_pinout() from util.rgb import Rgb ws = Rgb(pinout.PWM3_PIN) ws.simpleTest() print("DCmotors init") from util.dcmotors import Motor, Steering motor_r = Motor(pinout.MOTOR_1A, pinout.MOTOR_2A, pinout.MOTOR_12EN) motor_l = Motor(pinout.MOTOR_3A, pinout.MOTOR_4A, pinout.MOTOR_34EN) steering = Steering(motor_l, motor_r) from util.led import Led led = Led(2) led.blink() steering.center(speed)
from util.buzzer import Notes def beep(f=1000, l=50): # noqa: E741 piezzo.beep(f, l) def tone(f, l=300): # noqa: E741 piezzo.play_tone(f, l) # else: # piezzo =Buzzer(None) if io_conf.get('ws'): print("ws | ",end="") from util.rgb import Rgb from util.colors import * if pinout.WS_LED_PIN is None: print("Warning: WS LED not supported on this board") else: ws = Rgb(pinout.WS_LED_PIN,io_conf.get('ws')) # default rgb init def rgb_init(num_led=io_conf.get('ws'), pin=None): # default autoinit ws if pinout.WS_LED_PIN is None: print("Warning: WS LED not supported on this board") return if num_led is None or num_led == 0: print("Warning: Number of WS LED is 0") return from util.rgb import Rgb # setupNeopixel ws = Rgb(pin, num_led) return ws #if io_conf.get('fet'): # print("fet | ",end="") # FET = PWM(Pin(pinout.MFET_PIN), freq=500)
# The MIT License (MIT) # Copyright (c) 2020 Jan Cespivo, Jan Copak # octopusLAB pubsub example from time import sleep from examples.pubsub.ps_init import pubsub print("start: ps_rgb.py") from util.rgb import Rgb rgb = Rgb(15) # robot board default rgb.color((0, 0, 0)) while True: rgb.color((128, 0, 0)) pubsub.publish('value', 1) sleep(1) rgb.color((0, 128, 0)) pubsub.publish('value', 2) sleep(1) rgb.color((0, 0, 128)) pubsub.publish('value', 3) sleep(1)
config_setkeys = [ "influx_url", "influx_db", "influx_usr", "influx_psw", "timer_interval", "treshold" ] errorcount = 0 reconnectcount = 0 powerMode = False print("octopusLab solar regulator: ", _ver) # --- init --- print("--- init --- RAM free: " + str(mem_free())) pinout = set_pinout() ws = Rgb(pinout.WS_LED_PIN, 1) led_button = Button(0, release_value=1) built_in_led = Pin(2, Pin.OUT) anB = Analog(36) # Battery anS = Analog(39) # Solar re1 = Relay(pinout.PWM1_PIN) re2 = Relay(pinout.PWM2_PIN) re1.value(1) # inverse re2.value(1) def batt_adc(): valB = anB.get_adc_aver(8)
from util.pinout import set_pinout from util.octopus import disp7_init from util.rgb import Rgb from time import sleep pinout = set_pinout() from hcsr04 import HCSR04 d7 = disp7_init() ws = Rgb(4) print("ulrasonic distance sensor") # servo1: 17, servo2: 16, 4 # t16 / e17 # Echo module echo = HCSR04(trigger_pin=pinout.PWM2_PIN, echo_pin=pinout.PWM1_PIN) while True: echo_cm = echo.distance_cm() d7.show(int(echo_cm)) if echo_cm > 15: ws.color((32, 0, 0)) print("---treshold---") else: ws.color((0, 32, 0)) print(echo_cm) sleep(0.5)
from time import sleep from util.led import Led from util.rgb import Rgb from util.octopus import disp7_init, printOctopus from util.pinout import set_pinout print("this is simple Micropython example | ESP32 & octopusLAB") printOctopus() pinout = set_pinout() # set board pinout from util.io_config import get_from_file io_conf = get_from_file() led = Led(2) led.blink() ws = Rgb(pinout.WS_LED_PIN,io_conf.get('ws')) ws.simpleTest() d7 = disp7_init() # 7segment (8digit) display init def d7pause(ch = "-", sl = 0.5): for i in range(8): d7.show(" "*i + ch) sleep(sl) sleep(2) d7pause(sl=0.1) ws.rainbow_cycle() ws.color((0,0,0))