def gui_connection_init(self): self.gui_udp_client = rover_socket.UDP_server(50010, 0, "192.168.5.2") self.gui_send_status_udp_server = rover_socket.UDP_server( 50012, 0, "192.168.5.2") self.gui_server_run = True self.gui_command = {"gss": self._gui_set_speed, "gbm": self._gui_bm, "gum":self._gui_um, \ "gbms": self._gui_bm_stop, "gums":self._gui_um_stop} self.thread_gui = threading.Thread(target=self.gui_send_and_read, daemon=True) self.thread_gui.start() self.thread_gui_get_command = threading.Thread( target=self.gui_get_command, daemon=True) self.thread_gui_get_command.start()
def lidar_init(self): '''Initialize Lidar system and communication''' try: logging.info("Initialize lidar server\n") subprocess.Popen('python3 rover_rplidar.py', shell=True, start_new_session=True) self.lidar_server = rover_socket.TCP_server(50004) self.lidar_thread_server = rover_socket.UDP_server(50005) lidar_data = self.lidar_server.recv_list() if lidar_data == ['L', 'status', 'Good']: logging.info( "Lidar communication successfully established !\ncommunication center get : {} \n" .format(lidar_data)) self.lidar_server_run = True self.lidar_thread_server_run = True self.lidar_start_background_thread() else: self.end_lidar_server() self.end_lidar_thread_server() print( 'Undefined communication error of LiDAR, please check test message' ) logging.info( "Undefined communication error of Vision module, please check test message\n" ) raise KeyboardInterrupt except: print('\nError from Main : lidar_init\n') traceback.print_exc() logging.info('Main initializing fail at lidar_init()\n') logging.exception("Main initializing fail at lidar_init() : \n") self.lidar_server.close() self.lidar_thread_server.close()
def vision_init(self): '''Initialize vision system and communication ''' try: logging.info("Initialize vision server\n") subprocess.Popen('python3 rover_vision.py', shell=True, start_new_session=True) self.vision_thread_server = rover_socket.UDP_server(50003) self.vision_server = rover_socket.TCP_server(50002) receive = self.vision_server.recv_list() if receive == ['V', 'next']: logging.info("Vision communication successfully established !\ \ncommunication center get : {} \n".format(receive)) self.vision_server_run = True self.vision_thread_server_run = True self.vision_idle = True self.vision_start_background_thread() else: self.end_vision_server() self.end_vision_thread_server() print('{} received from TCN_vision'.format(receive)) print( 'Either vision module got problem or undefined communication error of\ Vision module, please check test message') logging.info('{} received from TCN_vision'.format(receive)) logging.info( "Either vision module got problem or undefined communication \ error of Vision module, please check test message\n") except: self.vision_server.close() self.vision_thread_server.close() print('\nError from Main : vision_init \n') traceback.print_exc() logging.info('Main initializing fail at vision_init()\n') logging.exception("Got error : \n")
def gui_get_command(self): while self.gui_server_run: self.gui_get_command_udp_server = rover_socket.UDP_server( 50013, 0, '192.168.5.2') time.sleep(0.1) self.gui_get_command_receive = self.gui_get_command_udp_server.recv_list( ) if self.gui_get_command_receive is not None: if self.gui_get_command_receive[0] in self.gui_command: self.gui_command[self.gui_get_command_receive[0]]() elif self.gui_get_command_receive[ 0] in self.command_dictionary: self.command_dictionary[self.gui_get_command_receive[0]]( ) # Referenced from CommanderDictionary elif self.gui_get_command_receive[ 0] in self.command_vision_dictionary: self.command_vision_dictionary[ self.gui_get_command_receive[0]]() elif self.gui_get_command_receive[ 0] in self.command_lidar_dictionary: self.command_lidar_dictionary[ self.gui_get_command_receive[0]]() else: print('Unknown Command') self.gui_get_command_udp_server.close()
def __init__(self): self.car_control_server = rover_socket.UDP_server( 50011, 0, "192.168.5.2") self.car_control = Adafruit_PCA9685.PCA9685() self.car_control.set_pwm_freq(60) self.car_control_server_run = True self.car_control_receive = None self.car_control_previous_receive = None self.car_control_state = 'stop' self.car_control_forward_pwm = 410 # 403 self.car_control_backward_pwm = 370 # 381 self.car_control_stop_pwm = 400 self.car_control_add_speed = 1 # Speed adjust from gui threading.Thread.__init__(self, daemon=True) thread = threading.Thread(target=self.car_control_main, daemon=True) thread.start()
num = 10 while run: # command = int(input("Enter0 ")) print(num) pwm.set_pwm(3, mode, num) time.sleep(0.2) num += 5 if num > 4040: run = False import Adafruit_PCA9685 import time import rover_socket import threading server = rover_socket.UDP_server(50008, 0, '192.168.5.2') pwm = Adafruit_PCA9685.PCA9685() pwm.set_pwm_freq(60) def keep_forward_after_forward(): pwm.set_pwm(3, 0, 415) time.sleep(0.15) # pwm.set_pwm(3,0,400) # time.sleep(0.15) def forward_after_reverse(): pwm.set_pwm(3, 0, 415) time.sleep(0.15) pwm.set_pwm(3, 0, 400)