def InitUI(self): blockAutorun = Block(self, 'Autorun') self.bindAutorun = BindInput(blockAutorun, hotkey=config.get_param('autorun_hk'), isOneKey=True) self.checkAutorun = wx.CheckBox(blockAutorun) self.checkAutorun.SetValue(config.get_param('autorun_state')) blockAutorun.add(self.bindAutorun) blockAutorun.add(self.checkAutorun, label='Activated: ') blockDwarfglitch = Block(self, 'Dwarf glitch') self.bindDwarfglitch = BindInput( blockDwarfglitch, hotkey=config.get_param('dwarfglitch_hk')) self.checkDwarfglitch = wx.CheckBox(blockDwarfglitch) self.checkDwarfglitch.SetValue(config.get_param('dwarfglitch_state')) blockDwarfglitch.add(self.bindDwarfglitch) blockDwarfglitch.add(self.checkDwarfglitch, label='Activated: ') hbox2 = wx.BoxSizer(wx.HORIZONTAL) self.applyBtn = wx.Button(self, label='Apply') # # self.applyBtn.Enable(False) hbox2.Add(self.applyBtn) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(blockAutorun, flag=wx.ALL | wx.EXPAND, border=5) vbox.Add(blockDwarfglitch, flag=wx.ALL | wx.EXPAND, border=5) vbox.Add(hbox2, flag=wx.ALIGN_CENTER | wx.TOP | wx.BOTTOM, border=10) self.SetSizer(vbox) self.applyBtn.Bind(wx.EVT_BUTTON, self.OnApply)
def on_config(self, e): self.autorunHK.disable() dlg = SettingsDialog(self.frame) dlg.ShowModal() self.autorunHK.hkAutorun = config.get_param('autorun_hk') self.autorunHK.hkDwarfglitch = config.get_param('dwarfglitch_hk') self.autorunHK.enable(config.get_param('autorun_state'), config.get_param('dwarfglitch_state'))
def inline_query(params,\ proxy_type=config.get_param('proxy_type'),\ proxy_url=config.get_param('proxy_url'),\ telegram_url=config.get_param('telegram_url'),\ bot_token=config.get_param('bot_token')): proxies = {proxy_type: proxy_url} telegram_method = telegram_url + bot_token + '/answerInlineQuery' return requests.get(telegram_method, params=params, proxies=proxies)
def send_message(params,\ proxy_type=config.get_param('proxy_type'),\ proxy_url=config.get_param('proxy_url'),\ telegram_url=config.get_param('telegram_url'),\ bot_token=config.get_param('bot_token')): proxies = {proxy_type: proxy_url} telegram_method = telegram_url + bot_token + '/sendMessage' return requests.get(telegram_method, params=params, proxies=proxies)
def update_message(params,\ proxy_type=config.get_param('proxy_type'),\ proxy_url=config.get_param('proxy_url'),\ telegram_url=config.get_param('telegram_url'),\ bot_token=config.get_param('bot_token')): proxies = {proxy_type: proxy_url} telegram_method = telegram_url + bot_token + '/editMessageReplyMarkup' return requests.get(telegram_method, params=params, proxies=proxies)
def get_updates(params,\ proxy_type=config.get_param('proxy_type'),\ proxy_url=config.get_param('proxy_url'),\ telegram_url=config.get_param('telegram_url'),\ bot_token=config.get_param('bot_token')): proxies = {proxy_type: proxy_url} telegram_method = telegram_url + bot_token + '/getUpdates' print(telegram_method) return requests.get(telegram_method, params=params, proxies=proxies)
def servo_180(state): servo_channel = config.get_param('servo_camera_channel') if state: gpio.set_servo_pulsewidth(servo_channel, servo_camera_front ) else: gpio.set_servo_pulsewidth(servo_channel, servo_camera_back ) master.after(500, lambda: gpio.set_servo_pulsewidth(config.get_param('servo_camera_channel'), 0))
def start_vision(): os.system('killall mplayer') time.sleep(1) print "start caputre" os.system(capture_hd_image_cmd % config.get_param('ip')) print "finish capture" img_hd = cv2.imread("img.jpg") print "get picture" analyse_picture(config.get_param('matrix_calibration_camera'), config.get_param('coefficient_distortion'), img_hd) pass
def __init__(self, frame): self.frame = frame self.autorunHK = autorun.AutoRunner(config.get_param('autorun_hk'), config.get_param('dwarfglitch_hk')) super().__init__() self.set_icon(TRAY_ICON) self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.on_config) self.onGo = True self.dayzState = None if self.onGo: wx.CallLater(1000, self.on_timer)
def on_timer(self): if not self.onGo: return newState = proccheck.process_exists(PROCESS_NAME) if self.dayzState != newState: if newState: self.autorunHK.enable(config.get_param('autorun_state'), config.get_param('dwarfglitch_state')) notify('Autorun is ready.') elif not self.dayzState is None: self.autorunHK.disable() notify('Autoran is stopped.') self.dayzState = newState wx.CallLater(1000, self.on_timer)
def main(): global arm, gpio, master, running, sm ip = config.get_param('control_ip') arm = rpyc.connect(ip, 18861).root gpio = pigpio.pi(ip) master = Tk() labels = init_ui(master) t = gpioloop() t.start() t1 = gamepadloop() t1.start() t2 = dynamixelInfoPinger(labels, arm) t2.start() sm = ArmStateManager(arm, keys, gpio) sm.start() mainloop() sm.running = False running = False t.join() t1.join() t2.join() sm.join()
def main(): global luminosity, gpio, w, running, master ip = config.get_param('ip') gpio = pigpio.pi(ip) master = Tk() master.title('Pupper control') master.geometry('500x500') Button(master, text="START VISION", command=start_vision).grid(row=2, column=0) master.bind("<KeyPress>", keydown) master.bind("<KeyRelease>", keyup) start_stream() t = gpioloop() t.start() t1 = gamepadloop() t1.start() mainloop() running = False t.join() t1.join()
def start_stream(): if not os.getenv('NO_CAMERA'): os.system(start_stream_cmd % config.get_param('ip')) time.sleep(1) os.system('''i3-msg '[class="MPlayer"] floating enable' ''')
def keydown(e): global x, y, z, r, light_state, light_value, rotated_servo k = e.char keys[e.char] = 1 if e.char == 'l': if(light_state == True): light_value = 50 light_state = False else: light_value = 0 light_state = True elif e.char == 'm' and light_value <= 100: light_value += 5 elif e.char == 'n' and light_value > 5: light_value -= 5 gpio.set_PWM_dutycycle(5, light_value) if e.char == 'p': global val_servo if(val_servo <= 2450): val_servo += 50 gpio.set_servo_pulsewidth(config.get_param('servo_camera_channel'), val_servo) master.after(100, lambda: gpio.set_servo_pulsewidth(config.get_param('servo_camera_channel'), 0)) if e.char == 'o': global val_servo if(val_servo >= 550): val_servo -= 50 gpio.set_servo_pulsewidth(config.get_param('servo_camera_channel'), val_servo) master.after(100, lambda: gpio.set_servo_pulsewidth(config.get_param('servo_camera_channel'), 0)) if e.char == 'k': if rotated_servo: gpio.set_servo_pulsewidth(config.get_param('servo_camera_channel'), servo_camera_front) val_servo = servo_camera_front #gpio.hardware_PWM(19, 50, 100000) # 800Hz 25% dutycycle else: gpio.set_servo_pulsewidth(config.get_param('servo_camera_channel'), servo_camera_back) val_servo = servo_camera_back #gpio.hardware_PWM(19, 50, 900000) # 800Hz 25% dutycycle rotated_servo = not rotated_servo master.after(500, lambda: gpio.set_servo_pulsewidth(config.get_param('servo_camera_channel'), 0)) if e.char == 'j': gpio.set_servo_pulsewidth(config.get_param('servo_camera_channel'), 0)
def __init__(self): Thread.__init__(self) self.speed = 0 self.state = 'stop' self.target_x = 0 self.actual_x = 0 self.acceleration_ratio = config.get_param('acceleration_ratio') self.motor_left_actual_speed = 0 self.motor_left_target_speed = 0 self.motor_right_actual_speed = 0 self.motor_right_target_speed = 0 self.states = {}
def check(self, directory, files): # {{{ super(CheckerPath, self).check(directory, files) # Get the correct path from the configuration file pattern_str = get_param('patterns', 'path') pat = re.compile(pattern_str) LOG.debug("matching %s with %s",directory,pattern_str) mat = pat.match(directory) if mat: result = True else: LOG.warn("Path '%s' does not match pattern '%s'") result = False return result
def run(self): while running: if 'w' in keys and 'd' in keys: self.motor_left_target_speed = forward_mov_speed self.motor_right_target_speed = forward_mov_speed/2 elif 'w' in keys and 'a' in keys: self.motor_left_target_speed = forward_mov_speed/2 self.motor_right_target_speed = forward_mov_speed elif 's' in keys and 'd' in keys: self.motor_left_target_speed = -backwards_mov_speed self.motor_right_target_speed = -backwards_mov_speed/2 elif 's' in keys and 'a' in keys: self.motor_left_target_speed = -backwards_mov_speed/2 self.motor_right_target_speed = -backwards_mov_speed elif 'w' in keys or 'forward' in pad_keys: self.motor_left_target_speed = forward_mov_speed self.motor_right_target_speed = forward_mov_speed elif 'e' in keys: self.motor_right_target_speed = forward_mov_speed self.motor_left_target_speed = 0 elif 'q' in keys: self.motor_left_target_speed = forward_mov_speed self.motor_right_target_speed = 0 elif 's' in keys or 'backward' in pad_keys: self.motor_left_target_speed = -backwards_mov_speed self.motor_right_target_speed = -backwards_mov_speed elif 'd' in keys or 'right' in pad_keys: self.motor_left_target_speed = rotation_speed self.motor_right_target_speed = -rotation_speed elif 'a' in keys or 'left' in pad_keys: self.motor_left_target_speed = -rotation_speed self.motor_right_target_speed = rotation_speed elif 'z' in keys: self.motor_left_target_speed = -2*backwards_mov_speed self.motor_right_target_speed = -2*backwards_mov_speed elif 'f' in keys: self.motor_left_target_speed = boost_forward_speed self.motor_right_target_speed = boost_forward_speed else: self.motor_left_target_speed = 0 self.motor_right_target_speed = 0 dx_left = sign(int(self.motor_left_target_speed * 10) - int(self.motor_left_actual_speed * 10)) dx_right = sign(int(self.motor_right_target_speed * 10) - int(self.motor_right_actual_speed * 10)) self.motor_left_actual_speed += dx_left * self.acceleration_ratio self.motor_right_actual_speed += dx_right * self.acceleration_ratio # self.motor_left_actual_speed = self.motor_left_target_speed # self.motor_right_actual_speed = self.motor_right_target_speed self.motor_left_actual_speed = int(self.motor_left_actual_speed * config.get_param('speed_motor_left')/100.0) self.motor_right_actual_speed = int(self.motor_right_actual_speed * config.get_param('speed_motor_right')/100.0) if self.motor_left_actual_speed < 0: write_pwm([config.get_param('motor_left_back_channel')], abs(self.motor_left_actual_speed)) write_pwm([config.get_param('motor_left_for_channel')], 0) else: write_pwm([config.get_param('motor_left_for_channel')], self.motor_left_actual_speed) write_pwm([config.get_param('motor_left_back_channel')], 0) if self.motor_right_actual_speed < 0: write_pwm([config.get_param('motor_right_back_channel')], abs(self.motor_right_actual_speed)) write_pwm([config.get_param('motor_right_for_channel')], 0) else: write_pwm([config.get_param('motor_right_for_channel')], self.motor_right_actual_speed) write_pwm([config.get_param('motor_right_back_channel')], 0) time.sleep(1/60.0)
import json import config import main_functions chat_id = config.get_param('chat_id') print(chat_id) if chat_id == '0': exit(-1) test_mess = 'Please respond the message' # https://core.telegram.org/bots/api#deletemessage # https://core.telegram.org/bots/api#forcereply force_reply = { 'force_reply': True, } message_params_force_reply = { 'chat_id': chat_id, 'text': test_mess, 'reply_markup': json.dumps(force_reply) } answer = main_functions.send_message(message_params_force_reply) print(answer.text)
running = True label_vars = {} keys = {} pad_keys = {} states = {} grip_state = True rotated_servo = False master = None light_state = True light_value = 0 JOYSTICK_IGNORE_THRESHOLD = 32000 # Robot Moving speed forward_mov_speed = config.get_param('for_speed') backwards_mov_speed = config.get_param('back_speed') rotation_speed = config.get_param('rotation_speed') boost_forward_speed = config.get_param('boost_speed') servo_camera_front = config.get_param('servo_camera_front') servo_camera_back = config.get_param('servo_camera_back') luminosity_step = 255/5 luminosity = luminosity_step start_stream_cmd = "mplayer -fps 200 -demuxer h264es ffmpeg://tcp://%s:9999 > /dev/null &" capture_hd_image_cmd = "nc %s 9000 > img.jpg"
def main(instance): print 'waiting for connection to ' + instance + '...' wait_for_host(get_param('ip')) ui.main()
import json import config import main_functions chat_id = config.get_param('chat_id') print(chat_id) if chat_id == '0': exit(-1) test_mess = config.get_param('sample_text') # ****************************************************** key1 = {'text': 'key1', 'callback_data': 'key1'} key2 = {'text': 'key2', 'callback_data': 'key2'} key3 = {'text': 'key3', 'callback_data': 'key3'} key4 = {'text': 'key4', 'callback_data': 'key4'} key_switch = { 'text': 'switch_key', 'switch_inline_query_current_chat': 'some query' } key_row1 = [key1, key2] key_row2 = [key3, key4] key_row3 = [ key_switch, ] inline_keyboard_markup = {'inline_keyboard': [key_row1, key_row2, key_row3]} inline_keyboard_markup2 = {'inline_keyboard': [key_row2, key_row1]} # https://core.telegram.org/bots/api#inlinekeyboardmarkup # ****************************************************** print(json.dumps(inline_keyboard_markup))