GRYNX

18th of October, 2005

Build your own Robotic WebCam

by @ 21:18. Filed under Uncategorized

Software



Where: webserver

Purpose: opens a socket and sends command to listener running on PC

Language: PHP

if (isSet($dir))
{
	$fp = fsockopen ("YOUR.IP.ADDR", 443, &$errno, &$errstr, 30);
	if (!$fp)
		die ($errstr);

	fputs ($fp, $dir);
	fclose ($fp);
}

Where: PC

Purpose: listens for incoming commands from PHP script and executes VBS scripts

Language: C++

#include "stdafx.h"
#include "afxsock.h"

CWinApp theApp;
using namespace std;

void failure (char *err)
{
	AfxMessageBox (err);
	exit (-1);
}

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
		failure ("Unable to init MFC!");

	// initialize sockets
	if (!AfxSocketInit ())
		failure ("Unable to init Winsock!");

	CSocket in;
	if (!in.Create (443))
		failure ("Unable to init Socket!");

	in.Listen (5);

	while (1)
	{
		// blocks until connection received
		CSocket newconn;
		BOOL rc = in.Accept (newconn);
		if (!rc)
		{
			printf ("ACCEPT ERROR!n");
			continue;
		}

		struct tm *newtime;
		time_t aclock;

		time( &aclock );                 /* Get time in seconds */
		newtime = localtime( &aclock );  /* Convert time to struct */

		// get one byte
		char buf;
		int num_received = newconn.Receive (&buf, 1);

		newconn.Close ();

		if (num_received)
		{
			cout << asctime( newtime );

			switch (buf)
			{
				case 'R':
					printf ("RIGHT!n");
					system ("RIGHT.vbs");
					break;
				case 'L':
					printf ("LEFT!n");
					system ("LEFT.vbs");
					break;
				case 'C':
					printf ("CENTER!n");
					system ("CENTER.vbs");
					break;

				default:
					printf ("ERROR!n");
					break;
			}
		}
	}

	in.Close ();

	return 0;
}

Where: PC

Purpose: send signal “L”, “C”, or “R” on COM2 serial port

Language: Visual Basic Script (.vbs) (Why VBS? Because I couldn’t figure out how to do it in Win32.)

' CENTER.vbs
Set com = CreateObject ("MSCommLib.MSComm")
com.CommPort = 2
com.Settings = "9600,N,8,1"
com.PortOpen = True
com.Output = "C"
com.PortOpen = False

' LEFT.vbs
Set com = CreateObject ("MSCommLib.MSComm")
com.CommPort = 2
com.Settings = "9600,N,8,1"
com.PortOpen = True
com.Output = "L"
com.PortOpen = False

' RIGHT.vbs
Set com = CreateObject ("MSCommLib.MSComm")
com.CommPort = 2
com.Settings = "9600,N,8,1"
com.PortOpen = True
com.Output = "R"
com.PortOpen = False

Where: Parallax Basic Stamp 2

Purpose: sends pulse signal to servo motor according to received signal from serial port

Language: Parallax Basic

counter var     byte
revolveWait     con     30
letter var byte

counter =       0

read_input:
        ' get some data on pin 10
        serin 10, 16468,[letter]

        if letter = "L" then start_left
        if letter = "R" then start_right
        if letter = "C" then start_center

'START LEFT ROTATION
start_left
        counter = 0

left:
        pulsout 4,1500
        pause 20

        counter = counter + 1

        if counter > revolveWait then read_input
        goto left

'START RIGHT ROTATION
start_right:
        counter = 0

right:
        pulsout 4,1
        pause 20

        counter = counter + 1

        if counter > revolveWait then read_input
        goto right

'CENTER SERVO
start_center:
        counter = 0

center:
        pulsout 4,600
        pause 20

        counter = counter + 1

        if counter > revolveWait then read_input
        goto center


Return to the projects index page


This page has been reposted with permission of Jawed, (c) 2005 Jawed.
The original article can be found here.

2 Responses to “Build your own Robotic WebCam”

  1. moath Says:

    hi,
    i want to know how i can make the c++ program and the vb program executable

  2. zaid Says:

    hi all , plz i want the c++ code for the webcam becouse i want to use it in a robotic project , so if you can help me with this , plz send the code to my E-mail: ( the_bad_killer@hotmail.com )

    hope to c your rely

    thx

    zaid ghanem

Leave a Reply

Host your project

Write for Grynx:

Do you have what it takes? If you're the right person then email us.

Archives:

Support Grynx:

Help us continue our work with a donation

Website promotion SEO Managed Advertising

5 Most popular articles:

Google

Categories:

Do it yourself - DIY
Our projects collection

40 queries. 0.444 seconds

Home