How we made a simple WebRTC robot at home

Concept

Have you ever had such a thing that after leaving the house you do not remember whether you turned off the iron? Discussing another such case with a friend, a comic idea appeared to make a robot for remote visual checking of household chores. And in general I wanted to make a β€œspy” robot controlled by a camera from a smartphone on my knees. We have been hatching this idea for a long time, but we have only reached our hands now. And we immediately went to the nearest bar for discussion. It is not entirely correct to call it a robot. Rather, it is a self-propelled platform with telemetry control over the Internet. But the article will use the term β€œrobot” simply because it’s more familiar. 





The WebRTC technology suited us perfectly, since it is quite easy to organize the transfer of video, audio and data channels between two peers with a minimum signal delay. And we didn't have any experience with this technology, so we really wanted to try it.





A simplified diagram of the entire system is shown in the figure. User - operator and robot - Raspberry PI each enter their own web page, connect to the signal server, after which a WebRTC session is created between them through which the video stream from the robot is transmitted to the user, and control signals are transmitted to the robot. Further, the robot sends control signals to its localhost, where another service processes them and outputs them to GPIO to control the motors. Everything seems simple. Here's what we got at this stage:  





Next, we will deal with all this in more detail.





Components

, . , . , .





Raspberry Pi (3b 4), , OS Raspbian. , OpenCV, .. , .





()

- ( ), FPS . Logitech QuickCam Connect Logitech C270 12$. Raspicam, . 





β€” β€” , -, . . , :





  1. , .









, . . 





Raspberry Pi . 3.7 DC-DC MT3608, , β€œβ€. - . Samsung. , . power- Xiaomi , - . Raspbery Pi4.





L9110, DC-DC , L293N. , . .





, "", -.   β€œβ€ 1$. Power- , . , Raspberry Pi.  . , . , . -. - power-. 





, , . . JavaScript Python. . , .





NodeJS . :





  • , .





  • , .. -.





  β€œβ€ . . . , .  .





SignalEmitter. . id - , isControl - . signalServer - uri . .  





const se = new SignalEmitter({
	id: searchParams.get('id'),
	isControl: false,
	signalServer: config.signalServer
});
      
      



WebRTC

RTC. - options SignalEmitter, . isControl - . platformSocket - uri localhost' .





const webrtc = new RTC({
	isControl: false,
	platformSocket: config.platformSocket}, 
se);
      
      



Vue.js, . /public. :





Selenium

, Selenium WebDriver + geckodriver headless . , robot-signal-server/selenium/index.js. , . , . /etc/network/if-up.d/ .





Python. - websocket , GPIO. , : [0…+-1, 0…+-1] JSON. .. , , -1 +1 0.01. , - . (. GItHub )





, . production- - , . , . .





3/4/5G , . :












All Articles