コード例 #1
0
    def start(self):
        myDebug(self.__class__.__name__, get_current_function_name())
        self.mViewController.start()
        self.mRobotController.start()
        self.mMainLoopTimer.start(1000/30)

        self.mViewController.navigateTo("ContentsNavWin")
コード例 #2
0
    def __init__(self, *args):
        myDebug(self.__class__.__name__, get_current_function_name())
        super(MultiViewFrame, self).__init__(*args)
        self.setStyleSheet(
            "color: rgb(0, 243, 255);background-color: rgba(255, 255, 255, 0); border:2px solid rgb(0, 178, 255);"
        )
        self.mMainLayout = QGridLayout(self)
        self.mMainLayout.setContentsMargins(1, 1, 1, 1)
        self.mMainLayout.setSpacing(1)

        self.mBackgound = QLabel(self)
        self.mBackgound.setGeometry(self.width() * 0.5 / 3,
                                    self.height() * 0.5 / 3,
                                    self.width() * 2 / 3,
                                    self.height() * 2 / 3)
        self.mBackgound.setStyleSheet(
            "background-color: rgba(255, 255, 255, 0); border:0px solid rgb(0, 0, 0)"
        )
        self.mBackgound.setAlignment(QtCore.Qt.AlignCenter)
        image = QPixmap("resource/images/earth.png")
        self.mBackgound.setPixmap(
            image.scaled(self.mBackgound.size(), QtCore.Qt.KeepAspectRatio,
                         QtCore.Qt.SmoothTransformation))
        self.mBackgound.show()

        self.mFocusedView = None
        self.mLastViewList = []
        self.mViewList = []
        self.isViewMaximizedStateChanged = False
        self.mMaximizedView = None
コード例 #3
0
 def deleteOptionList(self, ind):
     myDebug(self.__class__.__name__, get_current_function_name())
     if ind >= 0 and ind < len(self.mOptionList):
         self.mOptionList.pop(ind)
         self.mOptionFuncList.pop(ind)
     else:
         raise IndexError()
コード例 #4
0
    def __init__(self, *arg):
        myDebug(self.__class__.__name__, get_current_function_name())
        super(ContentsNavWin, self).__init__(*arg)
        loadUi(
            XSetting.getValue('Python/SrcDir') + 'Views/ContentsNavWin.ui',
            self)

        self.id = 'ContentsNavWin'
        self.name = 'ContentsNavWin'

        self.mImage_T = QPixmap()
        self.mImage_T.load('resource/icons/T.png')
        self.mImage_O = QPixmap()
        self.mImage_O.load('resource/icons/O.png')
        self.mImage_E = QPixmap()
        self.mImage_E.load('resource/icons/E.png')

        self.lbT.setAlignment(QtCore.Qt.AlignCenter)
        self.lbT.setPixmap(
            self.mImage_T.scaled(self.lbT.width(), self.lbT.height()))
        self.lbO.setAlignment(QtCore.Qt.AlignCenter)
        self.lbO.setPixmap(
            self.mImage_O.scaled(self.lbO.width(), self.lbO.height()))
        self.lbE.setAlignment(QtCore.Qt.AlignCenter)
        self.lbE.setPixmap(
            self.mImage_E.scaled(self.lbE.width(), self.lbE.height()))

        self.mkConnect()
コード例 #5
0
    def mkQMenu(self):
        myDebug(self.__class__.__name__, get_current_function_name())
        menu=QMenu(self)
        menu.setStyleSheet("""
        color: rgb(0, 243, 255);
        background-color: rgba(255, 255, 255, 0); 
        border:2px solid rgb(0, 108, 255);
        selection-background-color: rgba(183, 212, 255, 150);
        """
        )
        camera_list = QMenu(menu)
        camera_list.setTitle('新建相机视图')
        controller = MainController.getController()
        camera_names, camera_types = controller.mCameraController.getAvailableCameraNames()
        for ind, name in enumerate(camera_names):
            cam_action = QAction(name, camera_list)
            # cam_action.triggered.connect(self.mCameregister[ind])
            cam_action.triggered.connect(partial(self.on_add_camera_view, ind, camera_types[ind]))
            camera_list.addAction(cam_action)
        menu.addMenu(camera_list)

        add_image_proc_action = QAction('添加图像处理视图', menu)
        add_image_proc_action.triggered.connect(self.slot_add_image_proc_view)
        menu.addAction(add_image_proc_action)

        add_robot_action = QAction('添加机器人', menu)
        add_robot_action.triggered.connect(self.slot_add_robot)
        menu.addAction(add_robot_action)

        clear_views_action = QAction('清空视图', menu)
        clear_views_action.triggered.connect(self.slot_clearSubview)
        menu.addAction(clear_views_action)
        return menu
コード例 #6
0
 def contextMenuEvent(self, event: QContextMenuEvent):
     myDebug(self.__class__.__name__, get_current_function_name())
     # print(event.type(), ' ', QContextMenuEvent.MouseButtonRelease)
     # if event.type() == QContextMenuEvent.MouseButtonRelease:
     #     if event.button() == QtCore.Qt.RightButton:
     menu = self.mkQMenu()
     menu.exec_(event.globalPos())
コード例 #7
0
 def slot_view_focaus_changed(self):
     myDebug(self.__class__.__name__, get_current_function_name())
     if self.mFrameViewArea.mFocusedView:
         self.mSlm.setStringList(
             self.mFrameViewArea.mFocusedView.mOptionList)
     else:
         self.mSlm.setStringList([])
コード例 #8
0
 def mouseReleaseEvent(self, a0: QtGui.QMouseEvent):
     myDebug(self.__class__.__name__, get_current_function_name())
     super().mouseReleaseEvent(a0)
     if self.isFocused:
         self.signalFocusedChanged.emit(self, False)
     else:
         self.signalFocusedChanged.emit(self, True)
コード例 #9
0
 def start(self):
     myDebug(self.__class__.__name__, get_current_function_name())
     self.mMainWin.show()
     movie = QMovie("resource/images/background001.gif")
     for label_i in self.mMainWin.mlbBackgroundList:
         label_i.setMovie(movie)
         label_i.setScaledContents(True)
     movie.start()
コード例 #10
0
 def _addImageFlow(self, flow):
     myDebug(self.__class__.__name__, get_current_function_name())
     self.setImageFlowInput(flow)
     self.deleteOptionList(0)
     self.insertOptionList(flow.getName(), self.addImageFlowFunc, 0)
     if self.getOptionListLen() == 1:
         self.insertOptionList('添加图像处理模块', self.addImageProcFunc)
     self.signalFocusedChanged.emit(self, True)
コード例 #11
0
 def disconnect(self):
     myDebug(self.__class__.__name__, get_current_function_name())
     self.isConnected = False
     try:
         self.client_sock.close()
         self.mCamera.releaseCamera()
     except:
         pass
コード例 #12
0
 def loadConfigFile(self, path):
     myDebug(self.__class__.__name__, get_current_function_name())
     print(path)
     with open(path, 'r') as f:
         data = json.load(f)
         self.setRobotPolicy(data["policy"])
         for robot_data in data["robots"]:
             self.addRobot(robot_data)
コード例 #13
0
 def slot_subview_active_changed(self, view: ViewFrameBase, value: bool):
     myDebug(self.__class__.__name__, get_current_function_name())
     if self.mFocusedView:
         self.setFocusedView(None)
     if value:
         self.setFocusedView(view)
         # self.mFocusedView.active()
     else:
         view.deactive()
コード例 #14
0
    def __init__(self, parent, population, pos=np.array((0, 0, 0), dtype=np.float), orientation = np.zeros((3,3), dtype=np.float)) -> None:
        myDebug(self.__class__.__name__, get_current_function_name())
        super().__init__(parent)
        self.mRobotType = "RobotEpuck"
        self.mState = RobotControlMode.PolicyControl
        self.mCamera = CameraEPuck(self)
        self.mPopulation = population
        self.mPos = np.array(pos, dtype=np.float)
        self.mOrientation = np.array(orientation, dtype=np.float)
        self.mSpeedWheels:np.ndarray = np.zeros((1, 2), dtype=np.float)

        self.mTargetEulerAngle = 0.0      # 世界坐标系下目标角度
        self.mRobotEulerAngle  = 0.0      # 世界坐标系下机器人角度
        self.mX_t  = 0.0                  # 目标坐标系下机器人坐标
        self.mY_t  = 0.0                  # 目标坐标系下机器人坐标
        self.mLineSpeed = 0.0
        self.mRotationSpeed = 0.0
        self.mAlpha = 0.0
        self.mPreAlpha = 0.0
        self.mTheta = 0.0
        self.mBeta = 0.0

        # self.mTObsacle = target_obstacle    # 目标障碍物
        self.client_sock = 1000
        self.client_addr = "192.168.1.100"
        self.isConnected = False
        self.socket_error = 0
        self.isFirstConnect = True
        self.proximity = [0.0]*8  # 8个方向的距离传感器
        self.acceleration = 0.0 # 加速度
        self.orientation = 0.0  # 方向
        self.inclination = 0.0  # 倾斜度
        self.lightAvg = 0       # light sensor data
        self.gyroRaw = [0.0]*3    # Gyro
        self.magneticField = [0.0]*3    # Magnetometer
        self.distanceCm = 0.0   # ToF
        self.micVolume = [0]*4  # Microphone
        self.batteryRaw = 100.0 # Battery

        self.num_packets = 0
        self.mCommand = bytearray([0] * COMMAND_PACKET_SIZE)
        self.initCommand()
        self.mPolicy:RobotPolicyBase = None         # 机器人的决策,通过插件更改

        self.isGetLocationFromGlobal = True

        self.nearDestination = False
        self.toNextTarget = False   # if a robot has near the now target, it change the target value to the next target, to avoid speed down,

        # 参数
        self.MAX_SPEED = float(XSetting.getValue('Epuck/MAX_SPEED'))
        self.WHEEL_RADIUS = float(XSetting.getValue('Epuck/WHEEL_RADIUS'))
        self.AXLE_LENGTH = float(XSetting.getValue('Epuck/AXLE_LENGTH'))
        self.K_RHO = float(XSetting.getValue('Epuck/K_RHO'))
        self.K_ALPHA = float(XSetting.getValue('Epuck/K_ALPHA'))
        self.K_BETA = float(XSetting.getValue('Epuck/K_BETA'))
コード例 #15
0
 def windowSwitch(self, win: QWidget):
     myDebug(self.__class__.__name__, get_current_function_name())
     self.mCurrentWin: QFrame
     if self.mCurrentWin is not None:
         self.mMainLayout.replaceWidget(self.mCurrentWin, win)
         self.mCurrentWin.hide()
     else:
         self.mMainLayout.addWidget(win)
     self.mCurrentWin = win
     self.mCurrentWin.show()
コード例 #16
0
 def addSubview(self, view:ViewFrameBase):
     myDebug(self.__class__.__name__, get_current_function_name())
     if len(self.mViewList) < 36:
         self.mLastViewList = self.mViewList.copy()
         self.mViewList.append(view)
         view.signalDestroyed.connect(self.on_removeSubview)
         view.signalFocusedChanged.connect(self.slot_subview_active_changed)
         view.signalClearViews.connect(self.slot_clearSubview)
         view.signalAddImageProcView.connect(self.slot_add_image_proc_view)
         self.reLayoutView()
コード例 #17
0
 def insertOptionList(self, name, func, insert_ind=-1):
     myDebug(self.__class__.__name__, get_current_function_name())
     if insert_ind == -1 or len(self.mOptionList) == 0:
         self.mOptionList.append(name)
         self.mOptionFuncList.append(func)
     elif insert_ind >= 0 and insert_ind < len(self.mOptionList):
         self.mOptionList.insert(insert_ind, name)
         self.mOptionFuncList.insert(insert_ind, func)
     else:
         raise IndexError()
コード例 #18
0
 def contextMenuEvent(self, event: QContextMenuEvent):
     myDebug(self.__class__.__name__, get_current_function_name())
     # print(event.type(), ' ', QContextMenuEvent.MouseButtonRelease)
     # if event.type() == QContextMenuEvent.MouseButtonRelease:
     #     if event.button() == QtCore.Qt.RightButton:
     menu = self.mkQMenu()
     # set_robot_id_action = QAction('Set Robot ID', menu)
     # set_robot_id_action.triggered.connect(self.slot_set_robot_id)
     # menu.addAction(set_robot_id_action)
     menu.exec_(event.globalPos())
コード例 #19
0
 def slot_clearSubview(self):
     myDebug(self.__class__.__name__, get_current_function_name())
     self.mLastViewList = self.mViewList.copy()
     self.mViewList = []
     self.reLayoutView()
     camera_controller = MainController.getController().mCameraController
     for i in self.mLastViewList:
         i.destroy()
     camera_controller.releaseAllCamera()
     self.setFocusedView(None)
コード例 #20
0
    def navigateTo(self, win_name: str):
        myDebug(self.__class__.__name__, get_current_function_name())
        isFind = False
        for iter in self.mFrameList:
            if win_name.strip() == iter.name:
                self.windowSwitch(iter)
                isFind = True

        if not isFind:
            raise Exception("Fail to switch window. The name of win isn't exited, please checking.")
コード例 #21
0
 def setFocusedView(self, view):
     myDebug(self.__class__.__name__, get_current_function_name())
     if self.mFocusedView:
         self.mFocusedView.deactive()
         self.releaseKeyboard()
     self.mFocusedView = view
     if type(self.mFocusedView) is RobotFrame:
         self.grabKeyboard()
     
     self.signalViewFocusChanged.emit()
コード例 #22
0
    def contextMenuEvent(self, event: QContextMenuEvent):
        myDebug(self.__class__.__name__, get_current_function_name())
        # print(event.type(), ' ', QContextMenuEvent.MouseButtonRelease)
        # if event.type() == QContextMenuEvent.MouseButtonRelease:
        #     if event.button() == QtCore.Qt.RightButton:
        menu = self.mkQMenu()
        image_save_dir_set_action = QAction('设置图片保存路径', menu)
        image_save_dir_set_action.triggered.connect(self.on_image_save_dir_set)
        menu.addAction(image_save_dir_set_action)

        menu.exec_(event.globalPos())
コード例 #23
0
 def __init__(self, *arg):
     myDebug(self.__class__.__name__, get_current_function_name())
     super(MainController, self).__init__(*arg)
     self.mMainLoopTimer = QtCore.QTimer(self)
     self.mViewController = ViewController.ViewController()
     self.mCameraController = CameraController.CameraController()
     self.mRobotController = RobotController.RobotController()
     self.mCameraData = CameraData()
     self.mImageHandle = []
     self.initConnect()
     self.t1 = 0.0
コード例 #24
0
 def __init__(self, *arg):
     myDebug(self.__class__.__name__, get_current_function_name())
     super().__init__(*arg)
     self.controller = MainController.getController()
     self.robot_controller = RobotController.RobotController()
     self.robot_controller.start()
     self.mDataHandle = DataHandle()
     self.controller.addDataHandle(self.mDataHandle)
     self.mLayout.addWidget(self.mDataHandle.image_label)
     self.mDataHandle.image_label.show()
     self.mRobotPolicy = None
コード例 #25
0
 def on_add_camera_view(self, cam_id: int, cam_type: XCameraType):
     myDebug(self.__class__.__name__, get_current_function_name())
     camera_controller = MainController.getController().mCameraController
     camera = camera_controller.getCamera(cam_id)
     if camera and camera.isOpen():
         print('该相机已经打开')
     else:
         camera_controller.startCamera(cam_id, cam_type)
         view = CameraViewFrame(self)
         view.setCamera(camera_controller.mCameraList[len(camera_controller.mCameraList) - 1])
         self.addSubview(view)
         print('打开第%d个相机'%cam_id)
コード例 #26
0
 def getAvailableCameraNames(self):
     myDebug(self.__class__.__name__, get_current_function_name())
     names = []
     types = []
     for i in self.mCameraAvailable:
         try:
             names.append(i.description())
             types.append(XCameraType.X_USB_CAM)
         except:
             names.append(i.GetFriendlyName())
             types.append(XCameraType.X_MindVision)
     return names, types
コード例 #27
0
    def __init__(self, *args):
        myDebug(self.__class__.__name__, get_current_function_name())
        super(ViewController, self).__init__(*args)
        self.mMainWin = MainWindow()
        self.mMainFrame = QFrame(self.mMainWin)
        self.mCurrentWin = None
        self.mMainLayout = QGridLayout(self.mMainFrame)
        self.mFrameList = []

        self.mTestCamera = CameraInterface()
        self.mTestMovieShow = None
        self.windowLoad()
コード例 #28
0
 def __init__(self, *args):
     myDebug(self.__class__.__name__, get_current_function_name())
     super(ImageProcViewBase, self).__init__(*args)
     self.mActiveBorderStyle = 'border:1px solid rgba(200, 50, 50, 255);'
     self.mUnactiveBorderStyle = 'border:1px solid rgba(200, 200, 200, 150);'
     self.deactive()
     self.mImageSaveDir = "./general_image_save"
     self.mImageHandle = ImageHandle()
     self.mImageHandle.setImageSaveDir(self.mImageSaveDir)
     self.controller = MainController.getController()
     self.controller.addImageHandle(self.mImageHandle)
     self.mLayout.addWidget(self.mImageHandle.image_label)
     self.mImageHandle.image_label.show()
コード例 #29
0
 def setCamera(self, camera):
     myDebug(self.__class__.__name__, get_current_function_name())
     self.mOptionList = []
     camera_name = "unknown"
     if camera.mCameraName:
         camera_name = camera.mCameraName
     self.mCameraNameLabel.setText(camera_name)
     self.mCamera = camera
     self.mLayout.addWidget(self.mCameraNameLabel)
     self.mLayout.addWidget(camera.mViewCamera)
     self.mLayout.addWidget(self.foot_label)
     self.insertOptionList(camera_name, self.defaultFunc)
     self.insertOptionList('This is Camera View', self.defaultFunc)
コード例 #30
0
 def __init__(self, *arg):
     myDebug(self.__class__.__name__, get_current_function_name())
     super(ViewFrameBase, self).__init__(*arg)
     self.mActiveBorderStyle = 'border:2px solid rgba(200, 50, 50, 255);'
     self.mUnactiveBorderStyle = 'border:2px solid rgba(200, 200, 200, 150);'
     self.deactive()
     self.isFocused = False
     self.mOptionList = []
     self.mOptionFuncList = []
     self.isViewMaximized = False
     self.mLayout = QGridLayout(self)
     self.mLayout.setContentsMargins(0, 0, 0, 0)
     self.setLayout(self.mLayout)