def stop(self, p_keyword=''): if self.is_running(): print("Terminating process...") if self.force_kill: # edge case due to current implementation of video streamer if "start_ros_stream" in self.script: if p_keyword: real_pid = get_pid(p_keyword) else: real_pid = get_pid("cv_camera_node") if real_pid != -1: output, error = run_shell("kill -9", str(real_pid)) print("kill -9", str(real_pid)) else: return False else: self.p1.kill() print("Process terminated") self.p1_pid = -1 return True print("Failed to terminate process") return False
def stream_capture(stream_url): """ Given a stream, captures an image. stream_url : The URL of the stream to capture the image. """ image_directory = IMAGES_FOLDER + "/" + get_stream_shortname( stream_url) + "/" print("Capturing image of " + stream_url) if not os.path.exists(image_directory): os.makedirs(image_directory) formatted_date = datetime.datetime.now().strftime("%Y_%m_%d_%I_%M_%S") filename = get_stream_shortname(stream_url) + "_" + formatted_date + ".jpg" filename = image_directory + filename error, output = run_shell("ffmpeg -i " + stream_url + " -ss 00:00:01.500 -f image2 -vframes 1 " + filename) message = "Successfully captured image " + os.path.abspath(filename) if error: message = "Failed to capture image of " + stream_url print(message) return not error, message
def odroid_rx(): script_dir = os.path.dirname(os.path.realpath(__file__)) log_file = script_dir + "/../rospackages/src/odroid_rx/scripts/odroid_rx.txt" print("odroid_rx") # query the topic exactly once output, error = run_shell("cat", log_file) output = str(output, "utf-8") print("output: " + output) return jsonify(success=True, odroid_rx=output)
def ping_rover(): """Pings ROS_MASTER_URI and return response object with resulting outputs. Pings rover first directly with Unix ping command, then using ros ping_acknowledgment service. Returns JSON object with the following fields: success -- whether requests was successful ping_msg -- output of Unix ping command ros_msg -- output of the ROS ping_acknowledgment service """ ping_output, error = run_shell("ping -c 1 " + fetch_ros_master_ip()) ping_output = ping_output.decode() print("Output: " + ping_output) if "Destination Net Unreachable" in ping_output: error_msg = "Basestation has no connection to network, aborting ROS ping." return jsonify(success=False, ping_msg=ping_output, ros_msg=error_msg) if "Destination Host Unreachable" in ping_output: error_msg = "Rover has no connection to network, aborting ROS ping." return jsonify(success=False, ping_msg=ping_output, ros_msg=error_msg) if error: print("Error: " + error.decode()) ros_output, error = run_shell( "rosrun ping_acknowledgment ping_response_client.py hello") ros_output = ros_output.decode() print("Pinging rover") print("Output: " + ros_output) if error: print("Error: " + error.decode()) return jsonify(success=True, ping_msg=ping_output, ros_msg=ros_output)
def stream_capture(stream_url, camera_rotation): """ Given a stream, captures an image and rotates it as shown in GUI stream_url : The URL of the stream to capture the image. camera_rotation : The rotation value (0,1,2,3) of the stream as shown in the GUI. 0 = no rotation. 1 = clockwise 90 degrees 2 = 180 degrees. 3 = counterclockwise 90 degrees """ image_directory = IMAGES_FOLDER + "/" + get_stream_shortname( stream_url) + "/" print("Capturing image of " + stream_url) if not os.path.exists(image_directory): os.makedirs(image_directory) formatted_date = datetime.datetime.now().strftime("%Y_%m_%d_%I_%M_%S") image_filename = get_stream_shortname( stream_url) + "_" + formatted_date + ".jpg" image_filename = image_directory + image_filename error, output = run_shell("ffmpeg -i " + stream_url + " -ss 00:00:01.500 -f image2 -vframes 1 " + image_filename) rotate_stream(image_filename, camera_rotation) message = "Successfully captured image " + os.path.abspath(image_filename) if error: message = "Failed to capture image of " + stream_url print(message) return not error, message
def get_branch_name(): output, error = run_shell('git', 'symbolic-ref --short HEAD', False) return output.decode('utf8')[:-1]
#!/usr/bin/env python3 import robot.basestation.app as app from robot.util.utils import run_shell import re excluded_branches = {'master', 'develop', 'staging', 'test'} output, error = run_shell('git', 'symbolic-ref --short HEAD', False) branch_name = output.decode('utf8')[:-1] def is_excluded_branch(branch_name, excluded_branches): """ returns true if branch name is in list of excluded branches """ return branch_name in excluded_branches def get_issue_num(branch_name): """ Gets issue number from branch name returns None if there is no issue number """ issue_num = re.search(r'\d+$', branch_name) if issue_num is not None: issue_num = issue_num.group(0) return issue_num def has_issue_num(branch_name): """