At the forefront of Artificial Intelligence
  Home Articles Reviews Interviews JDK Glossary Features Discussion Search
Home » Articles » Robotics » LEGO Mindstorms

Programming with the LEGO Cam

When I started playing with Vision Command, I wanted to use my power stand to pivot the LEGO Cam without having to use the Vision Command interface. The QuickCam software didn't support the RCX, so I thought I'd write a program myself.

If you didn't know, the LEGO Cam is simply a Logitech QuickCam - so programming for the LEGO Cam is insanely easy. Simply download the Logitech QuickCam SDK and it will install all the necessary files, examples, redistributables (the majority of the download, unfortunately) and a lot of great documentation. The SDK can be downloaded here (about 9Mb download). Once you've installed it and rebooted your system, you'll immediately be able to develop for the QuickCam.

Programming the LEGO Cam in VC++

This tutorial will look at developing in Visual C++, but anybody familiar with component programming should be able to follow. Add the QuickCam component to your Visual C++ project - the component is called "VideoPortal". If you do not know how to add a component to your VC++ project, see the Using spirit.ocx in Visual C++ AISolutions article.

Now, in your main dialog (or equivalent) add a VideoPortal control. This is done easily in the Visual C++ dialog editor, since a QuickCam icon will be added to the "Controls" toolbar. Next open up ClassWizard and add a member variable called "m_cVideo" to your dialog associated with your VideoPortal control. Finally, in your OnInitDialog (or equivalent) function add something like:

// Prepare the control and registry settings
if (!m_cVideo.PrepareControl("PivotVC",
    "HKEY_CURRENT_USER\\Software\\Logitech\\PivotVC", 0 )) {
  AfxMessageBox("Error message");
  EndDialog(-1);
}

m_cVideo.ConnectCamera2();        // Restore camera settings

m_cVideo.SetPreviewMaxWidth(320); // Set maximum width
m_cVideo.SetPreviewMaxHeight(240);// Set maximum height

m_cVideo.SetEnablePreview(TRUE);  // Turn on the preview
The Logitech documentation is excellent, so you should be able to understand the functions by looking them up in the MFC reference document. It is impressive just how little code is required to get a fully functional camera working within your program. Below is a screenshot of my resultant program - it allowed me to take power the stand, and with a little modification allowed me to drive around. Here you can see the rover I built staring at our CyeSR robot.

Note that I didn't want the Logitech camera options to be present in my camera window, but they would be very easy to add, as would video and picture-taking facilities. Take a look at these functions for good pointers:
  • PictureToFile
  • PictureToMemory
  • StartMovieRecording
  • StopMovieRecording
  • EnableUIElements
It is also possible to process the video stream in real-time. Good examples of this are the Vision Commands region overlay and the Logitech Vidbert example. We'll hopefully cover this soon.

Submitted: 20/02/2001

Article content copyright © James Matthews, 2001.
 Article Toolbar
Print
BibTeX entry

Search

Latest News
- Generation5 10-year Anniversary (03/09/2008)
- New Generation5 Design! (09/04/2007)
- Happy New Year 2007 (02/01/2007)
- Where has Generation5 Gone?! (04/11/2005)
- NeuroEvolving Robotic Operatives (NERO) (25/06/2005)

What's New?
- Back-propagation using the Generation5 JDK (07/04/2008)
- Hough Transforms (02/01/2008)
- Kohonen-based Image Analysis using the Generation5 JDK (11/12/2007)
- Modelling Bacterium using the JDK (19/03/2007)
- Modelling Bacterium using the JDK (19/03/2007)


All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -