Components and supplies
Mindstorms NXT Programming Brick / Kit
HERO Series Camera
Project description
Code
Video Streaming - GoPro Hero
python
This is code will help you to visualize the robot's vision. You can use the official app available from GoPro. Credits for the code below.
1## GoPro Instant Streaming v1.0 2## 3## By @Sonof8Bits and @KonradIT 4## 5## 1. Connect your desktop or laptop to your GoPro via WIFI. 6## 2. Set the parameters below. 7## 3. Run this script. 8## 9## Supported cameras: 10## GoPro HERO5 (incl. Session), HERO4 (incl. Session), HERO+, HERO3+, HERO3, HERO2 w/ WiFi BacPac. 11## 12## That's all! When done, press CTRL+C to quit this application. 13## 14 15import sys 16import socket 17try: 18 # For Python 3.0 and later 19 from urllib.request import urlopen 20except ImportError: 21 # Fall back to Python 2's urllib2 22 from urllib2 import urlopen 23import subprocess 24from time import sleep 25import signal 26import json 27import re 28import http 29 30def get_command_msg(id): 31 return "_GPHD_:%u:%u:%d:%1lf\ 32" % (0, 0, 2, 0) 33 34## Parameters: 35## 36VERBOSE=False 37## Sends Record command to GoPro Camera, must be in Video mode! 38RECORD=False 39## 40## Saves the feed to a custom location 41SAVE=False 42SAVE_FILENAME="goprofeed3" 43SAVE_FORMAT="ts" 44SAVE_LOCATION="/tmp/" 45 46def gopro_live(): 47 UDP_IP = "10.5.5.9" 48 UDP_PORT = 8554 49 KEEP_ALIVE_PERIOD = 2500 50 KEEP_ALIVE_CMD = 2 51 52 MESSAGE = get_command_msg(KEEP_ALIVE_CMD) 53 URL = "http://10.5.5.9:8080/live/amba.m3u8" 54 try: 55 # original code - response_raw = urllib.request.urlopen('http://10.5.5.9/gp/gpControl').read().decode('utf-8') 56 response_raw = urlopen('http://10.5.5.9/gp/gpControl').read().decode('utf-8') 57 jsondata=json.loads(response_raw) 58 response=jsondata["info"]["firmware_version"] 59 except http.client.BadStatusLine: 60 response = urlopen('http://10.5.5.9/camera/cv').read().decode('utf-8') 61 if "HD4" in response or "HD3.2" in response or "HD5" in response or "HX" in response or "HD6" in response: 62 print("branch HD4") 63 print(jsondata["info"]["model_name"]+"\ 64"+jsondata["info"]["firmware_version"]) 65 ## 66 ## HTTP GETs the URL that tells the GoPro to start streaming. 67 ## 68 urlopen("http://10.5.5.9/gp/gpControl/execute?p1=gpStream&a1=proto_v2&c1=restart").read() 69 if RECORD: 70 urlopen("http://10.5.5.9/gp/gpControl/command/shutter?p=1").read() 71 print("UDP target IP:", UDP_IP) 72 print("UDP target port:", UDP_PORT) 73 print("message:", MESSAGE) 74 print("Recording on camera: " + str(RECORD)) 75 76 ## GoPro HERO4 Session needs status 31 to be greater or equal than 1 in order to start the live feed. 77 if "HX" in response: 78 connectedStatus=False 79 while connectedStatus == False: 80 req=urlopen("http://10.5.5.9/gp/gpControl/status") 81 data = req.read() 82 encoding = req.info().get_content_charset('utf-8') 83 json_data = json.loads(data.decode(encoding)) 84 if json_data["status"]["31"] >= 1: 85 connectedStatus=True 86 ## 87 ## Opens the stream over udp in ffplay. This is a known working configuration by Reddit user hoppjerka: 88 ## https://www.reddit.com/r/gopro/comments/2md8hm/how_to_livestream_from_a_gopro_hero4/cr1b193 89 ## 90 loglevel_verbose="" 91 if VERBOSE==False: 92 loglevel_verbose = "-loglevel panic" 93 if SAVE == False: 94 subprocess.Popen("ffplay " + loglevel_verbose + " -fflags nobuffer -f:v mpegts -probesize 8192 udp://:8554", shell=True) 95 else: 96 if SAVE_FORMAT=="ts": 97 TS_PARAMS = " -acodec copy -vcodec copy " 98 else: 99 TS_PARAMS = "" 100 SAVELOCATION = SAVE_LOCATION + SAVE_FILENAME + "." + SAVE_FORMAT 101 print("Recording locally: " + str(SAVE)) 102 print("Recording stored in: " + SAVELOCATION) 103 print("Note: Preview is not available when saving the stream.") 104 subprocess.Popen("ffmpeg -i 'udp://:8554' -fflags nobuffer -f:v mpegts -probesize 8192 " + TS_PARAMS + SAVELOCATION, shell=True) 105 if sys.version_info.major >= 3: 106 MESSAGE = bytes(MESSAGE, "utf-8") 107 print("Press ctrl+C to quit this application.\ 108") 109 while True: 110 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 111 sock.sendto(MESSAGE, (UDP_IP, UDP_PORT)) 112 sleep(KEEP_ALIVE_PERIOD/1000) 113 else: 114 print("branch hero3"+response) 115 if "Hero3" in response or "HERO3+" in response: 116 print("branch hero3") 117 PASSWORD=urlopen("http://10.5.5.9/bacpac/sd").read() 118 print("HERO3/3+/2 camera") 119 Password = str(PASSWORD, 'utf-8') 120 text=re.sub(r'\\W+', '', Password) 121 urlopen("http://10.5.5.9/camera/PV?t=" + text + "&p=%02") 122 subprocess.Popen("ffplay " + URL, shell=True) 123 124 125 126def quit_gopro(signal, frame): 127 if RECORD: 128 urlopen("http://10.5.5.9/gp/gpControl/command/shutter?p=0").read() 129 sys.exit(0) 130 131if __name__ == '__main__': 132 signal.signal(signal.SIGINT, quit_gopro) 133 gopro_live()
Robot Controller - NXT
There are plenty of softwares that control the NXT, this is only an example. Most of then are for Android.
Robot Controller - NXT
There are plenty of softwares that control the NXT, this is only an example. Most of then are for Android.
Video Streaming - GoPro Hero
python
This is code will help you to visualize the robot's vision. You can use the official app available from GoPro. Credits for the code below.
1## GoPro Instant Streaming v1.0 2## 3## By @Sonof8Bits and @KonradIT 4## 5## 1. Connect your desktop or laptop to your GoPro via WIFI. 6## 2. Set the parameters below. 7## 3. Run this script. 8## 9## Supported cameras: 10## GoPro HERO5 (incl. Session), HERO4 (incl. Session), HERO+, HERO3+, HERO3, HERO2 w/ WiFi BacPac. 11## 12## That's all! When done, press CTRL+C to quit this application. 13## 14 15import sys 16import socket 17try: 18 # For Python 3.0 and later 19 from urllib.request import urlopen 20except ImportError: 21 # Fall back to Python 2's urllib2 22 from urllib2 import urlopen 23import subprocess 24from time import sleep 25import signal 26import json 27import re 28import http 29 30def get_command_msg(id): 31 return "_GPHD_:%u:%u:%d:%1lf\ 32" % (0, 0, 2, 0) 33 34## Parameters: 35## 36VERBOSE=False 37## Sends Record command to GoPro Camera, must be in Video mode! 38RECORD=False 39## 40## Saves the feed to a custom location 41SAVE=False 42SAVE_FILENAME="goprofeed3" 43SAVE_FORMAT="ts" 44SAVE_LOCATION="/tmp/" 45 46def gopro_live(): 47 UDP_IP = "10.5.5.9" 48 UDP_PORT = 8554 49 KEEP_ALIVE_PERIOD = 2500 50 KEEP_ALIVE_CMD = 2 51 52 MESSAGE = get_command_msg(KEEP_ALIVE_CMD) 53 URL = "http://10.5.5.9:8080/live/amba.m3u8" 54 try: 55 # original code - response_raw = urllib.request.urlopen('http://10.5.5.9/gp/gpControl').read().decode('utf-8') 56 response_raw = urlopen('http://10.5.5.9/gp/gpControl').read().decode('utf-8') 57 jsondata=json.loads(response_raw) 58 response=jsondata["info"]["firmware_version"] 59 except http.client.BadStatusLine: 60 response = urlopen('http://10.5.5.9/camera/cv').read().decode('utf-8') 61 if "HD4" in response or "HD3.2" in response or "HD5" in response or "HX" in response or "HD6" in response: 62 print("branch HD4") 63 print(jsondata["info"]["model_name"]+"\ 64"+jsondata["info"]["firmware_version"]) 65 ## 66 ## HTTP GETs the URL that tells the GoPro to start streaming. 67 ## 68 urlopen("http://10.5.5.9/gp/gpControl/execute?p1=gpStream&a1=proto_v2&c1=restart").read() 69 if RECORD: 70 urlopen("http://10.5.5.9/gp/gpControl/command/shutter?p=1").read() 71 print("UDP target IP:", UDP_IP) 72 print("UDP target port:", UDP_PORT) 73 print("message:", MESSAGE) 74 print("Recording on camera: " + str(RECORD)) 75 76 ## GoPro HERO4 Session needs status 31 to be greater or equal than 1 in order to start the live feed. 77 if "HX" in response: 78 connectedStatus=False 79 while connectedStatus == False: 80 req=urlopen("http://10.5.5.9/gp/gpControl/status") 81 data = req.read() 82 encoding = req.info().get_content_charset('utf-8') 83 json_data = json.loads(data.decode(encoding)) 84 if json_data["status"]["31"] >= 1: 85 connectedStatus=True 86 ## 87 ## Opens the stream over udp in ffplay. This is a known working configuration by Reddit user hoppjerka: 88 ## https://www.reddit.com/r/gopro/comments/2md8hm/how_to_livestream_from_a_gopro_hero4/cr1b193 89 ## 90 loglevel_verbose="" 91 if VERBOSE==False: 92 loglevel_verbose = "-loglevel panic" 93 if SAVE == False: 94 subprocess.Popen("ffplay " + loglevel_verbose + " -fflags nobuffer -f:v mpegts -probesize 8192 udp://:8554", shell=True) 95 else: 96 if SAVE_FORMAT=="ts": 97 TS_PARAMS = " -acodec copy -vcodec copy " 98 else: 99 TS_PARAMS = "" 100 SAVELOCATION = SAVE_LOCATION + SAVE_FILENAME + "." + SAVE_FORMAT 101 print("Recording locally: " + str(SAVE)) 102 print("Recording stored in: " + SAVELOCATION) 103 print("Note: Preview is not available when saving the stream.") 104 subprocess.Popen("ffmpeg -i 'udp://:8554' -fflags nobuffer -f:v mpegts -probesize 8192 " + TS_PARAMS + SAVELOCATION, shell=True) 105 if sys.version_info.major >= 3: 106 MESSAGE = bytes(MESSAGE, "utf-8") 107 print("Press ctrl+C to quit this application.\ 108") 109 while True: 110 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 111 sock.sendto(MESSAGE, (UDP_IP, UDP_PORT)) 112 sleep(KEEP_ALIVE_PERIOD/1000) 113 else: 114 print("branch hero3"+response) 115 if "Hero3" in response or "HERO3+" in response: 116 print("branch hero3") 117 PASSWORD=urlopen("http://10.5.5.9/bacpac/sd").read() 118 print("HERO3/3+/2 camera") 119 Password = str(PASSWORD, 'utf-8') 120 text=re.sub(r'\\W+', '', Password) 121 urlopen("http://10.5.5.9/camera/PV?t=" + text + "&p=%02") 122 subprocess.Popen("ffplay " + URL, shell=True) 123 124 125 126def quit_gopro(signal, frame): 127 if RECORD: 128 urlopen("http://10.5.5.9/gp/gpControl/command/shutter?p=0").read() 129 sys.exit(0) 130 131if __name__ == '__main__': 132 signal.signal(signal.SIGINT, quit_gopro) 133 gopro_live()
Downloadable files
Github Page
https://github.com/brudarko/ExplorerRobot
Comments
Only logged in users can leave comments