ilchiodo - 2014-03-22

Hello everyone.

I made a mobile camera mount for my webcam with the NXT. Everything's working fine, but the motor control is somehow jerky. The motion is not continuous: the motors stop and go instead of keeping a steady velocity.

Let me post my snippet:

void driveNXT(Comm::NXTComm *com1, Mat frame, Point obj_center){

int distance_x= frame.cols/2-obj_center.x;
int distance_y= frame.rows/2-obj_center.y;
NXT::KeepAlive(com1);

if (distance_x >0)  //proportional control for the camera position
    NXT::Motor::SetForward(com1, OUT_A, abs(distance_x)*0.05);
else NXT::Motor::SetReverse(com1, OUT_A, abs(distance_x)*0.05);

if (distance_y <0)
    NXT::Motor::SetReverse(com1, OUT_B, abs(distance_y)*0.1);
else NXT::Motor::SetForward(com1, OUT_B, abs(distance_y)*0.1);  
return;
}

Point is a OpenCV object, containing an x and y coordinate. The function is called continuously, as the main program detects and tracks objects into the camera field. The motors, though, run for a split second and then stop, and then run again. The robot manages to follow the tracked objects, but this is not the control I'd like to obtain.
Is there any possible fix for this?

Thanks a lot
chiodo