mirror of
https://github.com/OSURoboticsClub/Rover_2017_2018.git
synced 2025-12-31 03:24:18 +00:00
Mining system completegit add .!
This commit is contained in:
@@ -9,10 +9,20 @@ import spnav
|
||||
|
||||
import rospy
|
||||
|
||||
from rover_control.msg import MiningControlMessage
|
||||
|
||||
#####################################
|
||||
# Global Variables
|
||||
#####################################
|
||||
THREAD_HERTZ = 15
|
||||
THREAD_HERTZ = 100
|
||||
|
||||
MINING_CONTROL_TOPIC = "/rover_control/mining/control"
|
||||
|
||||
Y_ANGULAR_DEADBAND = 0.05
|
||||
Z_LINEAR_DEADBAND = 0.15
|
||||
|
||||
MINING_LIFT_SCALAR = 5
|
||||
MINING_TILT_SCALAR = 5
|
||||
|
||||
|
||||
#####################################
|
||||
@@ -21,7 +31,7 @@ THREAD_HERTZ = 15
|
||||
class SpaceNavControlSender(QtCore.QThread):
|
||||
spacenav_state_update__signal = QtCore.pyqtSignal(object)
|
||||
|
||||
GUI_MODE = 0
|
||||
MINING_MODE = 0
|
||||
ARM_MODE = 1
|
||||
|
||||
def __init__(self, shared_objects):
|
||||
@@ -95,7 +105,10 @@ class SpaceNavControlSender(QtCore.QThread):
|
||||
5: "f_pressed"
|
||||
}
|
||||
|
||||
self.current_control_mode = self.GUI_MODE
|
||||
# ##### Mining Control #####
|
||||
self.mining_control_publisher = rospy.Publisher(MINING_CONTROL_TOPIC, MiningControlMessage, queue_size=1)
|
||||
|
||||
self.current_control_mode = self.MINING_MODE
|
||||
|
||||
def run(self):
|
||||
spnav.spnav_open()
|
||||
@@ -110,7 +123,7 @@ class SpaceNavControlSender(QtCore.QThread):
|
||||
|
||||
time_diff = time() - start_time
|
||||
|
||||
self.msleep(max(int((self.wait_time - time_diff) * 1000), 0))
|
||||
# self.msleep(max(int((self.wait_time - time_diff) * 1000), 0))
|
||||
|
||||
def process_spnav_events(self):
|
||||
event = spnav.spnav_poll_event()
|
||||
@@ -132,16 +145,33 @@ class SpaceNavControlSender(QtCore.QThread):
|
||||
|
||||
def check_control_mode_change(self):
|
||||
if self.spnav_states["1_pressed"]:
|
||||
self.current_control_mode = self.GUI_MODE
|
||||
self.current_control_mode = self.MINING_MODE
|
||||
elif self.spnav_states["2_pressed"]:
|
||||
self.current_control_mode = self.ARM_MODE
|
||||
|
||||
def broadcast_control_state(self):
|
||||
if self.current_control_mode == self.GUI_MODE:
|
||||
self.spacenav_state_update__signal.emit(self.spnav_states)
|
||||
if self.current_control_mode == self.MINING_MODE:
|
||||
self.send_mining_commands()
|
||||
# self.spacenav_state_update__signal.emit(self.spnav_states)
|
||||
elif self.current_control_mode == self.ARM_MODE:
|
||||
pass
|
||||
|
||||
def send_mining_commands(self):
|
||||
linear_z = self.spnav_states["linear_z"]
|
||||
angular_y = self.spnav_states["angular_y"]
|
||||
|
||||
message = MiningControlMessage()
|
||||
|
||||
message.lift_set_absolute = 1024
|
||||
message.tilt_set_absolute = 1024
|
||||
|
||||
message.lift_set_relative = linear_z * MINING_LIFT_SCALAR if abs(linear_z) > Z_LINEAR_DEADBAND else 0
|
||||
message.tilt_set_relative = angular_y * MINING_TILT_SCALAR if abs(angular_y) > Y_ANGULAR_DEADBAND else 0
|
||||
message.cal_factor = -1
|
||||
|
||||
self.mining_control_publisher.publish(message)
|
||||
# print self.spnav_states["linear_z"], self.spnav_states["angular_y"]
|
||||
|
||||
def connect_signals_and_slots(self):
|
||||
pass
|
||||
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
# coding=utf-8
|
||||
#####################################
|
||||
# Imports
|
||||
#####################################
|
||||
# Python native imports
|
||||
from PyQt5 import QtCore, QtWidgets
|
||||
import logging
|
||||
import rospy
|
||||
|
||||
from rover_control.msg import MiningStatusMessage, MiningControlMessage
|
||||
|
||||
#####################################
|
||||
# Global Variables
|
||||
#####################################
|
||||
MINING_STATUS_TOPIC = "/rover_control/mining/status"
|
||||
MINING_CONTROL_TOPIC = "/rover_control/mining/control"
|
||||
|
||||
TRAVEL_POSITION_LIFT = 110
|
||||
TRAVEL_POSITION_TILT = 1023
|
||||
|
||||
MEASURE_POSITION_LIFT = 350
|
||||
MEASURE_POSITION_TILT = 1023
|
||||
|
||||
SCOOP_POSITION_LIFT = 228
|
||||
SCOOP_POSITION_TILT = 215
|
||||
|
||||
|
||||
#####################################
|
||||
# UbiquitiRadioSettings Class Definition
|
||||
#####################################
|
||||
class Mining(QtCore.QObject):
|
||||
|
||||
lift_position_update_ready__signal = QtCore.pyqtSignal(int)
|
||||
tilt_position_update_ready__signal = QtCore.pyqtSignal(int)
|
||||
|
||||
def __init__(self, shared_objects):
|
||||
super(Mining, self).__init__()
|
||||
|
||||
# ########## Reference to class init variables ##########
|
||||
self.shared_objects = shared_objects
|
||||
self.left_screen = self.shared_objects["screens"]["left_screen"]
|
||||
|
||||
self.mining_qlcdnumber = self.left_screen.mining_qlcdnumber # type:QtWidgets.QLCDNumber
|
||||
self.mining_tare_button = self.left_screen.mining_tare_button # type:QtWidgets.QPushButton
|
||||
self.mining_measure_button = self.left_screen.mining_measure_button # type:QtWidgets.QPushButton
|
||||
self.mining_cal_factor_spinbox = self.left_screen.mining_cal_factor_spinbox # type:QtWidgets.QSpinBox
|
||||
self.mining_set_cal_factor_button = self.left_screen.mining_set_cal_factor_button # type:QtWidgets.QPushButton
|
||||
self.lift_position_progress_bar = self.left_screen.lift_position_progress_bar # type:QtWidgets.QProgressBar
|
||||
self.tilt_position_progress_bar = self.left_screen.tilt_position_progress_bar # type:QtWidgets.QProgressBar
|
||||
|
||||
self.mining_measure_move_button = self.left_screen.mining_measure_move_button # type:QtWidgets.QPushButton
|
||||
self.mining_transport_move_button = self.left_screen.mining_transport_move_button # type:QtWidgets.QPushButton
|
||||
self.mining_scoop_move_button = self.left_screen.mining_scoop_move_button # type:QtWidgets.QPushButton
|
||||
|
||||
# ########## Get the settings instance ##########
|
||||
self.settings = QtCore.QSettings()
|
||||
|
||||
# ########## Get the Pick And Plate instance of the logger ##########
|
||||
self.logger = logging.getLogger("groundstation")
|
||||
|
||||
# ########## Thread Flags ##########
|
||||
self.run_thread_flag = True
|
||||
|
||||
# ########## Class Variables ##########
|
||||
self.mining_status_subscriber = rospy.Subscriber(MINING_STATUS_TOPIC, MiningStatusMessage,
|
||||
self.mining_status_message_received__callback)
|
||||
|
||||
self.mining_control_publisher = rospy.Publisher(MINING_CONTROL_TOPIC, MiningControlMessage, queue_size=1)
|
||||
|
||||
self.connect_signals_and_slots()
|
||||
|
||||
def connect_signals_and_slots(self):
|
||||
self.mining_set_cal_factor_button.clicked.connect(self.on_mining_set_cal_factor_clicked__slot)
|
||||
self.mining_tare_button.clicked.connect(self.on_mining_tare_clicked__slot)
|
||||
self.mining_measure_button.clicked.connect(self.on_mining_measure_clicked__slot)
|
||||
|
||||
self.mining_measure_move_button.clicked.connect(self.on_mining_move_measure_clicked__slot)
|
||||
self.mining_transport_move_button.clicked.connect(self.on_mining_move_transport_clicked__slot)
|
||||
self.mining_scoop_move_button.clicked.connect(self.on_mining_move_scoop_clicked__slot)
|
||||
|
||||
self.tilt_position_update_ready__signal.connect(self.tilt_position_progress_bar.setValue)
|
||||
self.lift_position_update_ready__signal.connect(self.lift_position_progress_bar.setValue)
|
||||
|
||||
def on_mining_set_cal_factor_clicked__slot(self):
|
||||
message = MiningControlMessage()
|
||||
|
||||
message.tilt_set_absolute = 1024
|
||||
message.lift_set_absolute = 1024
|
||||
message.cal_factor = self.mining_cal_factor_spinbox.value()
|
||||
|
||||
self.mining_control_publisher.publish(message)
|
||||
|
||||
def on_mining_tare_clicked__slot(self):
|
||||
message = MiningControlMessage()
|
||||
message.tilt_set_absolute = 1024
|
||||
message.lift_set_absolute = 1024
|
||||
message.cal_factor = -1
|
||||
message.tare = 1
|
||||
|
||||
self.mining_control_publisher.publish(message)
|
||||
|
||||
def on_mining_measure_clicked__slot(self):
|
||||
message = MiningControlMessage()
|
||||
message.tilt_set_absolute = 1024
|
||||
message.lift_set_absolute = 1024
|
||||
message.cal_factor = -1
|
||||
message.measure = True
|
||||
|
||||
self.mining_control_publisher.publish(message)
|
||||
|
||||
def on_mining_move_transport_clicked__slot(self):
|
||||
message = MiningControlMessage()
|
||||
message.tilt_set_absolute = TRAVEL_POSITION_TILT
|
||||
message.lift_set_absolute = TRAVEL_POSITION_LIFT
|
||||
message.cal_factor = -1
|
||||
|
||||
self.mining_control_publisher.publish(message)
|
||||
|
||||
def on_mining_move_measure_clicked__slot(self):
|
||||
message = MiningControlMessage()
|
||||
message.tilt_set_absolute = MEASURE_POSITION_TILT
|
||||
message.lift_set_absolute = MEASURE_POSITION_LIFT
|
||||
message.cal_factor = -1
|
||||
|
||||
self.mining_control_publisher.publish(message)
|
||||
|
||||
def on_mining_move_scoop_clicked__slot(self):
|
||||
message = MiningControlMessage()
|
||||
message.tilt_set_absolute = SCOOP_POSITION_TILT
|
||||
message.lift_set_absolute = SCOOP_POSITION_LIFT
|
||||
message.cal_factor = -1
|
||||
|
||||
self.mining_control_publisher.publish(message)
|
||||
|
||||
def mining_status_message_received__callback(self, status):
|
||||
status = status # type:MiningStatusMessage
|
||||
self.tilt_position_update_ready__signal.emit(status.tilt_position)
|
||||
self.lift_position_update_ready__signal.emit(status.lift_position)
|
||||
self.mining_qlcdnumber.display(status.measured_weight)
|
||||
@@ -1392,6 +1392,334 @@ N/A</string>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
<string>Mining</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_8">
|
||||
<item row="5" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_12">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_15">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Lift Position</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QProgressBar" name="lift_position_progress_bar">
|
||||
<property name="maximum">
|
||||
<number>1023</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>512</number>
|
||||
</property>
|
||||
<property name="format">
|
||||
<string>%v</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_11">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_14">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Tilt Position</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QProgressBar" name="tilt_position_progress_bar">
|
||||
<property name="maximum">
|
||||
<number>1023</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>512</number>
|
||||
</property>
|
||||
<property name="format">
|
||||
<string>%v</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Scoop Measurement</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mining_tare_button">
|
||||
<property name="text">
|
||||
<string>Tare</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mining_measure_button">
|
||||
<property name="text">
|
||||
<string>Measure</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_10">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="mining_cal_factor_spinbox">
|
||||
<property name="maximum">
|
||||
<number>65535</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>114</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mining_set_cal_factor_button">
|
||||
<property name="text">
|
||||
<string>Set Cal Factor</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_10">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_12">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLCDNumber" name="mining_qlcdnumber">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>150</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>150</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>9</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="value" stdset="0">
|
||||
<double>0.000000000000000</double>
|
||||
</property>
|
||||
<property name="intValue" stdset="0">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>19</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>g</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_11">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="Line" name="line_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_13">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_13">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mining_transport_move_button">
|
||||
<property name="text">
|
||||
<string>Transport</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mining_measure_move_button">
|
||||
<property name="text">
|
||||
<string>Measure</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mining_scoop_move_button">
|
||||
<property name="text">
|
||||
<string>Scoop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_14">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>SSH Console</string>
|
||||
|
||||
@@ -23,6 +23,7 @@ import Framework.StatusSystems.StatusCore as StatusCore
|
||||
import Framework.StatusSystems.UbiquitiStatusCore as UbiquitiStatusCore
|
||||
import Framework.SettingsSystems.UbiquitiRadioSettings as UbiquitiRadioSettings
|
||||
import Framework.InputSystems.SpaceNavControlSender as SpaceNavControlSender
|
||||
import Framework.MiscSystems.MiningCore as MiningCore
|
||||
|
||||
#####################################
|
||||
# Global Variables
|
||||
@@ -101,6 +102,7 @@ class GroundStation(QtCore.QObject):
|
||||
rospy.init_node("ground_station")
|
||||
|
||||
# ##### Instantiate Regular Classes ######
|
||||
self.__add_non_thread("Mining System", MiningCore.Mining(self.shared_objects))
|
||||
|
||||
# ##### Instantiate Threaded Classes ######
|
||||
self.__add_thread("Video Coordinator", RoverVideoCoordinator.RoverVideoCoordinator(self.shared_objects))
|
||||
@@ -132,6 +134,9 @@ class GroundStation(QtCore.QObject):
|
||||
instance.setup_signals(self.start_threads_signal, self.connect_signals_and_slots_signal,
|
||||
self.kill_threads_signal)
|
||||
|
||||
def __add_non_thread(self, name, instance):
|
||||
self.shared_objects["regular_classes"][name] = instance
|
||||
|
||||
def __connect_signals_to_slots(self):
|
||||
self.shared_objects["screens"]["left_screen"].exit_requested_signal.connect(self.on_exit_requested__slot)
|
||||
self.shared_objects["screens"]["right_screen"].exit_requested_signal.connect(self.on_exit_requested__slot)
|
||||
|
||||
Reference in New Issue
Block a user