Here is easy way to work with Kinect's motor, through OpenNI. No other
drivers or libraries is required.
The code is following:
// OpenNI includes
#include <XnUSB.h>
// Standard includes
#include <stdio.h>
#include <time.h>
/**
* Class to control Kinect's motor.
*/
class KinectMotor
{
public:
KinectMotor();
virtual ~KinectMotor();
/**
* Open device.
* @return true if succeeded, false - overwise
*/
bool Open();
/**
* Close device.
*/
void Close();
/**
* Move motor up or down to specified angle value.
* @param angle angle value
* @return true if succeeded, false - overwise
*/
bool Move(int angle);
private:
XN_USB_DEV_HANDLE m_dev;
bool m_isOpen;
};
KinectMotor::KinectMotor()
{
m_isOpen = false;
}
KinectMotor::~KinectMotor()
{
Close();
}
bool KinectMotor::Open()
{
const XnUSBConnectionString *paths;
XnUInt32 count;
XnStatus res;
// Init OpenNI USB
res = xnUSBInit();
if (res != XN_STATUS_OK) {
xnPrintError(res, "xnUSBInit failed");
return false;
}
// Open "Kinect motor" USB device
res = xnUSBEnumerateDevices(0x045E /* VendorID */, 0x02B0 /*ProductID
*/, &paths, &count);
if (res != XN_STATUS_OK) {
xnPrintError(res, "xnUSBEnumerateDevices failed");
return false;
}
// Open first found device
res = xnUSBOpenDeviceByPath(paths[0], &m_dev);
if (res != XN_STATUS_OK) {
xnPrintError(res, "xnUSBOpenDeviceByPath failed");
return false;
}
XnUChar buf[1]; // output buffer
// Init motor
res = xnUSBSendControl(m_dev, (XnUSBControlType) 0xc0, 0x10, 0x00,
0x00, buf, sizeof(buf), 0);
if (res != XN_STATUS_OK) {
xnPrintError(res, "xnUSBSendControl failed");
Close();
return false;
}
res = xnUSBSendControl(m_dev,
XnUSBControlType::XN_USB_CONTROL_TYPE_VENDOR, 0x06, 0x01, 0x00, NULL,
0, 0);
if (res != XN_STATUS_OK) {
xnPrintError(res, "xnUSBSendControl failed");
Close();
return false;
}
return true;
}
void KinectMotor::Close()
{
if (m_isOpen) {
xnUSBCloseDevice(m_dev);
m_isOpen = false;
}
}
bool KinectMotor::Move(int angle)
{
XnStatus res;
// Send move control request
res = xnUSBSendControl(m_dev, XN_USB_CONTROL_TYPE_VENDOR, 0x31,
angle, 0x00, NULL, 0, 0);
if (res != XN_STATUS_OK) {
xnPrintError(res, "xnUSBSendControl failed");
return false;
}
return true;
}
int main(int argc, char *argv[])
{
KinectMotor motor;
if (!motor.Open()) // Open motor device
return 1;
motor.Move(31); // move it up to 31 degree
Sleep(1000);
motor.Move(-31); // move it down to 31 degree
Sleep(1000);
motor.Move(0);
return 0;
}
AND, Is there any way to control the led State??
> }- 隐藏被引用文字 -
>
> - 显示引用的文字 -
A stupid question, have you tried it while grabbing images? No USB
resources conflicts? Since the motor is a different usb device I
expect it to work, but if you can already confirm it would be great!
Cheers,
Nicolas
> --
> You received this message because you are subscribed to the Google Groups "OpenNI" group.
> To post to this group, send email to openn...@googlegroups.com.
> To unsubscribe from this group, send email to openni-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/openni-dev?hl=en.
>
> > For more options, visit this group athttp://groups.google.com/group/openni-dev?hl=en.- 隐藏被引用文字 -
>
> - 显示引用的文字 -
On 14 дек, 14:02, Nicolas Burrus <nicolas.bur...@gmail.com> wrote:
> Thanks for sharing this!
>
> A stupid question, have you tried it while grabbing images? No USB
> resources conflicts? Since the motor is a different usb device I
> expect it to work, but if you can already confirm it would be great!
>
I tried it, when grabbing image - it works well. :-)
Not tried with depth, and skeleton tracking, but i think, it will work
fine.
Best regards ,Crash.
This method is example of using features, already implemented in
OpenNI.
And it doesn't need openfreenect or any other software.
led controlled the same way - sending USB control request through
OpenNI USB driver.
I need just a few lines of code.
Best regards.
My configuration:
OpenNI-Bin-Dev-Linux-x64-v1.4.0.2
Sensor-Bin-Linux-x64-v5.0.5.1_avin2
nite-bin-linux-x64-v1.5.0.2
What I get, when I start the test Program:
"xnUSBSendControl failed: Wrong USB control type requested!"
Can someone please tell my, what is wrong here?
I use OpenNI 1.3.2.3 on Windows 7.
It can be caused by changes in ps3drv USB driver, in your version of
OpenNI.
Best regards,
I've chosen a combination of freenect and OpenNI/NITE/Avin2-driver to
be able to control the motor and still being able to create programs
using OpenNI & NITE.
Since I only need the motor control to calibrate my kinect before
demos or presentations of my application, the freenect-glview sample
is just fine for me. :)
KR
rumppat
--
You received this message because you are subscribed to the Google Groups "OpenNI" group.
To view this discussion on the web visit https://groups.google.com/d/msg/openni-dev/-/m_Fuk7VusvwJ.
--
You received this message because you are subscribed to the Google Groups "OpenNI" group.
--
You received this message because you are subscribed to the Google Groups "OpenNI" group.
To post to this group, send email to openn...@googlegroups.com.
To unsubscribe from this group, send email to openni-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/openni-dev?hl=en.
Is there any way to control the motor in linux?
Thanks, really appreciate your help
> --
> You received this message because you are subscribed to the Google Groups "OpenNI" group.
Hello all,Here is easy way to work with Kinect's motor, through OpenNI. No other
drivers or libraries is required.The code is following:
// OpenNI includes
#include <XnUSB.h>// Standard includes
#include <stdio.h>
#include <time.h>/**
* Class to control Kinect's motor.
*/
class KinectMotor
{
public:
KinectMotor();
virtual ~KinectMotor();/**
* Open device.
* @return true if succeeded, false - overwise
*/
bool Open();/**
* Close device.
*/
void Close();/**
* Move motor up or down to specified angle value.
* @param angle angle value
* @return true if succeeded, false - overwise
*/
bool Move(int angle);private:
XN_USB_DEV_HANDLE m_dev;
bool m_isOpen;
};KinectMotor::KinectMotor()
{
m_isOpen = false;
}KinectMotor::~KinectMotor()
{
Close();
}bool KinectMotor::Open()
{
const XnUSBConnectionString *paths;
XnUInt32 count;
XnStatus res;// Init OpenNI USB
res = xnUSBInit();
if (res != XN_STATUS_OK) {
xnPrintError(res, "xnUSBInit failed");
return false;
}// Open "Kinect motor" USB device
res = xnUSBEnumerateDevices(0x045E /* VendorID */, 0x02B0 /*ProductID
*/, &paths, &count);
if (res != XN_STATUS_OK) {
xnPrintError(res, "xnUSBEnumerateDevices failed");
return false;
}// Open first found device
res = xnUSBOpenDeviceByPath(paths[0], &m_dev);
if (res != XN_STATUS_OK) {
xnPrintError(res, "xnUSBOpenDeviceByPath failed");
return false;
}XnUChar buf[1]; // output buffer
// Init motor
res = xnUSBSendControl(m_dev, (XnUSBControlType) 0xc0, 0x10, 0x00,
0x00, buf, sizeof(buf), 0);
if (res != XN_STATUS_OK) {
xnPrintError(res, "xnUSBSendControl failed");
Close();
return false;
}res = xnUSBSendControl(m_dev,
XnUSBControlType::XN_USB_CONTROL_TYPE_VENDOR, 0x06, 0x01, 0x00, NULL,
0, 0);
if (res != XN_STATUS_OK) {
xnPrintError(res, "xnUSBSendControl failed");
Close();
return false;
}
return true;
}void KinectMotor::Close()
{
if (m_isOpen) {
xnUSBCloseDevice(m_dev);
m_isOpen = false;
}
}bool KinectMotor::Move(int angle)
{
XnStatus res;// Send move control request
res = xnUSBSendControl(m_dev, XN_USB_CONTROL_TYPE_VENDOR, 0x31,
angle, 0x00, NULL, 0, 0);
if (res != XN_STATUS_OK) {
xnPrintError(res, "xnUSBSendControl failed");
return false;
}
return true;
}int main(int argc, char *argv[])
{
KinectMotor motor;if (!motor.Open()) // Open motor device
return 1;motor.Move(31); // move it up to 31 degree
Sleep(1000);motor.Move(-31); // move it down to 31 degree
Sleep(1000);motor.Move(0);
return 0;
}