def capture_image(): stream_url = "http://" + fetch_ros_master_ip() + ":8080/stream?topic=/cv_camera/image_raw" #lserror, lsoutput = run_shell("ls -1q img* | wc -l") # p1 = subprocess.Popen(split("ls -1q img*"), stdout=subprocess.PIPE) # p2 = subprocess.Popen(split("wc -l"), stdin=p1.stdout) # output, error = p2.communicate() output, error = run_shell('ls') output = output.decode() print('output:', output) i = 0 if 'img' in output: i = output.rfind('img') i = int(output[i + 3]) + 1 # shift by 'img' print('i', i) error, output = run_shell("ffmpeg -i " + stream_url + " -ss 00:00:01.500 -f image2 -vframes 1 img" + str(i) + ".jpg") msg = "success" if error: msg = "F" print('msg', msg) return jsonify(msg=msg)
def feed_connection_check(stream, formatted_date, recording_log_msg): """ Check if video feed is up before starting start ffmpeg """ stream_url = "http://" + fetch_ros_master_ip( ) + ":8080/stream?topic=/cv_camera/image_raw" error_state = 0 connection_check = os.system('ffprobe -select_streams v -i ' + stream_url) if connection_check == 0: threading.Thread(target=start_ffmpeg_record, args=(stream, stream_url, formatted_date)).start() print(recording_log_msg) return jsonify(recording_log_msg=recording_log_msg, error_state=error_state) else: recording_log_msg = 'failed to connect to video feed of ' + stream error_state = 1 print(recording_log_msg) return jsonify(recording_log_msg=recording_log_msg, error_state=error_state)
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(): """Stream page.""" return flask.render_template("pages/Stream.html", roverIP=fetch_ros_master_ip())
def pds(): """PDS page.""" return flask.render_template("pages/PDS.html", roverIP=fetch_ros_master_ip())
def science(): """Science page.""" return flask.render_template("pages/Science.html", roverIP=fetch_ros_master_ip())
def rover(): """Rover control panel.""" return flask.render_template("pages/Rover.html", roverIP=fetch_ros_master_ip())
def index(): """Current landing page, the arm panel.""" return flask.render_template("pages/Arm.html", roverIP=fetch_ros_master_ip())
def navigation(): """Navigation page.""" return flask.render_template("pages/Navigation.html", roverIP=fetch_ros_master_ip())
def camerapopup(): """Camera Pop-up.""" return flask.render_template("pages/CameraPopUp.html", roverIP=fetch_ros_master_ip())