From 263edbde06f4d5218459a652aadd6b3d71791ca1 Mon Sep 17 00:00:00 2001 From: Carmen Date: Wed, 1 Jun 2022 00:00:23 -0400 Subject: [PATCH] [percep, ansible] percep upgraded streaming (#1132) --- .../rover-base_station_gstreamer.service | 9 -------- .../rover-base_station_gstreamer@.service | 10 +++++++++ ...er => rover-base_station_gstreamer@.timer} | 0 .../rover-base_station_gstreamer_2.service | 9 -------- .../base_station_services/files/rover.env | 3 +++ .../base_station_services/tasks/main.yml | 16 +++++++------- .../files/rover-science-gstreamer-2.service | 9 -------- .../files/rover-science-gstreamer-2.timer | 5 ----- .../files/rover-science-gstreamer.service | 9 -------- .../files/rover-science-gstreamer.timer | 5 ----- .../files/rover-science-gstreamer@.service | 9 ++++++++ .../files/rover-science-gstreamer@.timer} | 0 ansible/roles/science_services/tasks/main.yml | 14 ++++++------- jetson/percep/config.h.in | 1 + jetson/percep/main.cpp | 21 ++++++++++++++++++- jetson/percep/meson.build | 2 ++ jetson/percep/meson_options.txt | 3 ++- 17 files changed, 61 insertions(+), 64 deletions(-) delete mode 100644 ansible/roles/base_station_services/files/rover-base_station_gstreamer.service create mode 100644 ansible/roles/base_station_services/files/rover-base_station_gstreamer@.service rename ansible/roles/base_station_services/files/{rover-base_station_gstreamer.timer => rover-base_station_gstreamer@.timer} (100%) delete mode 100644 ansible/roles/base_station_services/files/rover-base_station_gstreamer_2.service delete mode 100644 ansible/roles/science_services/files/rover-science-gstreamer-2.service delete mode 100644 ansible/roles/science_services/files/rover-science-gstreamer-2.timer delete mode 100644 ansible/roles/science_services/files/rover-science-gstreamer.service delete mode 100644 ansible/roles/science_services/files/rover-science-gstreamer.timer create mode 100644 ansible/roles/science_services/files/rover-science-gstreamer@.service rename ansible/roles/{base_station_services/files/rover-base_station_gstreamer_2.timer => science_services/files/rover-science-gstreamer@.timer} (100%) diff --git a/ansible/roles/base_station_services/files/rover-base_station_gstreamer.service b/ansible/roles/base_station_services/files/rover-base_station_gstreamer.service deleted file mode 100644 index 4293d913a7..0000000000 --- a/ansible/roles/base_station_services/files/rover-base_station_gstreamer.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Base Station Video Stream - -[Service] -Environment="DISPLAY=:0" -Environment="XAUTHORITY=/home/mrover/.Xauthority" -User={{ running_user }} -ExecStart=/usr/bin/gst-launch-1.0 -v udpsrc port=5000 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! autovideosink -Restart=always \ No newline at end of file diff --git a/ansible/roles/base_station_services/files/rover-base_station_gstreamer@.service b/ansible/roles/base_station_services/files/rover-base_station_gstreamer@.service new file mode 100644 index 0000000000..1c63c95c38 --- /dev/null +++ b/ansible/roles/base_station_services/files/rover-base_station_gstreamer@.service @@ -0,0 +1,10 @@ +[Unit] +Description=Base Station Video Stream %I + +[Service] +Environment="DISPLAY=:0" +Environment="XAUTHORITY=/home/mrover/.Xauthority" +EnvironmentFile=/etc/default/rover.env +User={{ running_user }} +ExecStart=/usr/bin/gst-launch-1.0 -v udpsrc port=%i caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! autovideosink +Restart=always \ No newline at end of file diff --git a/ansible/roles/base_station_services/files/rover-base_station_gstreamer.timer b/ansible/roles/base_station_services/files/rover-base_station_gstreamer@.timer similarity index 100% rename from ansible/roles/base_station_services/files/rover-base_station_gstreamer.timer rename to ansible/roles/base_station_services/files/rover-base_station_gstreamer@.timer diff --git a/ansible/roles/base_station_services/files/rover-base_station_gstreamer_2.service b/ansible/roles/base_station_services/files/rover-base_station_gstreamer_2.service deleted file mode 100644 index 166b8ca64e..0000000000 --- a/ansible/roles/base_station_services/files/rover-base_station_gstreamer_2.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Base Station Video Stream 2 - -[Service] -Environment="DISPLAY=:0" -Environment="XAUTHORITY=/home/mrover/.Xauthority" -User={{ running_user }} -ExecStart=/usr/bin/gst-launch-1.0 -v udpsrc port=5001 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! autovideosink -Restart=always \ No newline at end of file diff --git a/ansible/roles/base_station_services/files/rover.env b/ansible/roles/base_station_services/files/rover.env index 7804047a2d..95573d52c2 100644 --- a/ansible/roles/base_station_services/files/rover.env +++ b/ansible/roles/base_station_services/files/rover.env @@ -1 +1,4 @@ LCM_DEFAULT_URL="udpm://239.255.76.67:7667?ttl=255" +usbcam0=5000 +usbcam1=5001 +zed=5002 diff --git a/ansible/roles/base_station_services/tasks/main.yml b/ansible/roles/base_station_services/tasks/main.yml index 3406da1ba7..542ea49c74 100644 --- a/ansible/roles/base_station_services/tasks/main.yml +++ b/ansible/roles/base_station_services/tasks/main.yml @@ -10,12 +10,10 @@ dest: "/etc/systemd/system/{{ item }}" with_items: - rover-base_station_gui.service - - rover-base_station_gstreamer.service - - rover-base_station_gstreamer_2.service + - rover-base_station_gstreamer@.service - rover-lcm_bridge_server.service - rover-base_station_kineval.service - - rover-base_station_gstreamer.timer - - rover-base_station_gstreamer_2.timer + - rover-base_station_gstreamer@.timer - name: Copy environment variable definitions copy: @@ -29,9 +27,11 @@ systemd: name={{item}} enabled=yes with_items: - rover-base_station_gui.service - - rover-base_station_gstreamer.service - - rover-base_station_gstreamer_2.service + - rover-base_station_gstreamer@5000.service + - rover-base_station_gstreamer@5001.service + - rover-base_station_gstreamer@5002.service - rover-lcm_bridge_server.service - rover-base_station_kineval.service - - rover-base_station_gstreamer.timer - - rover-base_station_gstreamer_2.timer + - rover-base_station_gstreamer@5000.timer + - rover-base_station_gstreamer@5001.timer + - rover-base_station_gstreamer@5002.timer diff --git a/ansible/roles/science_services/files/rover-science-gstreamer-2.service b/ansible/roles/science_services/files/rover-science-gstreamer-2.service deleted file mode 100644 index 166b8ca64e..0000000000 --- a/ansible/roles/science_services/files/rover-science-gstreamer-2.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Base Station Video Stream 2 - -[Service] -Environment="DISPLAY=:0" -Environment="XAUTHORITY=/home/mrover/.Xauthority" -User={{ running_user }} -ExecStart=/usr/bin/gst-launch-1.0 -v udpsrc port=5001 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! autovideosink -Restart=always \ No newline at end of file diff --git a/ansible/roles/science_services/files/rover-science-gstreamer-2.timer b/ansible/roles/science_services/files/rover-science-gstreamer-2.timer deleted file mode 100644 index 402352bf1d..0000000000 --- a/ansible/roles/science_services/files/rover-science-gstreamer-2.timer +++ /dev/null @@ -1,5 +0,0 @@ -[Timer] -OnBootSec=20s - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/ansible/roles/science_services/files/rover-science-gstreamer.service b/ansible/roles/science_services/files/rover-science-gstreamer.service deleted file mode 100644 index 4293d913a7..0000000000 --- a/ansible/roles/science_services/files/rover-science-gstreamer.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Base Station Video Stream - -[Service] -Environment="DISPLAY=:0" -Environment="XAUTHORITY=/home/mrover/.Xauthority" -User={{ running_user }} -ExecStart=/usr/bin/gst-launch-1.0 -v udpsrc port=5000 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! autovideosink -Restart=always \ No newline at end of file diff --git a/ansible/roles/science_services/files/rover-science-gstreamer.timer b/ansible/roles/science_services/files/rover-science-gstreamer.timer deleted file mode 100644 index 402352bf1d..0000000000 --- a/ansible/roles/science_services/files/rover-science-gstreamer.timer +++ /dev/null @@ -1,5 +0,0 @@ -[Timer] -OnBootSec=20s - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/ansible/roles/science_services/files/rover-science-gstreamer@.service b/ansible/roles/science_services/files/rover-science-gstreamer@.service new file mode 100644 index 0000000000..314664b63c --- /dev/null +++ b/ansible/roles/science_services/files/rover-science-gstreamer@.service @@ -0,0 +1,9 @@ +[Unit] +Description=Base Station Video Stream %I + +[Service] +Environment="DISPLAY=:0" +Environment="XAUTHORITY=/home/mrover/.Xauthority" +User={{ running_user }} +ExecStart=/usr/bin/gst-launch-1.0 -v udpsrc port=%i caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! autovideosink +Restart=always \ No newline at end of file diff --git a/ansible/roles/base_station_services/files/rover-base_station_gstreamer_2.timer b/ansible/roles/science_services/files/rover-science-gstreamer@.timer similarity index 100% rename from ansible/roles/base_station_services/files/rover-base_station_gstreamer_2.timer rename to ansible/roles/science_services/files/rover-science-gstreamer@.timer diff --git a/ansible/roles/science_services/tasks/main.yml b/ansible/roles/science_services/tasks/main.yml index ee5cb9ac0e..60ea863e9d 100644 --- a/ansible/roles/science_services/tasks/main.yml +++ b/ansible/roles/science_services/tasks/main.yml @@ -4,10 +4,8 @@ dest: "/etc/systemd/system/{{ item }}" with_items: - rover-lcm-bridge-server.service - - rover-science-gstreamer.service - - rover-science-gstreamer-2.service - - rover-science-gstreamer.timer - - rover-science-gstreamer-2.timer + - rover-science-gstreamer@.service + - rover-science-gstreamer@.timer - rover-science-gui.service - rover-science-raman.service @@ -23,9 +21,9 @@ systemd: name={{ item }} enabled=yes with_items: - rover-lcm-bridge-server.service - - rover-science-gstreamer.service - - rover-science-gstreamer-2.service - - rover-science-gstreamer.timer - - rover-science-gstreamer-2.timer + - rover-science-gstreamer@5000.service + - rover-science-gstreamer@5001.service + - rover-science-gstreamer@5000.timer + - rover-science-gstreamer@5001.timer - rover-science-gui.service - rover-science-raman.service \ No newline at end of file diff --git a/jetson/percep/config.h.in b/jetson/percep/config.h.in index ef2f2636fd..f0efa66de4 100644 --- a/jetson/percep/config.h.in +++ b/jetson/percep/config.h.in @@ -5,6 +5,7 @@ #mesondefine OBS_RECORD #mesondefine ZED_SDK_PRESENT #mesondefine PERCEPTION_DEBUG +#mesondefine STREAM_ZED #mesondefine WRITE_CURR_FRAME_TO_DISK #mesondefine DEFAULT_ONLINE_DATA_FOLDER diff --git a/jetson/percep/main.cpp b/jetson/percep/main.cpp index bd2727773c..d172c8c21d 100644 --- a/jetson/percep/main.cpp +++ b/jetson/percep/main.cpp @@ -130,8 +130,20 @@ int main() { DoubleTrack(&detector.getAlvarParams()->maxErroneousBitsInBorderRate).setup("maxErroneousBitsInBorderRate", "ARUCO Debug", 1); DoubleTrack(&detector.getAlvarParams()->minOtsuStdDev).setup("minOtsuStdDev", "ARUCO Debug", 20); DoubleTrack(&detector.getAlvarParams()->errorCorrectionRate).setup("errorCorrectionRate", "ARUCO Debug", 1); + #endif + #if AR_DETECTION && STREAM_ZED + std::string const gstLaunch = "appsrc ! video/x-raw, format=BGR !" + "queue ! videoconvert ! x264enc tune=zerolatency bitrate=500000 speed-preset=superfast !" + "rtph264pay ! udpsink host=10.0.0.1 port=5002"; + + cv::Size streamSize(256, 144); + cv::VideoWriter writer(gstLaunch, 0, 30, streamSize); + cv::Mat send(streamSize, CV_8UC3); + + #endif + /* --- Main Processing Stuff --- */ while (true) { //Check to see if we were able to grab the frame @@ -143,6 +155,7 @@ int main() { cv::Mat src = cam.image(); cv::Mat depth_img = cam.depth(); cv::Mat xyz_img = cam.xyz(); + #endif #if OBSTACLE_DETECTION @@ -170,11 +183,17 @@ int main() { #if AR_RECORD cam.record_ar(rgb); #endif +#if STREAM_ZED + cv::Mat bgr, sendMat; + cv::cvtColor(rgb, bgr, cv::COLOR_RGB2BGR); + cv::resize(bgr, sendMat, streamSize); + writer.write(sendMat); +#endif detector.updateDetectedTagInfo(arTags, tagPair, depth_img, xyz_img); #if PERCEPTION_DEBUG && AR_DETECTION -// cv::imshow("depth", depth_img); + cv::imshow("depth", depth_img); cv::waitKey(1); #endif diff --git a/jetson/percep/meson.build b/jetson/percep/meson.build index c366c7ad87..6af2f91a3a 100644 --- a/jetson/percep/meson.build +++ b/jetson/percep/meson.build @@ -66,6 +66,7 @@ obs_record = get_option('obs_record') perception_debug = get_option('perception_debug') write_frame = get_option('write_frame') data_folder = get_option('data_folder') +stream_zed = get_option('stream_zed') conf_data = configuration_data() conf_data.set10('AR_DETECTION', ar_detection) @@ -74,6 +75,7 @@ conf_data.set10('OBSTACLE_DETECTION', obs_detection) conf_data.set10('OBSTACLE_RECORD', obs_record) conf_data.set10('ZED_SDK_PRESENT', with_zed) conf_data.set10('PERCEPTION_DEBUG', perception_debug) +conf_data.set10('STREAM_ZED', stream_zed) conf_data.set10('WRITE_CURR_FRAME_TO_DISK', write_frame) conf_data.set10('VIRTUAL_MACHINE_CONFIG', vm_config) conf_data.set_quoted('DEFAULT_ONLINE_DATA_FOLDER', data_folder) diff --git a/jetson/percep/meson_options.txt b/jetson/percep/meson_options.txt index 86b148ecf8..49ce6b0cf6 100644 --- a/jetson/percep/meson_options.txt +++ b/jetson/percep/meson_options.txt @@ -2,8 +2,9 @@ option('ar_detection', type: 'boolean', value : true) option('ar_record', type: 'boolean', value : false) option('obs_detection', type: 'boolean', value: false) option('obs_record', type: 'boolean', value : false) +option('stream_zed', type: 'boolean', value: false) option('with_zed', type: 'boolean', value : true) -option('perception_debug', type: 'boolean', value: true) +option('perception_debug', type: 'boolean', value: false) option('write_frame', type: 'boolean', value: false) option('data_folder', type: 'string', value: '/home/jessica/auton_data/') option('vm_config',type: 'boolean', value: false)