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,212 @@
cmake_minimum_required(VERSION 2.8.3)
project(rover_status)
## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()
################################################
## Declare ROS messages, services and actions ##
################################################
## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
## * add a build_depend tag for "message_generation"
## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
## but can be declared for certainty nonetheless:
## * add a run_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
## * add "message_generation" and every package in MSG_DEP_SET to
## find_package(catkin REQUIRED COMPONENTS ...)
## * add "message_runtime" and every package in MSG_DEP_SET to
## catkin_package(CATKIN_DEPENDS ...)
## * uncomment the add_*_files sections below as needed
## and list every .msg/.srv/.action file to be processed
## * uncomment the generate_messages entry below
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
## Generate messages in the 'msg' folder
# add_message_files(
# FILES
# Message1.msg
# Message2.msg
# )
add_message_files(
FILES
BatteryStatusMessage.msg
RoverSysStatus.msg
WheelStatuses.msg
FrSkyStatus.msg
JetsonInfo.msg
CameraStatuses.msg
GPSInfo.msg
MiscStatuses.msg
)
## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
# Service2.srv
# )
## Generate actions in the 'action' folder
# add_action_files(
# FILES
# Action1.action
# Action2.action
# )
## Generate added messages and services with any dependencies listed here
generate_messages(
DEPENDENCIES
std_msgs
)
################################################
## Declare ROS dynamic reconfigure parameters ##
################################################
## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
## * add a build_depend and a run_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
## * add "dynamic_reconfigure" to
## find_package(catkin REQUIRED COMPONENTS ...)
## * uncomment the "generate_dynamic_reconfigure_options" section below
## and list every .cfg file to be processed
## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
# cfg/DynReconf1.cfg
# cfg/DynReconf2.cfg
# )
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES system_statuses
# CATKIN_DEPENDS roscpp rospy std_msgs
# DEPENDS system_lib
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
${catkin_INCLUDE_DIRS}
)
## Declare a C++ library
# add_library(${PROJECT_NAME}
# src/${PROJECT_NAME}/system_statuses.cpp
# )
## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/system_statuses_node.cpp)
## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")
## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Specify libraries to link a library or executable target against
# target_link_libraries(${PROJECT_NAME}_node
# ${catkin_LIBRARIES}
# )
#############
## Install ##
#############
# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# install(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark executables and/or libraries for installation
# install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_node
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# FILES_MATCHING PATTERN "*.h"
# PATTERN ".svn" EXCLUDE
# )
## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
# # myfile1
# # myfile2
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )
#############
## Testing ##
#############
## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_system_statuses.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()
## Add folders to be run by python nosetests
# catkin_add_nosetests(test)

View File

@@ -0,0 +1,4 @@
bool camera_zed
bool camera_undercarriage
bool camera_chassis
bool camera_main_navigation

View File

@@ -0,0 +1 @@
bool FrSky_controller_connection_status

View File

@@ -0,0 +1,6 @@
bool gps_connected
bool gps_fix
int8 num_satellites
float32 horizontal_dilution
float32 kmph
float32 gps_heading

View File

@@ -0,0 +1,5 @@
float64 jetson_CPU
float64 jetson_RAM
float64 jetson_EMMC
float64 jetson_NVME_SSD
float64 jetson_GPU_temp

View File

@@ -0,0 +1,5 @@
bool arm_connection_status
bool arm_end_effector_connection_statuses
bool sample_containment_connection_status
bool tower_connection_status
bool chassis_pan_tilt_connection_status

View File

@@ -0,0 +1,20 @@
int8 UTC_GPS_time
bool bogie_connection_1
bool bogie_connection_2
bool bogie_connection_3
bool arm_connection_status
bool arm_end_effector_connection_statuses
bool camera_zed
bool camera_undercarriage
bool camera_chassis
bool camera_main_navigation
bool sample_containment_connection_status
bool tower_connection_status
bool chassis_pan_tilt_connection_status
int8 GPS_connection_status
float64 jetson_CPU
float64 jetson_RAM
float64 jetson_EMMC
float64 jetson_NVME_SSD
float64 jetson_GPU_temp
bool FrSky_controller_connection_status

View File

@@ -0,0 +1,6 @@
bool front_left
bool middle_left
bool rear_left
bool front_right
bool middle_right
bool rear_right

View File

@@ -0,0 +1,68 @@
<?xml version="1.0"?>
<package format="2">
<name>rover_status</name>
<version>0.0.0</version>
<description>The rover_status package</description>
<!-- One maintainer tag required, multiple allowed, one person per tag -->
<!-- Example: -->
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
<maintainer email="matcurtay@matcurtay.net">matcurtay</maintainer>
<!-- One license tag required, multiple allowed, one license per tag -->
<!-- Commonly used license strings: -->
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
<license>BSD</license>
<!-- Url tags are optional, but multiple are allowed, one per tag -->
<!-- Optional attribute type can be: website, bugtracker, or repository -->
<!-- Example: -->
<!-- <url type="website">http://wiki.ros.org/rover_status</url> -->
<!-- Author tags are optional, multiple are allowed, one per tag -->
<!-- Authors do not have to be maintainers, but could be -->
<!-- Example: -->
<!-- <author email="jane.doe@example.com">Jane Doe</author> -->
<!-- The *depend tags are used to specify dependencies -->
<!-- Dependencies can be catkin packages or system dependencies -->
<!-- Examples: -->
<!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
<!-- <depend>roscpp</depend> -->
<!-- Note that this is equivalent to the following: -->
<!-- <build_depend>roscpp</build_depend> -->
<!-- <exec_depend>roscpp</exec_depend> -->
<!-- Use build_depend for packages you need at compile time: -->
<build_depend>message_generation</build_depend>
<!-- Use build_export_depend for packages you need in order to build against this package: -->
<!-- <build_export_depend>message_generation</build_export_depend> -->
<!-- Use buildtool_depend for build tool packages: -->
<!-- <buildtool_depend>catkin</buildtool_depend> -->
<!-- Use exec_depend for packages you need at runtime: -->
<exec_depend>message_runtime</exec_depend>
<!-- Use test_depend for packages you need only for testing: -->
<!-- <test_depend>gtest</test_depend> -->
<!-- Use doc_depend for packages you need only for building documentation: -->
<!-- <doc_depend>doxygen</doc_depend> -->
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>rospy</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<!-- The export tag contains other, unspecified, tags -->
<export>
<!-- Other tools can request additional information be placed here -->
</export>
</package>

View File

@@ -0,0 +1,26 @@
#!/usr/bin/env python
# import rospy
# from system_statuses.msg import Camera2Changer
# def camera_2_changer():
# pub = rospy.Publisher('camera_2_changer_chatter', Camera2Changer, queue_size=10)
# rospy.init_node('camera_2_changer_talker', anonymous=True)
# # r = rospy.sleep(10) # 10hz
# msg = Camera2Changer()
# msg.camera_2_value = 0
# while not rospy.is_shutdown():
# msg.camera_2_value = (msg.camera_2_value + 1) % 2
# rospy.loginfo(msg)
# pub.publish(msg)
# r.sleep()
## rospy.sleep(2.)
#if __name__ == '__main__':
# try:
# camera_2_changer()
# except rospy.ROSInterruptException:
# pass

View File

@@ -0,0 +1,78 @@
#!/usr/bin/env python
import rospy
from rover_status.msg import CameraStatuses, BogieStatuses, FrSkyStatus, GPSInfo, MiscStatuses, JetsonInfo
# THIS IS A SUPER ROUGH EXAMPLE OF HOW TO PULL THE DATA
# You can create your own message formats in the msg folder
# This is a simple example of pulling data from system_statuses_node.py
# and storing them into self values.
# The ground control code sounds like it'll be fairly different in format.
class RoverStatuses:
def __init__(self):
rospy.init_node('RoverStatuses')
# self.pub = rospy.Publisher('rover_statuses_chatter', RoverSysStatus, queue_size=10)
# Subscription examples on pulling data from system_statuses_node.py
rospy.Subscriber('camera_system_status_chatter', CameraStatuses, self.__camera_callback)
rospy.Subscriber('bogie_system_status_chatter', BogieStatuses, self.__bogie_callback)
rospy.Subscriber('FrSky_system_status_chatter', FrSkyStatus, self.__frsky_callback)
rospy.Subscriber('GPS_system_status_chatter', GPSInfo, self.__gps_callback)
rospy.Subscriber('jetson_system_status_chatter', JetsonInfo, self.__jetson_callback)
rospy.Subscriber('misc_system_status_chatter', MiscStatuses, self.__misc_callback)
self.camera_msg = CameraStatuses()
self.bogie_msg = BogieStatuses()
self.FrSky_msg = FrSkyStatus()
self.GPS_msg = GPSInfo()
self.jetson_msg = JetsonInfo()
self.misc_msg = MiscStatuses()
def __camera_callback(self, data):
self.camera_msg.camera_zed = data.camera_zed
self.camera_msg.camera_undercarriage = data.camera_undercarriage
self.camera_msg.camera_chassis = data.camera_chassis
self.camera_msg.camera_main_navigation = data.camera_main_navigation
def __frsky_callback(self, data):
self.FrSky_msg.FrSky_controller_connection_status = data.FrSky_controller_connection_status
def __bogie_callback(self, data):
self.bogie_msg.bogie_connection_1 = data.bogie_connection_1
self.bogie_msg.bogie_connection_2 = data.bogie_connection_2
self.bogie_msg.bogie_connection_3 = data.bogie_connection_3
def __jetson_callback(self, data):
self.jetson_msg.jetson_CPU = data.jetson_CPU
self.jetson_msg.jetson_RAM = data.jetson_RAM
self.jetson_msg.jetson_EMMC = data.jetson_EMMC
self.jetson_msg.jetson_NVME_SSD = data.jetson_NVME_SSD
self.jetson_msg.jetson_GPU_temp = data.jetson_GPU_temp
rospy.loginfo(self.jetson_msg)
def __gps_callback(self, data):
self.GPS_msg.UTC_GPS_time = data.UTC_GPS_time
self.GPS_msg.GPS_connection_status = data.GPS_connection_status
def __misc_callback(self, data):
self.misc_msg.arm_connection_status = data.arm_connection_status
self.misc_msg.arm_end_effector_connection_statuses = data.arm_end_effector_connection_statuses
self.misc_msg.sample_containment_connection_status = data.sample_containment_connection_status
self.misc_msg.tower_connection_status = data.tower_connection_status
self.misc_msg.chassis_pan_tilt_connection_status = data.chassis_pan_tilt_connection_status
def run(self):
rospy.Subscriber('camera_system_status_chatter', CameraStatuses, self.__camera_callback)
rospy.Subscriber('bogie_system_status_chatter', BogieStatuses, self.__bogie_callback)
rospy.Subscriber('FrSky_system_status_chatter', FrSkyStatus, self.__frsky_callback)
rospy.Subscriber('GPS_system_status_chatter', GPSInfo, self.__gps_callback)
rospy.Subscriber('jetson_system_status_chatter', JetsonInfo, self.__jetson_callback)
rospy.Subscriber('misc_system_status_chatter', MiscStatuses, self.__misc_callback)
rospy.spin()
if __name__ == '__main__':
rover_statuses = RoverStatuses()
rover_statuses.run()

View File

@@ -0,0 +1,398 @@
#!/usr/bin/env python
#####################################
# Imports
#####################################
# Python native imports
import rospy
import os.path
import psutil
import pynmea2
import subprocess
from rover_status.msg import BatteryStatusMessage, CameraStatuses, WheelStatuses, FrSkyStatus, GPSInfo, MiscStatuses, JetsonInfo
from rover_control.msg import DriveCommandMessage, DriveStatusMessage, IrisStatusMessage
from std_msgs.msg import Empty
from nmea_msgs.msg import Sentence
from time import time
#####################################
# Global Variables
#####################################
# Publishers
DEFAULT_BATTERY_TOPIC_NAME = "battery_status"
DEFAULT_CAMERA_TOPIC_NAME = "camera_status"
DEFAULT_WHEEL_TOPIC_NAME = "wheel_status"
DEFAULT_FRSKY_TOPIC_NAME = "frsky_status"
DEFAULT_GPS_TOPIC_NAME = "gps_status"
DEFAULT_JETSON_TOPIC_NAME = "jetson_status"
DEFAULT_MISC_TOPIC_NAME = "misc_status"
MAX_JETSON_UPDATE_HERTZ = 0.2
MAX_IRIS_UPDATE_HERTZ = 0.2
# Subscribers
DEFAULT_REQUEST_UPDATE_TOPIC_NAME = "update_requested"
DEFAULT_IRIS_STATUS_TOPIC_NAME = "/rover_control/iris_status"
DEFAULT_BOGIE_LEFT_TOPIC_NAME = '/rover_control/drive_status/left'
DEFAULT_BOGIE_RIGHT_TOPIC_NAME = '/rover_control/drive_status/right'
DEFAULT_BOGIE_REAR_TOPIC_NAME = '/rover_control/drive_status/rear'
DEFAULT_GPS_NMEA_TOPIC_NAME = '/rover_odometry/gps/sentence'
#####################################
# SystemStatuses Class Definition
#####################################
class SystemStatuses:
def __init__(self):
# Camera path locations
self.system_path_locations = [
'/dev/rover/camera_zed',
'/dev/rover/camera_undercarriage',
'/dev/rover/camera_chassis',
'/dev/rover/camera_main_navigation'
]
# filesystem paths for EMMC [0] and NVME_SSD [1]
# -- UPDATE [1] FOR JETSON --
self.file_systems_EMMC_NVMe_SSD = [
'/',
'/dev/shm'
]
rospy.init_node('SystemStatuses')
# Get Topic Names
self.battery_topic_name = rospy.get_param("~pub_battery_status_topic", DEFAULT_BATTERY_TOPIC_NAME)
self.camera_topic_name = rospy.get_param("~pub_camera_status_topic", DEFAULT_CAMERA_TOPIC_NAME)
self.wheel_topic_name = rospy.get_param("~pub_wheel_status_topic", DEFAULT_WHEEL_TOPIC_NAME)
self.frsky_topic_name = rospy.get_param("~pub_frsky_status_topic", DEFAULT_FRSKY_TOPIC_NAME)
self.gps_topic_name = rospy.get_param("~pub_gps_status_topic", DEFAULT_GPS_TOPIC_NAME)
self.jetson_topic_name = rospy.get_param("~pub_jetson_status_topic", DEFAULT_JETSON_TOPIC_NAME)
self.misc_topic_name = rospy.get_param("~pub_misc_status_topic", DEFAULT_MISC_TOPIC_NAME)
# Subscribers
self.request_update_topic_name = rospy.get_param("~sub_request_update_status_topic",
DEFAULT_REQUEST_UPDATE_TOPIC_NAME)
self.iris_status_topic_name = rospy.get_param("~sub_iris_status_topic", DEFAULT_IRIS_STATUS_TOPIC_NAME)
self.bogie_left_topic_name = rospy.get_param("~sub_bogie_left_topic", DEFAULT_BOGIE_LEFT_TOPIC_NAME)
self.bogie_right_topic_name = rospy.get_param("~sub_bogie_right_topic", DEFAULT_BOGIE_RIGHT_TOPIC_NAME)
self.bogie_rear_topic_name = rospy.get_param("~sub_bogie_rear_topic", DEFAULT_BOGIE_REAR_TOPIC_NAME)
self.gps_nmea_topic_name = rospy.get_param("~sub_gps_nmea_topic", DEFAULT_GPS_NMEA_TOPIC_NAME)
# init all publisher functions
self.pub_battery = rospy.Publisher(self.battery_topic_name, BatteryStatusMessage, queue_size=1)
self.pub_camera = rospy.Publisher(self.camera_topic_name, CameraStatuses, queue_size=1)
self.pub_wheel = rospy.Publisher(self.wheel_topic_name, WheelStatuses, queue_size=1)
self.pub_FrSky = rospy.Publisher(self.frsky_topic_name, FrSkyStatus, queue_size=1)
self.pub_GPS = rospy.Publisher(self.gps_topic_name, GPSInfo, queue_size=1)
self.pub_jetson = rospy.Publisher(self.jetson_topic_name, JetsonInfo, queue_size=1)
self.pub_Misc = rospy.Publisher(self.misc_topic_name, MiscStatuses, queue_size=1)
# Subscribers
self.request_update_subscriber = rospy.Subscriber(self.request_update_topic_name, Empty,
self.on_update_requested)
# Manual update variable
self.manual_update_requested = False
# init all message variables
self.battery_message = BatteryStatusMessage()
self.camera_msg = CameraStatuses()
self.wheel_msg = WheelStatuses()
self.FrSky_msg = FrSkyStatus()
self.GPS_msg = GPSInfo()
self.jetson_msg = JetsonInfo()
self.misc_msg = MiscStatuses()
# init all message values
self.__pull_new_message_values()
self.__instantiate_subscribers()
# init all previous values
self.__update_all_previous_values()
self.last_jetson_message_sent = time()
self.last_iris_message_sent = time()
# init all RoverSysMessage values
def __pull_new_message_values(self):
self.__set_arm_connection_status()
self.__set_arm_end_effector_connection_statuses()
self.__set_cameras()
self.__set_sample_containment_connection_status()
self.__set_tower_connection_status()
self.__set_chassis_pan_tilt_connection_status()
self.__set_jetson_usage_information()
self.__set_frsky_controller_connection_status()
# Pulls the UTC GPS Information (WIP v2.0)
def __set_gps_info(self, data):
self.GPS_msg.gps_connected = True
try:
self.Nmea_Message = pynmea2.parse(data.sentence)
except:
return
if self.Nmea_Message.sentence_type == 'GGA':
if int(self.Nmea_Message.gps_qual) != 0:
self.GPS_msg.gps_fix = True
else:
self.GPS_msg.gps_fix = False
self.GPS_msg.num_satellites = int(self.Nmea_Message.num_sats)
self.GPS_msg.horizontal_dilution = float(self.Nmea_Message.horizontal_dil)
if self.Nmea_Message.sentence_type == 'VTG':
try:
self.GPS_msg.kmph = float(self.Nmea_Message.spd_over_grnd_kmph)
except:
pass
if self.Nmea_Message.true_track is not None:
self.GPS_msg.gps_heading = float(self.Nmea_Message.true_track)
else:
self.GPS_msg.gps_heading = -1.0
# Instantiates all subscriber methods
def __instantiate_subscribers(self):
# Iris Status Subscriber
self.iris_status_sub = rospy.Subscriber(self.iris_status_topic_name, IrisStatusMessage, self.__iris_status_callback)
# Bogie Wheel Subscribers
self.bogie_left_sub = rospy.Subscriber(self.bogie_left_topic_name, DriveStatusMessage, self.__left_wheel_callback)
self.bogie_right_sub = rospy.Subscriber(self.bogie_right_topic_name, DriveStatusMessage, self.__right_wheel_callback)
self.bogie_rear_sub = rospy.Subscriber(self.bogie_rear_topic_name, DriveStatusMessage, self.__rear_wheel_callback)
# GPS NMEA subscriber
self.gps_nmea_sub = rospy.Subscriber(self.gps_nmea_topic_name, Sentence, self.__set_gps_info)
def __iris_status_callback(self, data):
self.battery_message.battery_voltage = data.voltage_24v
def __left_wheel_callback(self, data):
self.wheel_msg.front_left = data.first_motor_connected
self.wheel_msg.middle_left = data.second_motor_connected
def __right_wheel_callback(self, data):
self.wheel_msg.front_right = data.first_motor_connected
self.wheel_msg.middle_right = data.second_motor_connected
def __rear_wheel_callback(self, data):
self.wheel_msg.rear_left = data.first_motor_connected
self.wheel_msg.rear_right = data.second_motor_connected
# Checks arm connection status (WIP)
def __set_arm_connection_status(self):
self.misc_msg.arm_connection_status = 0
# Checks Arm End Effector Connection Statuses (WIP)
def __set_arm_end_effector_connection_statuses(self):
self.misc_msg.arm_end_effector_connection_statuses = 0
# Sets the Camera values (zed, undercarriage, chassis, and main_nav
def __set_cameras(self):
# Check if camera_zed is found
self.camera_msg.camera_zed = 1 if os.path.exists(self.system_path_locations[0]) else 0
# Check if camera_undercarriage is found
self.camera_msg.camera_undercarriage = 1 if os.path.exists(self.system_path_locations[1]) else 0
# Check if camera_chassis is found
self.camera_msg.camera_chassis = 1 if os.path.exists(self.system_path_locations[2]) else 0
# Check if camera_main_navigation is found
self.camera_msg.camera_main_navigation = 1 if os.path.exists(self.system_path_locations[3]) else 0
# Checks Sample Containment Connection Status (WIP)
def __set_sample_containment_connection_status(self):
self.misc_msg.sample_containment_connection_status = 0
def __set_tower_connection_status(self):
self.misc_msg.tower_connection_status = 0
# Checks Tower Connection Status (WIP)
def __set_chassis_pan_tilt_connection_status(self):
self.misc_msg.chassis_pan_tilt_connection_status = 0
# Get Jetson Statuses (WIP)
def __set_jetson_usage_information(self):
self.jetson_msg.jetson_CPU = psutil.cpu_percent()
mem = psutil.virtual_memory()
self.jetson_msg.jetson_RAM = mem.percent
self.jetson_msg.jetson_EMMC = self.__used_percent_fs(self.file_systems_EMMC_NVMe_SSD[0])
self.jetson_msg.jetson_NVME_SSD = self.__used_percent_fs(self.file_systems_EMMC_NVMe_SSD[1])
# Temperature
# This try except causes a bunch of annoying messages, but lets it run on non-jetson devices
# sets to -1.0 if sensor fails to give it a default value notifying failure to pull
try:
sensor_temperatures = subprocess.check_output("sensors | grep temp", shell=True)
parsed_temps = sensor_temperatures.replace("\xc2\xb0C","").replace("(crit = ","").replace("temp1:","")\
.replace("\n", "").replace("+", "").split()
self.jetson_msg.jetson_GPU_temp = float(parsed_temps[4])
except subprocess.CalledProcessError:
print('sensors call failed (potential reason: on VM)')
self.jetson_msg.jetson_GPU_temp = -1.0
# EMMC and NVMe_SSD used % calculation
def __used_percent_fs(self, pathname):
statvfs = os.statvfs(pathname)
# percentage :: USED:
# used amount: blocks - bfree
# used%: used_amount / (used_amount + bavail)
used_available = (statvfs.f_frsize * statvfs.f_blocks / 1024) - (statvfs.f_frsize * statvfs.f_bfree / 1024.0)
used_percent = used_available / (used_available + (statvfs.f_frsize * statvfs.f_bavail / 1024.0))
# Round 4 for 2 decimal accuracy
value = 100 * round(used_percent, 4)
return value
# Check FrSky Controller Connection Status (WIP)
def __set_frsky_controller_connection_status(self):
rospy.Subscriber('/rover_control/command_control/iris_drive', DriveCommandMessage, self.__frsky_callback)
def __frsky_callback(self, data):
self.FrSky_msg.FrSky_controller_connection_status = data.controller_present
# Used mainly for init, sets all previous values in one go
def __update_all_previous_values(self):
self.__set_previous_battery_values()
self.__set_previous_camera_values()
self.__set_previous_jetson_values()
self.__set_previous_frsky_value()
self.__set_previous_wheel_values()
self.__set_previous_gps_values()
self.__set_previous_misc_values()
def __set_previous_camera_values(self):
self.previous_camera_zed = self.camera_msg.camera_zed
self.previous_camera_undercarriage = self.camera_msg.camera_undercarriage
self.previous_camera_chassis = self.camera_msg.camera_chassis
self.previous_camera_main_navigation = self.camera_msg.camera_main_navigation
def __set_previous_jetson_values(self):
self.previous_jetson_CPU = self.jetson_msg.jetson_CPU
self.previous_jetson_RAM = self.jetson_msg.jetson_RAM
self.previous_jetson_EMMC = self.jetson_msg.jetson_EMMC
self.previous_jetson_NVME_SSD = self.jetson_msg.jetson_NVME_SSD
self.previous_jetson_GPU_temp = self.jetson_msg.jetson_GPU_temp
def __set_previous_frsky_value(self):
self.previous_FrSky_controller_connection_status = self.FrSky_msg.FrSky_controller_connection_status
def __set_previous_wheel_values(self):
self.previous_wheel_front_left = self.wheel_msg.front_left
self.previous_wheel_middle_left = self.wheel_msg.middle_left
self.previous_wheel_rear_left = self.wheel_msg.rear_left
self.previous_wheel_front_right = self.wheel_msg.front_right
self.previous_wheel_middle_right = self.wheel_msg.middle_right
self.previous_wheel_rear_right = self.wheel_msg.rear_right
def __set_previous_gps_values(self):
self.previous_gps_connected = self.GPS_msg.gps_connected
self.previous_gps_fix = self.GPS_msg.gps_fix
self.previous_gps_num_satellites = self.GPS_msg.num_satellites
self.previous_gps_horizontal_dilution = self.GPS_msg.horizontal_dilution
self.previous_gps_kmph = self.GPS_msg.kmph
self.previous_gps_heading = self.GPS_msg.gps_heading
def __set_previous_misc_values(self):
self.previous_arm_connection_status = self.misc_msg.arm_connection_status
self.previous_arm_end_effector_connection_statuses = self.misc_msg.arm_end_effector_connection_statuses
self.previous_chassis_pan_tilt_connection_status = self.misc_msg.chassis_pan_tilt_connection_status
self.previous_sample_containment_connection_status = self.misc_msg.sample_containment_connection_status
self.previous_tower_connection_status = self.misc_msg.tower_connection_status
def __set_previous_battery_values(self):
self.previous_battery_voltage = self.battery_message.battery_voltage
def on_update_requested(self, _):
self.manual_update_requested = True
def run(self):
r = rospy.Rate(10) # 10Hz
while not rospy.is_shutdown():
# Update all message values
self.__pull_new_message_values()
if (self.battery_message.battery_voltage != self.previous_battery_voltage or
self.manual_update_requested):
if (time() - self.last_iris_message_sent) > (1.0 / MAX_IRIS_UPDATE_HERTZ):
self.__set_previous_battery_values()
self.pub_battery.publish(self.battery_message)
self.last_iris_message_sent = time()
# Camera Check -- if current value is now different from previous value,
# update the previous value for cameras and publish to listening Subscribers
if (self.camera_msg.camera_zed != self.previous_camera_zed or
self.camera_msg.camera_undercarriage != self.previous_camera_undercarriage or
self.camera_msg.camera_chassis != self.previous_camera_chassis or
self.camera_msg.camera_main_navigation != self.previous_camera_main_navigation or
self.manual_update_requested):
self.__set_previous_camera_values()
self.pub_camera.publish(self.camera_msg)
# Placeholder Jetson Info Check
if (self.jetson_msg.jetson_CPU != self.previous_jetson_CPU or
self.jetson_msg.jetson_RAM != self.previous_jetson_RAM or
self.jetson_msg.jetson_EMMC != self.previous_jetson_EMMC or
self.jetson_msg.jetson_NVME_SSD != self.previous_jetson_NVME_SSD or
self.jetson_msg.jetson_GPU_temp != self.previous_jetson_GPU_temp or
self.manual_update_requested):
if (time() - self.last_jetson_message_sent) > (1.0 / MAX_JETSON_UPDATE_HERTZ):
self.__set_previous_jetson_values()
self.pub_jetson.publish(self.jetson_msg)
self.last_jetson_message_sent = time()
# Placeholder FrSky Controller Check
if (self.FrSky_msg.FrSky_controller_connection_status != self.previous_FrSky_controller_connection_status or
self.manual_update_requested):
self.__set_previous_frsky_value()
self.pub_FrSky.publish(self.FrSky_msg)
# bogie wheel status check
if (self.wheel_msg.front_left != self.previous_wheel_front_left or
self.wheel_msg.middle_left != self.previous_wheel_middle_left or
self.wheel_msg.rear_left != self.previous_wheel_rear_left or
self.wheel_msg.front_right != self.previous_wheel_front_right or
self.wheel_msg.middle_right != self.previous_wheel_middle_right or
self.wheel_msg.rear_right != self.previous_wheel_rear_right or
self.manual_update_requested):
self.__set_previous_wheel_values()
self.pub_wheel.publish(self.wheel_msg)
# Placeholder GPS Information check
# if (self.GPS_msg.UTC_GPS_time != self.previous_UTC_GPS_time or
# self.GPS_msg.UTC_GPS_time != self.previous_GPS_connection_status or
# self.manual_update_requested):
# self.__set_previous_gps_values()
# self.pub_GPS.publish(self.GPS_msg)
# GPS info status -- connected, fix, satellites, horizontal dilution, kmph, and heading
if (self.GPS_msg.gps_connected != self.previous_gps_connected or
self.GPS_msg.gps_fix != self.previous_gps_fix or
self.GPS_msg.num_satellites != self.previous_gps_num_satellites or
self.GPS_msg.horizontal_dilution != self.previous_gps_horizontal_dilution or
self.GPS_msg.kmph != self.previous_gps_kmph or
self.GPS_msg.gps_heading != self.previous_gps_heading):
self.__set_previous_gps_values()
self.pub_GPS.publish(self.GPS_msg)
# Placeholder Misc Information check
if (self.misc_msg.arm_connection_status !=
self.previous_arm_connection_status or
self.misc_msg.arm_end_effector_connection_statuses !=
self.previous_arm_end_effector_connection_statuses or
self.misc_msg.chassis_pan_tilt_connection_status !=
self.previous_chassis_pan_tilt_connection_status or
self.misc_msg.sample_containment_connection_status !=
self.previous_sample_containment_connection_status or
self.misc_msg.tower_connection_status != self.previous_tower_connection_status or
self.manual_update_requested):
self.__set_previous_misc_values()
self.pub_Misc.publish(self.misc_msg)
if self.manual_update_requested:
self.manual_update_requested = False
r.sleep()
if __name__ == '__main__':
system_status = SystemStatuses()
system_status.run()