From: Jim <ji...@ho...> - 2009-08-11 03:46:43
|
Martin, I know this is an older email, but I saved it for when I had time to tinker with my camera again. Well, I dug it out, and ran into the same problems you have. This is also a question for the list... did the below patches get rolled into the main code base? That is, when I do an svn update today, I get v461. Are these patches present? Thank you Jim -----Original Message----- From: Martin <mar...@gm...> Reply-to: Motion discussion list <mot...@li...> To: mot...@li... Subject: [Motion-user] working pan and tilt functionality of the Logitech Quickcam Orbit/Sphere MP with an up to date kernel (2.6.29) Date: Wed, 20 May 2009 16:44:05 +0200 Hi, this is to all who look for pan and tilt functionality for the Logitech Quickcam Orbit/Sphere MP with an currently up to date kernel (e.g. 2.6.29). I managed to get the pan and tilt functionality of the Logitech Quickcam Orbit/Sphere MP (2006 model) (046d:08cc) to work with an up to date kernel. Since I found a lot of support requests for this problem I want to tell you about my experiences. Note that this might work with other similar cameras that use the uvcvideo driver. I used motion 3.2.11 on Debian Sid with the standard kernel 2.6.29-2-686 which has the uvcvideo-module built in. First I installed libwebcam, but instead of the official release I used the last svn snapshot (from http://svn.quickcamteam.net/svn/qct/Linux) which was revision 23. The README tells to copy or link the files uvcvideo.h and uvc_compat.h into the folder Common/include/. I tried to use the actual version of uvcvideo.h which comes with the kernel-source but compiling failed. The solution is to use the files mentioned in README http://svn.berlios.de/svnroot/repos/linux-uvc/linux-uvc/trunk/uvcvideo.h http://svn.berlios.de/svnroot/repos/linux-uvc/linux-uvc/trunk/uvc_compat.h which are to my believe the newest versions before the driver became a built-in kernel module. This might not be a clean solution but it works and we just use the program to achieve the mapping for the pan and tilt functionality. After successful "make" and "make install" we can call uvcdynctrl -i /etc/udev/data/046d/logitech.xml after loading the uvcvideo module, to map the needed controls. It should reply with "Importing dynamic controls from file /etc/udev/data/046d/logitech.xml." and the command uvcdynctrl -c should now include the commands "Pan/tilt Reset", "Tilt (relative)" and "Pan (relative)" which will be used by motion to pan and tilt the camera. Before compiling motion I adjusted the addresses at the end of motion's "track.h" in order to match with the values in "logitech.xml" as well as in "/usr/include/linux/videodev2.h". I attached the changes in the attached file "trackh_patch3.2.11.diff" which can be used to patch "track.h" with the command patch track.h < trackh_patch3.2.11.diff After this, I set "track_type 5" as well as "control_localhost off" in my motion.conf. Now, my camera somehow reacts on commands coming from the web interface but unfortunately not as desired. When I exclusively pan without tilting or vice versa, the camera often moved along both axes. I did not find any other person also having this problem. So I took a look at the code in track.c which commands the movements and I found out that by making calls to VIDIOC_S_EXT_CTRLS instead of VIDIOC_S_CTRL this problem does not occur. Also it allows faster combined movements of the camera, since pan and tilt commands can be sent simultaneously. The changes I made to track.c can be found in the other attached patch in the file "trackc_patch3.2.11.diff" which is applied by patch track.c < trackc_patch3.2.11.diff Note that for being able to compile motion with ffmpeg-support I also had to apply the patch http://www.lavrsen.dk/foswiki/pub/Motion/ReleaseNoteMotion3x2x11/ffmpeg-0.4.9.15594svn-20081010.diff to the file "ffmpeg.c". I hope this is helpful for somebody and maybe the developers of motion want to take a look at the modifications in "track.c" and take into account merging them into the next revision. Best, Martin plain text document attachment (trackh_patch3.2.11.diff) --- track.h (original) +++ track.h (modified) @@ -122,15 +122,15 @@ #ifdef MOTION_V4L2 #ifndef V4L2_CID_PAN_RELATIVE -#define V4L2_CID_PAN_RELATIVE (V4L2_CID_PRIVATE_BASE+7) +#define V4L2_CID_PAN_RELATIVE 0x009a0904 #endif #ifndef V4L2_CID_TILT_RELATIVE -#define V4L2_CID_TILT_RELATIVE (V4L2_CID_PRIVATE_BASE+8) +#define V4L2_CID_TILT_RELATIVE 0x009a0905 #endif #ifndef V4L2_CID_PANTILT_RESET -#define V4L2_CID_PANTILT_RESET (V4L2_CID_PRIVATE_BASE+9) +#define V4L2_CID_PANTILT_RESET 0x0A046D03 #endif #define INCPANTILT 64 // 1 degree @@ -140,3 +140,4 @@ #endif /* WITHOUT_V4L */ #endif /* _INCLUDE_TRACK_H */ + plain text document attachment (trackc_patch3.2.11.diff) --- track.c (original) +++ track.c (modified) @@ -561,6 +561,8 @@ Logitech QuickCam Sphere camera tracking code by oBi + Modify by Martin Hess(Wuerzburg) 18.05.09 + Modify by Dirk Wesenberg(Munich) 30.03.07 - for new API in uvcvideo - add Trace-steps for investigation @@ -572,30 +574,25 @@ /* CALC ABSOLUTE MOVING : Act.Position +/- delta to request X and Y */ int move_x_degrees = 0, move_y_degrees = 0; - union pantilt { - struct { - short pan; - short tilt; - } s16; - int value; - }; - union pantilt pan; - if (cnt->track.dev == -1) { int reset = 3; //0-non reset, 1-reset pan, 2-reset tilt, 3-reset pan&tilt - struct v4l2_control control_s; + struct v4l2_ext_control xctrls[2]; + struct v4l2_ext_controls ctrls; - control_s.id = V4L2_CID_PANTILT_RESET; - control_s.value = (unsigned char) reset; + //Use VIDIOC_S_EXT_CTRLS for calling pan and tilt changes simultaneously + xctrls[0].id = V4L2_CID_PANTILT_RESET; + xctrls[0].value = (unsigned char) reset; + ctrls.count = 1; + ctrls.controls = xctrls; - if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { + if (ioctl(dev, VIDIOC_S_EXT_CTRLS, &ctrls) < 0) { motion_log(LOG_ERR, 1, "Failed to reset UVC camera to starting position! Reason"); return 0; } motion_log(LOG_DEBUG, 0, "Reseting UVC camera to starting position"); - SLEEP(8, 0) + SLEEP(2, 0) /* Get camera range */ struct v4l2_queryctrl queryctrl; @@ -617,14 +614,12 @@ */ // //get mininum -// pan.value = queryctrl.minimum; - cnt->track.panmin = -4480 / INCPANTILT; cnt->track.tiltmin = -1920 / INCPANTILT; // //get maximum cnt->track.panmax = 4480 / INCPANTILT; cnt->track.tiltmax = 1920 / INCPANTILT; -// pan.value = queryctrl.maximum; + cnt->track.dev = dev; cnt->track.pan_angle = 0; @@ -633,7 +628,8 @@ } - struct v4l2_control control_s; + struct v4l2_ext_control xctrls[2]; + struct v4l2_ext_controls ctrls; motion_log(LOG_DEBUG, 0, "INPUT_PARAM_ABS pan_min %d,pan_max %d,tilt_min %d,tilt_max %d ", cnt->track.panmin, cnt->track.panmax, cnt->track.tiltmin, cnt->track.tiltmax ); @@ -652,8 +648,6 @@ pan left: - value pan right: + value */ - pan.s16.pan = -move_x_degrees * INCPANTILT; - pan.s16.tilt = -move_y_degrees * INCPANTILT; motion_log(LOG_DEBUG, 0, "For_SET_ABS move_X %d,move_Y %d", move_x_degrees, move_y_degrees); @@ -662,31 +656,19 @@ - The Webcam or uvcvideo does not like a call with a zero-move */ - if (move_x_degrees != 0) { - control_s.id = V4L2_CID_PAN_RELATIVE; - // control_s.value = pan.value; - control_s.value = pan.s16.pan; - if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(LOG_ERR, 1, "Failed to move UVC camera!"); - return 0; - } + //Use VIDIOC_S_EXT_CTRLS for calling pan and tilt changes simultaneously + xctrls[0].id = V4L2_CID_PAN_RELATIVE; + xctrls[0].value = -move_x_degrees * INCPANTILT; + xctrls[1].id = V4L2_CID_TILT_RELATIVE; + xctrls[1].value = -move_y_degrees * INCPANTILT; + ctrls.count = 2; + ctrls.controls = xctrls; + + if (ioctl(dev, VIDIOC_S_EXT_CTRLS, &ctrls) < 0) { + motion_log(LOG_ERR, 1, "Failed to move UVC camera!"); + return 0; } - /* DWe 30.03.07 We must wait a little,before we set the next CMD, otherwise PAN is mad ... */ - if ((move_x_degrees != 0) && (move_y_degrees != 0)) - SLEEP (1,0); - - - if (move_y_degrees != 0) { - control_s.id = V4L2_CID_TILT_RELATIVE; - // control_s.value = pan.value; - control_s.value = pan.s16.tilt; - if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(LOG_ERR, 1, "Failed to move UVC camera!"); - return 0; - } - - } motion_log(LOG_DEBUG, 0,"Found MINMAX = %d", cnt->track.minmaxfound); @@ -721,12 +703,16 @@ /* PAN Value 7777 in relative will init also a want reset for CAM - it will be "0" after that */ if ((cnt->track.minmaxfound != 1) || (cent->x == 7777)) { unsigned short int reset = 3; //0-non reset, 1-reset pan, 2-reset tilt, 3-reset pan&tilt - struct v4l2_control control_s; + struct v4l2_ext_control xctrls[2]; + struct v4l2_ext_controls ctrls; - control_s.id = V4L2_CID_PANTILT_RESET; - control_s.value = (unsigned char) reset; + //Use VIDIOC_S_EXT_CTRLS for calling pan and tilt changes simultaneously + xctrls[0].id = V4L2_CID_PANTILT_RESET; + xctrls[0].value = (unsigned char) reset; + ctrls.count = 1; + ctrls.controls = xctrls; - if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { + if (ioctl(dev, VIDIOC_S_EXT_CTRLS, &ctrls) < 0) { motion_log(LOG_ERR, 1, "Failed to reset UVC camera to starting position! Reason"); return 0; } @@ -735,7 +721,7 @@ /* set the "helpvalue" back to null because after reset CAM should be in x=0 and not 70 */ cent->x = 0; - SLEEP(8,0); + SLEEP(2,0); /* DWe 30.03.07 The orig request failed : * must be VIDIOC_G_CTRL separate for pan and tilt or via VIDIOC_G_EXT_CTRLS - now for 1st manual @@ -768,16 +754,8 @@ move_y_degrees = cent->y; } - union pantilt { - struct { - short pan; - short tilt; - } s16; - int value; - }; - - struct v4l2_control control_s; - union pantilt pan; + struct v4l2_ext_control xctrls[2]; + struct v4l2_ext_controls ctrls; if (cnt->track.minmaxfound == 1) { /* Check current position of camera and see if we need to adjust @@ -809,45 +787,23 @@ pan right: + value */ - pan.s16.pan = -move_x_degrees * INCPANTILT; - pan.s16.tilt = -move_y_degrees * INCPANTILT; - + /* DWe 30.03.07 Must be broken in diff calls, because - one call for both is not accept via VIDIOC_S_CTRL -> maybe via VIDIOC_S_EXT_CTRLS - The Webcam or uvcvideo does not like a call with a zero-move */ - if (move_x_degrees != 0) { - - control_s.id = V4L2_CID_PAN_RELATIVE; - - control_s.value = pan.s16.pan; - motion_log(LOG_DEBUG, 0," dev %d,addr= %d, control_S= %d,Wert= %d,", - dev,VIDIOC_S_CTRL, &control_s, pan.s16.pan ); - - if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(LOG_ERR, 1, "Failed to move UVC camera!"); - return 0; - } - } - - /* DWe 30.03.07 We must wait a little,before we set the next CMD, otherwise PAN is mad ... */ - if ((move_x_degrees != 0) && (move_y_degrees != 0)) - SLEEP (1,0); - - - - if (move_y_degrees != 0) { - - control_s.id = V4L2_CID_TILT_RELATIVE; - control_s.value = pan.s16.tilt; - motion_log(LOG_DEBUG, 0," dev %d,addr= %d, control_S= %d, Wert= %d, ", - dev,VIDIOC_S_CTRL, &control_s, pan.s16.tilt); - - if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(LOG_ERR, 1, "Failed to move UVC camera!"); - return 0; - } + //Use VIDIOC_S_EXT_CTRLS for calling pan and tilt changes simultaneously + xctrls[0].id = V4L2_CID_PAN_RELATIVE; + xctrls[0].value = -move_x_degrees * INCPANTILT; + xctrls[1].id = V4L2_CID_TILT_RELATIVE; + xctrls[1].value = -move_y_degrees * INCPANTILT; + ctrls.count = 2; + ctrls.controls = xctrls; + + if (ioctl(dev, VIDIOC_S_EXT_CTRLS, &ctrls) < 0) { + motion_log(LOG_ERR, 1, "Failed to move UVC camera!"); + return 0; } @@ -858,10 +814,10 @@ cnt->track.pan_angle, cnt->track.tilt_angle); if (move_x_degrees != 0) - cnt->track.pan_angle += -pan.s16.pan / INCPANTILT; + cnt->track.pan_angle += move_x_degrees; if (move_y_degrees != 0) - cnt->track.tilt_angle += -pan.s16.tilt / INCPANTILT; + cnt->track.tilt_angle += move_y_degrees; motion_log(LOG_DEBUG, 0," After_REL_Y_Angel : x= %d , Y= %d", cnt->track.pan_angle, cnt->track.tilt_angle); @@ -871,3 +827,4 @@ } #endif /* MOTION_V4L2 */ #endif /* WITHOUT_V4L */ + ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ Motion-user mailing list Mot...@li... https://lists.sourceforge.net/lists/listinfo/motion-user http://www.lavrsen.dk/twiki/bin/view/Motion/WebHome |