Libusb and linux: controltransfer

hello folks.

I’ve been struggeling with a code to put my servo into a new position and the final (and working) edition is the following code:

void setServoPos(libusb_device *device, int position, int servo)
{
	libusb_device_handle *device_handle;
	libusb_open(device, &device_handle);
	libusb_control_transfer(device_handle, 0x40, REQUEST_SET_TARGET, position*4, servo, 0, 0, (ushort)5000);	
	libusb_close(device_handle);
}

Now this works very well, but I wanted to also be able to set the speed and the acceleration. I stated out with the speed like this:

void setServoSpeed(libusb_device *device, int speed, int servo)
{
	libusb_device_handle *device_handle;
	libusb_open(device, &device_handle);
	libusb_control_transfer(device_handle, 0x40, COMMAND_SET_SPEED, speed, servo, 0, 0, (ushort)5000);
	libusb_close(device_handle);
}

Now this dosn’t seem to work very well. And I cant tell why.

Any help on setting the speed with libusb is very welcome :slight_smile:

I’m also looking for a solution on the “give feedback once the operation is finished” (aka GET_MOVING_STATE in scripting language)

my goal is to totally avoid the usbwrapper because I’m building a lightweight controller for my panorama camera. (servos for the x/y coordinates and usb-ptp for picture control)

Hello.

You should let us know what product you have when asking for help. I’m going to assume it is a Maestro servo controller.

The COMMAND_SET_SPEED is the command byte for the serial command. You want to use the native USB command, which is REQUEST_SET_SERVO_VARIABLE. You should look in Usc.cs in the Pololu USB SDK to see what the right parameters are for that command.

We don’t have a native USB command that returns the moving state as a single byte, but you can use the REQUEST_GET_VARIABLES command and compare each servo’s position to its target. If the two are equal, then the servo is done moving.

–David

try
libusb_control_transfer(device_handle, 0x40, REQUEST_SET_SERVO_VARIABLE, %insert speed value here%, servo, 0, 0, (ushort)5000);