Added 2017-2018 mars rover repository.

This commit is contained in:
2018-08-22 14:54:52 -07:00
parent a56690ca18
commit 7fd2641766
750 changed files with 2019222 additions and 0 deletions

View File

@@ -0,0 +1,173 @@
"""
This file contains the live logs page sub-class
"""
#####################################
# Imports
#####################################
# Python native imports
from PyQt5 import QtCore, QtWidgets, QtGui
import logging
from inputs import devices, GamePad
import sys
import time
import rospy
from rover_drive.msg import RoverMotorDrive
#####################################
# Global Variables
#####################################
GAME_CONTROLLER_NAME = "Logitech Logitech Extreme 3D Pro"
#####################################
# Controller Class Definition
#####################################
class LogitechJoystick(QtCore.QThread):
def __init__(self):
super(LogitechJoystick, self).__init__()
# ########## Thread Flags ##########
self.run_thread_flag = True
self.setup_controller_flag = True
self.data_acquisition_and_broadcast_flag = True
self.controller_aquired = False
# ########## Class Variables ##########
self.gamepad = None # type: GamePad
self.controller_states = {
"left_stick_x_axis": 0,
"left_stick_y_axis": 0,
"left_stick_center_pressed": 0,
"right_stick_x_axis": 0,
"right_stick_y_axis": 0,
"right_stick_center_pressed": 0,
"left_trigger_z_axis": 0,
"left_bumper_pressed": 0,
"right_trigger_z_axis": 0,
"right_bumper_pressed": 0,
"dpad_x": 0,
"dpad_y": 0,
"select_pressed": 0,
"start_pressed": 0,
"home_pressed": 0,
"a_pressed": 0,
"b_pressed": 0,
"x_pressed": 0,
"y_pressed": 0
}
self.raw_mapping_to_class_mapping = {
"ABS_X": "left_stick_x_axis",
"ABS_Y": "left_stick_y_axis",
"BTN_THUMBL": "left_stick_center_pressed",
"ABS_RX": "right_stick_x_axis",
"ABS_RY": "right_stick_y_axis",
"BTN_THUMBR": "right_stick_center_pressed",
"ABS_Z": "left_trigger_z_axis",
"BTN_TL": "left_bumper_pressed",
"ABS_RZ": "right_trigger_z_axis",
"BTN_TR": "right_bumper_pressed",
"ABS_HAT0X": "dpad_x",
"ABS_HAT0Y": "dpad_y",
"BTN_SELECT": "select_pressed",
"BTN_START": "start_pressed",
"BTN_MODE": "home_pressed",
"BTN_SOUTH": "a_pressed",
"BTN_EAST": "b_pressed",
"BTN_NORTH": "x_pressed",
"BTN_WEST": "y_pressed"
}
self.ready = False
self.start()
def run(self):
while self.run_thread_flag:
if self.setup_controller_flag:
self.controller_aquired = self.__setup_controller()
self.setup_controller_flag = False
if self.data_acquisition_and_broadcast_flag:
self.__get_controller_data()
def __setup_controller(self):
for device in devices.gamepads:
if device.name == GAME_CONTROLLER_NAME:
self.gamepad = device
return True
return False
def __get_controller_data(self):
if (self.controller_aquired):
events = self.gamepad.read()
for event in events:
if event.code in self.raw_mapping_to_class_mapping:
self.controller_states[self.raw_mapping_to_class_mapping[event.code]] = event.state
self.ready = True
# print "Logitech: %s" % self.controller_states
#####################################
# Controller Class Definition
#####################################
class Publisher(QtCore.QThread):
def __init__(self):
super(Publisher, self).__init__()
self.joystick = LogitechJoystick()
while not self.joystick.ready:
self.msleep(100)
# ########## Thread Flags ##########
self.run_thread_flag = True
rospy.init_node("drive_tester")
self.pub = rospy.Publisher("/drive/motoroneandtwo", RoverMotorDrive, queue_size=1)
self.last_time = time.time()
self.drive = RoverMotorDrive()
self.start()
def run(self):
while self.run_thread_flag:
self.__update_and_publish()
self.msleep(50)
def __update_and_publish(self):
axis = self.joystick.controller_states["left_stick_y_axis"]
self.drive.first_motor_direction = 1 if axis <= 512 else 0
self.drive.first_motor_speed = min(abs(self.joystick.controller_states["left_stick_y_axis"] - 512) * 128, 65535)
self.pub.publish(self.drive)
if __name__ == '__main__':
qapp = QtCore.QCoreApplication(sys.argv)
joystick = Publisher()
qapp.exec_()

View File

@@ -0,0 +1,129 @@
#!/usr/bin/env python
#####################################
# Imports
#####################################
# Python native imports
from time import time, sleep
import serial.rs485
import minimalmodbus
# from std_msgs.msg import UInt8, UInt16
# Custom Imports
# from rover_control.msg import TowerPanTiltControlMessage
#####################################
# Global Variables
#####################################
NODE_NAME = "chassis_pan_tilt_control"
DEFAULT_PORT = "/dev/rover/ttyEffectors"
DEFAULT_BAUD = 115200
DEFAULT_INVERT = False
DEFAULT_PAN_TILT_CONTROL_TOPIC = "chassis/pan_tilt/control"
PAN_TILT_NODE_ID = 1
COMMUNICATIONS_TIMEOUT = 0.15
# Seconds
RX_DELAY = 0.01
TX_DELAY = 0.01
DEFAULT_HERTZ = 20
MINING_MODBUS_REGISTERS = {
"LIFT_SET": 0,
"TILT_SET": 1,
"TARE": 2,
"CAL_FACTOR": 3,
"LIFT_POSITION": 4,
"TILT_POSITION": 5,
"MEASURED_WEIGHT": 6
}
POSITIONAL_THRESHOLD = 20
NODE_LAST_SEEN_TIMEOUT = 2 # seconds
#####################################
# DriveControl Class Definition
#####################################
class MiningControl(object):
def __init__(self):
self.port = DEFAULT_PORT
self.baud = 115200
self.mining_node = None
self.tower_node = None
self.connect_to_pan_tilt_and_tower()
self.pan_tilt_control_message = None
self.new_pan_tilt_control_message = False
self.modbus_nodes_seen_time = time()
self.mining_registers = [
0,
0,
0,
0,
0,
0,
0
]
self.run()
def __setup_minimalmodbus_for_485(self):
self.mining_node.serial = serial.rs485.RS485(self.port, baudrate=self.baud, timeout=COMMUNICATIONS_TIMEOUT)
self.mining_node.serial.rs485_mode = serial.rs485.RS485Settings(rts_level_for_rx=1, rts_level_for_tx=0,
delay_before_rx=RX_DELAY,
delay_before_tx=TX_DELAY)
def run(self):
self.initialize_mining_system()
while True:
try:
print self.mining_node.read_registers(0, 7)
self.mining_registers[MINING_MODBUS_REGISTERS["TILT_SET"]] = int(input("Enter new tilt value:"))
self.mining_node.write_registers(0, self.mining_registers)
except Exception, e:
print e
def connect_to_pan_tilt_and_tower(self):
self.mining_node = minimalmodbus.Instrument(self.port, int(2))
self.__setup_minimalmodbus_for_485()
def initialize_mining_system(self):
self.mining_registers[MINING_MODBUS_REGISTERS["LIFT_SET"]] = 1023
self.mining_registers[MINING_MODBUS_REGISTERS["TILT_SET"]] = 350
self.mining_registers[MINING_MODBUS_REGISTERS["CAL_FACTOR"]] = 114
while abs(self.mining_registers[MINING_MODBUS_REGISTERS["LIFT_POSITION"]] - self.mining_registers[MINING_MODBUS_REGISTERS["LIFT_SET"]]) > POSITIONAL_THRESHOLD or \
abs(self.mining_registers[MINING_MODBUS_REGISTERS["TILT_POSITION"]] - self.mining_registers[MINING_MODBUS_REGISTERS["TILT_SET"]]) > POSITIONAL_THRESHOLD:
try:
self.mining_node.write_registers(0, self.mining_registers)
self.mining_registers = self.mining_node.read_registers(0, 7)
except Exception, e:
print "Had trouble communicating:", e
try:
self.mining_registers[MINING_MODBUS_REGISTERS["TARE"]] = 1
self.mining_node.write_registers(0, self.mining_registers)
self.mining_registers[MINING_MODBUS_REGISTERS["TARE"]] = 0
except:
print "Had trouble communicating: no tare: ", e
if __name__ == "__main__":
MiningControl()

View File

@@ -0,0 +1,66 @@
<launch>
<!-- https://github.com/vikiboy/AGV_Localization/blob/master/robot_localization/launch/ekf.launch -->
<!-- https://answers.ros.org/question/241222/fusing-imu-gps-with-robot_location-package/ -->
<node name="rosbag" pkg="rosbag" type="play" args="-l /home/nvidia/gps_imu_data_2018-02-01-05-31-34.bag">
<remap from="/imu_data" to="/imu/data" />
</node>
<node name="navsat" pkg="nmea_navsat_driver" type="nmea_topic_driver" output="screen">
<remap from="/fix" to="/gps/fix"/>
</node>
<node pkg="tf" type="static_transform_publisher" name="imu_tf" args="0 0 0 0 0 0 1 base_link imu 20"/>
<node pkg="tf" type="static_transform_publisher" name="gps_tf" args="0 0 0 0 0 0 1 base_link gps 20"/>
<node pkg="robot_localization" type="ekf_localization_node" name="ekf_localization" clear_params="true">
<param name="output_frame" value="odom"/>
<param name="frequency" value="20"/>
<param name="odom_used" value="true"/>
<param name="imu_used" value="true"/>
<param name="vo_used" value="false"/>
<param name="sensor_timeout" value="0.1"/>
<param name="two_d_mode" value="false"/>
<param name="map_frame" value="map"/>
<param name="odom_frame" value="odom"/>
<param name="base_link_frame" value="base_link"/>
<param name="world_frame" value="odom"/>
<param name="odom0" value="/odometry/gps"/>
<param name="imu0" value="/imu/data"/>
<rosparam param="odom0_config">[true, true, true,
false, false, false,
false , false, false,
false, false, false,
false, false, false]</rosparam>
<rosparam param="imu0_config">[false, false, false,
true , true , true,
false, false, false,
true , true , true ,
true , true , true ]</rosparam>
<param name="odom0_differential" value="false"/>
<param name="imu0_differential" value="false"/>
<param name="imu0_remove_gravitational_acceleration" value="true"/>
<param name="odom0_relative" value="false"/>
<param name="imu0_relative" value="false"/>
<param name="print_diagnostics" value="true"/>
<!-- ======== ADVANCED PARAMETERS ======== -->
<param name="odom0_queue_size" value="2"/>
<param name="imu0_queue_size" value="10"/>
</node>
<node name="navsat_transform" pkg="robot_localization" type="navsat_transform_node" output="screen">
<param name="broadcast_utm_transform" value="true"/>
</node>
</launch>

View File

@@ -0,0 +1,147 @@
Panels:
- Class: rviz/Displays
Help Height: 78
Name: Displays
Property Tree Widget:
Expanded:
- /Global Options1
- /Status1
Splitter Ratio: 0.5
Tree Height: 1113
- Class: rviz/Selection
Name: Selection
- Class: rviz/Tool Properties
Expanded:
- /2D Pose Estimate1
- /2D Nav Goal1
- /Publish Point1
Name: Tool Properties
Splitter Ratio: 0.588679016
- Class: rviz/Views
Expanded:
- /Current View1
Name: Views
Splitter Ratio: 0.5
- Class: rviz/Time
Experimental: false
Name: Time
SyncMode: 0
SyncSource: ""
Visualization Manager:
Class: ""
Displays:
- Alpha: 0.5
Cell Size: 1
Class: rviz/Grid
Color: 160; 160; 164
Enabled: true
Line Style:
Line Width: 0.0299999993
Value: Lines
Name: Grid
Normal Cell Count: 0
Offset:
X: 0
Y: 0
Z: 0
Plane: XY
Plane Cell Count: 10
Reference Frame: <Fixed Frame>
Value: true
- Angle Tolerance: 0.100000001
Class: rviz/Odometry
Covariance:
Orientation:
Alpha: 0.5
Color: 255; 255; 127
Color Style: Unique
Frame: Local
Offset: 1
Scale: 1
Value: true
Position:
Alpha: 0.300000012
Color: 204; 51; 204
Scale: 1
Value: true
Value: true
Enabled: true
Keep: 100
Name: Odometry
Position Tolerance: 0.100000001
Shape:
Alpha: 1
Axes Length: 1
Axes Radius: 0.100000001
Color: 255; 25; 0
Head Length: 0.300000012
Head Radius: 0.100000001
Shaft Length: 1
Shaft Radius: 0.0500000007
Value: Arrow
Topic: /odometry/filtered
Unreliable: false
Value: true
Enabled: true
Global Options:
Background Color: 48; 48; 48
Default Light: true
Fixed Frame: odom
Frame Rate: 30
Name: root
Tools:
- Class: rviz/Interact
Hide Inactive Objects: true
- Class: rviz/MoveCamera
- Class: rviz/Select
- Class: rviz/FocusCamera
- Class: rviz/Measure
- Class: rviz/SetInitialPose
Topic: /initialpose
- Class: rviz/SetGoal
Topic: /move_base_simple/goal
- Class: rviz/PublishPoint
Single click: true
Topic: /clicked_point
Value: true
Views:
Current:
Class: rviz/Orbit
Distance: 14.6344223
Enable Stereo Rendering:
Stereo Eye Separation: 0.0599999987
Stereo Focal Distance: 1
Swap Stereo Eyes: false
Value: false
Focal Point:
X: 1.49345744
Y: -0.492769718
Z: -0.707593679
Focal Shape Fixed Size: true
Focal Shape Size: 0.0500000007
Invert Z Axis: false
Name: Current View
Near Clip Distance: 0.00999999978
Pitch: 1.35979652
Target Frame: <Fixed Frame>
Value: Orbit (rviz)
Yaw: 4.07858229
Saved: ~
Window Geometry:
Displays:
collapsed: false
Height: 1401
Hide Left Dock: false
Hide Right Dock: false
QMainWindow State: 000000ff00000000fd000000040000000000000156000004e1fc0200000008fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000005c00fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000003a000004e1000000c600fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c000002610000000100000100000004e1fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073010000003a000004e10000009e00fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000003510000003efc0100000002fb0000000800540069006d00650100000000000003510000024400fffffffb0000000800540069006d00650100000000000004500000000000000000000000ef000004e100000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
Selection:
collapsed: false
Time:
collapsed: false
Tool Properties:
collapsed: false
Views:
collapsed: false
Width: 849
X: 2787
Y: 18

View File

@@ -0,0 +1,30 @@
#!/usr/bin/env python
import rospy
import time
from std_msgs.msg import Float64MultiArray
class RDFProceesor(object):
def __init__(self):
super(RDFProceesor, self).__init__()
self.sub = rospy.Subscriber("/rover_science/rdf/data", Float64MultiArray, self.on_rdf_data_received)
self.new_data = False
self.current_data = None
print self.sub
def run(self):
while True:
if self.new_data:
print self.current_data
self.new_data = False
time.sleep(0.01)
def on_rdf_data_received(self, rdf_data):
print rdf_data
self.current_data = rdf_data
self.new_data = True
if __name__ == '__main__':
processor = RDFProceesor()
processor.run()

View File

@@ -0,0 +1,67 @@
import paramiko
import json
import time
# ath0 21 channels in total; available frequencies :
# Channel 01 : 2.412 GHz
# Channel 31 : 2.414 GHz
# Channel 02 : 2.417 GHz
# Channel 32 : 2.419 GHz
# Channel 03 : 2.422 GHz
# Channel 33 : 2.424 GHz
# Channel 04 : 2.427 GHz
# Channel 34 : 2.429 GHz
# Channel 05 : 2.432 GHz
# Channel 35 : 2.434 GHz
# Channel 06 : 2.437 GHz
# Channel 36 : 2.439 GHz
# Channel 07 : 2.442 GHz
# Channel 37 : 2.444 GHz
# Channel 08 : 2.447 GHz
# Channel 38 : 2.449 GHz
# Channel 09 : 2.452 GHz
# Channel 39 : 2.454 GHz
# Channel 10 : 2.457 GHz
# Channel 40 : 2.459 GHz
# Channel 11 : 2.462 GHz
# Current Frequency:2.417 GHz (Channel 2)
# Sets: iwconfig ath0 channel 01
# Gets: iwlist ath0 channel
# NOTE
# Only the access point has to get changed the station (client) will automatically choose the new freq
channel = 3
get_general_info = "wstalist"
get_wireless_info = "iwlist ath0 channel"
set_wireless_frequency = "iwconfig ath0 channel " + "%02d" % channel # iwconfig ath0 freq 2.456G
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy)
# Before anyone complains, I'm not worried about this password being online.
# We only set one because the web interfaces HAVE to have one
ssh.connect("192.168.1.20", username="ubnt", password="rover4lyfe^", compress=True)
while True:
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(get_general_info)
output_json = json.loads(ssh_stdout.read())[0]
successful_transmit_percent = output_json["ccq"]
quality = output_json["airmax"]["quality"]
capacity = output_json["airmax"]["capacity"]
rx_rate = output_json["rx"]
tx_rate = output_json["tx"]
ground_tx_latency = output_json["tx_latency"]
rover_tx_latency = output_json["remote"]["tx_latency"]
print successful_transmit_percent, " | ", quality, " | ", capacity, " | ", rx_rate, " | ", tx_rate, " | ", ground_tx_latency, " | ", rover_tx_latency
time.sleep(0.25)
# ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(set_wireless_frequency)
# ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(get_wireless_info)
#
# print ssh_stdout.read()

View File

@@ -0,0 +1,28 @@
import socket
import sys
# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = ('task.cstag.ca', 4547)
messages = ["HELP", "LOGIN MTECH GITRDONE", "STATUS", "START", "STOP", "LOGOUT"]
print "Connected.... Enter commands now..."
# for message in messages:
while True:
try:
# Send data
message = raw_input()
# print type(message)
if message not in messages:
print "Invalid command. Please try again."
continue
sent = sock.sendto(message, server_address)
# Receive response
# print 'waiting to receive'
data, server = sock.recvfrom(4096)
print data
except:
pass