📜 ⬆️ ⬇️

If you have no money for AXIS, or a webcam with your own, moderately curved, hands

When I first saw the video broadcast from a managed webcam on the 13th floor of Moscow State University, I was very impressed. So much so that I wanted to arrange something similar. I do not have extra money for cameras like AXIS 214PTZ, so I had to leave this idea for some time. Until I found out about the Arduino and the fact that you can attach a “network card” and motors to it. The necessary components were quickly acquired and I had everything available for the construction of a full-fledged, web-based webcam.

The study of the Internet has shown that the idea of ​​attaching a camera to the servers comes first to all the happy owners of arduine and servos. However, none of the already implemented control schemes (buttons, PS / 2 mouse, from a controlled router, from a computer, from a webpage on the server built into the arduin) did not impress me, for it was inconvenient, IMHO. I wanted something universal so that you can lay out the web interface on the site and manage it.

As a result, such a thing appeared:


A regular Logitech Pro 9000 webcam (won a long time ago in Computerra) is attached to the servo No. 1 rocking chair (Y-axis). Servo number 1, in turn, is attached to the rocking chair of serf No. 2 (X axis). And the server number 2 is pretty tightly screwed to the base - a heavy wooden bar. Serva - the most simple and cheap SRM-102 (about 400 rubles per piece).
')
That's the whole design, everything is elementary. For the joints, we used strips from the children's designer (remember, such old Soviet metal constructors? They are still on sale).

The controller of all this disgrace consists of a bundle of Arduino (more precisely, Freeduino 2009) and Ethernet Shield v2. Also nothing complicated.

Invented an approximate control scheme. The script in the web interface receives commands (keystrokes, mouse movements, etc.) and in a certain format writes them to the database. Arduin cyclically makes a GET request to a script on the server and the script issues all commands from the database, after which the database is cleared. Maybe you can make a prettier one, but for now, everything suits me.

On my server, MySQL is spinning, the HEAP database (so that it is more bright). The structure is as follows:

CREATE TABLE `servo` (
`id` smallint(6) NOT NULL AUTO_INCREMENT,
`cam_id` tinyint(4) NOT NULL,
`action` varchar(20) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `cam_id` (`cam_id`)
) ENGINE=MEMORY DEFAULT CHARSET=cp1251 AUTO_INCREMENT=1 ;


Next come the scripts. The first, most important, sketch for Sobssno Arduiny. The sketch is not really licked, so it can be improved for sure. But, since it works stably, it suits me so far. I don’t explain how to fill in a sketch, because if you are familiar with Arduino, you already know this. I use IDE Arduino 18, so the sketch is for it. The new version of IDE probably will not start!

File servowebclient.pde

Gulf sketch to Arduin and sticking the power cable, half the case is done. Arduin is online and polls the necessary script, longing to work out the commands received. But teams have to come from somewhere. To do this, use the following scripts.

index.php - sobssno, a page with a web-based camera control interface.
set.php - asynchronously called from index.php and writes necessary commands for camera movement to the database
get.php - the script is called remotely by Arduina, reads commands from the database and displays their plain text

These files, and in general the entire structure of the webmordial catalog can be taken here in the archive. serva.rar
Used libraries for Arduiny here - libs.rar

In principle, everything. I hope that now all those who called me a megamind will relax and say “yes, every fool can” :-)

Of course, there is something to work on. Some kind of authorization is needed so that the camera is not shmonally horrible. I deliberately lay out as it is to demonstrate the basic features, elementary details of management.

The control logic is perfectly programmed in Javascript in the main index.php file. Since the MakeAction function is responsible for placing commands, you can do anything with it. For example, on the webmord there are links like "Fixed points - Balcony". This is the usual call to this MakeAction itself (11, coordinate_x, coordinate_y), i.e. where the camera should be sent. And so you can program any movement. But we must not forget that in this way it is possible to zasrat the queue of teams for the most undesirable. For example, I had a left-to-right Javascript function. Which in the cycle changed the coordinate of X, as a result, the camera cyclically drove back and forth. And if someone had this function turned on in the browser, it was impossible to stop it until the one who turned it on turned it off. A temporary solution was to set a timer to load another file through jQuery, which forcibly killed that timer. It's ugly, but it worked.

In general, I just wanted to tell you about a rather beautiful opportunity to make a good managed webcam and show how it works. After that, someone else, like fantasy, will play out, because in the same way you can control anything and everything.

Now a little about the testing process, because I just have to tell about it.

I first turned on this camera a couple of days ago. I launched a broadcast, posted a link to a web interface in my blog. A dozen people drove her a bit and piled. The next day I dragged the camera at work, put it in the office where our girls are sitting. The camera spun almost constantly. The girl passes through the office, and the camera moves synchronously behind her, the people did not let the aisle go :-) In addition, we have a parrot Pitrovich living in the office, who at first had a wildly disliked camera and constantly attacked her. By the way, this infection gnawed the power cable from the laptop and the wires to the serv. Many thanks to the girls - they courageously suffered the whole working day under the tireless eye of the camera. And constantly attracted new testers :-)



I tried to place the description of the camera here on Habré, but because of the small but very positive karma I could not do it. Well, no matter how, though you burst. Desperate, I posted a question in Q & A. As a result, I was filled with karma in full, much more than was required to accommodate the topic. For that, once again, thanks guys. The people with Habra really liked (judging by the comments) my control implementation, so the camera at the moment almost nine hours is continuously spinning (taken from the statistics of the broadcast on watch.com). Serva cold, not warm nifiga. Arduin is slightly lukewarm. For all this time there was only one glitch - the Arduin lost the grid. As it turned out, "I had a cliff" (c) Anton Uralsky

There were still glitches associated with the included very long reproduction of the trained movements (someone cut in the training, drove the mouse for a long time and then pressed Play), so I restricted this mode to a hundred commands. Of course, this restriction is easy to manage :-)

Tomorrow I have a working day, I will turn off the camera for the night, but I will turn it on again in the morning at work. There will be even more fun.

UPD> The first construction (on a wooden bar) turned out to be not very stable - we managed to knock it over several times, sharply jerking the camera from side to side. So there was a new modification - Serv â„–2 bolted to a small wooden sticks. A hole is drilled in the box, just under the diameter of the screw on a standard fixture from a tripod. Well, the bar is riveted to a tripod from an ordinary camera. The design turned out to be mega-reliable - the people have been trying hard to overthrow it for 7 hours, but it does not work.

In addition, a second one was installed next to the main camera (exactly the same Logitech, but stationary), through which it was possible to observe how the first one thrashes. Very fascinating show, to be honest.



Surprisingly fast, the reaction of the camera was obtained - the delay in relation to the control in the web-snatch is (for me, in any case) a split second. Although I sit at home, and the server is at work and between us is the usual Corbino / Beeline Internet. Video broadcast on smotri.com slows down, but it is not always.

Well, then a few photos of the camera and a few videos for clarity of design.











Several demo videos (video is not inserted something, so just give links):
www.youtube.com/watch?v=diEv3LS1nWg
www.youtube.com/watch?v=JEpCG5_nl1s
www.youtube.com/watch?v=t6cCTCtWCqg

By the way, daughter loves this toy. True, it does not matter, the camera is there or something else. The main thing that moves www.youtube.com/watch?v=dEOh0asfVJ0

And here, of course, is the controller. Sandwich from Freeduino and Ethernet Shield


Finally



God, give forces to my server to sustain Habraeffekt when the topic is published. And do not let the camera die in the very dawn of the forces.

PS I checked the work in Opera 10.63 and in fresh Chrome. The remaining browsers should theoretically cope too.

PPS Taking this opportunity, I want to say hello to the SysCat habrauser , who once gave me my first Arduin with my e-shild, and thereby encouraged me to do a lot of interesting research.

UPD> I forgot the most important thing - a working web interface here www.g0l.ru/test/serva
Please treat with understanding - the camera and servos are not rubber, so do not pull if it is already moving. I'll leave it on until morning, then I'll take it with me to work and turn it on there.

UPD> Made control through a web interface, but with a gamepad. Need a softphone such as Joy2Key , for mapping gamepad buttons on keyboard buttons. If you assign the buttons up-left-down-right on the keyboard WASD, you can control it from the gamepad. The regular keyboard buttons also work.

Source: https://habr.com/ru/post/108058/


All Articles