Products for USB Sensing and Control
It is currently Fri May 24, 2013 6:32 am

All times are UTC - 7 hours [ DST ]




Post new topic Reply to topic  [ 38 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: Wed Jan 23, 2008 3:18 pm 
Offline
Phidgetly

Joined: Wed Jan 23, 2008 2:07 pm
Posts: 15
Location: UK
Hi,

I'm working on the small project and I wanted to control one or two servos from my Asus 500g wireless router. It has mips Broadcom BCM4704 CPU, 4 ethernet ports and 2 USB. I'm running dd-wrt firmware on it, which is basically a Linux, kernel 2.4.34, with all goodies like ssh, samba, openvpn etc.
On my second linux, standard PC with Fedora (kernel 2.6) I've installed cross-compiler so I can produce binary for the mips.
I have 4 Motor PhidgetServo Kit and it is running perfectly OK on my PC linux box. I can connect it to usb port (uhci_hcd), run test program which basically calls setMotorPosition in a loop going from -23 to 231 doing getMotorPosition to confirm the position and usleep, more or less something like that:
Code:
for (i = -23; i < 231; i += step) { 
    ret = CPhidgetServo_setMotorPosition(servo, 0, i);
        ... if ret != OK print error ...
    ret = CPhidgetServo_getMotorPosition(servo, 0, &cur);
        ... if ret != OK print error ...
     printf("Current position is: %f, %f\n, i, cur);
     usleep(20000);
}

This way I can rotate servo smoothly full 180 degrees, when connected to my PC Linux, it's perfectly fine.
I've got libphidgets (ver 2.1.2) and my software compiled for mips.
When I attach servo to the Asus (uhci module and usbfs mounted in /proc/bus/usb) and run my program, the servo is moving, but very unpredictable. I mean, I can control in which direction in rotates, but I cannot get full control over the rotation and it is far from being smooth. If I go from -23 to 231 the servo eventually will do almost 180 degree but it will move quickly couple of degrees, then stop, 'shake' for a while, then rotate another couple of degrees etc. If I didn't know that the motor is OK I would think that it is broken.
If I try to run setMotorPosition once then it won't move at all.
setMotorPosition never returns an error, but getMotorPosition very often
returns
9: Value is Unknown (State not yet received from device).
When it doesn't return the error it returns zero or -23 even if the servo is in different position. On some rare ocassion it returns the real position.
This is a part of the output, first is the position I try to set, and the second value is obtained by calling getMotorPosition (see pseudo code above, step = 0.1)
    Current position is 60.700000 0.000000
    Current position is 60.800000 0.000000
    9: Value is Unknown (State not yet received from device).
    Current position is 60.800000 0.000000
    Current position is 60.900000 0.000000
    Current position is 60.900000 -23.000000
    ...
    Current position is 79.700000 -23.000000
    Current position is 79.700000 79.550000
    Current position is 79.800000 79.550000
    Current position is 79.800000 79.550000
    Current position is 79.900000 79.550000

I have enabled
CPhidget_enableLogging(6, "./phidgetlog.txt"), but nothing interesting there.
I'm stuck and have no idea what's wrong.
I've finished writing the software, it is OK on PC, but cannot get it working on Asus. It's very frustrating because servo is doing something, it is rotating, but it doesn't exactly do what it should.
Any advice or suggestion is highly appreciated.

Thanks,

Mike

P.S part of lsusb output from Asus:

    Bus 002 Device 002: ID 06c2:0038
    Device Descriptor:
    bLength 18
    bDescriptorType 1
    bcdUSB 1.10
    bDeviceClass 0
    bDeviceSubClass 0
    bDeviceProtocol 0
    bMaxPacketSize0 8
    idVendor 0x06c2
    idProduct 0x0038
    bcdDevice 3.0d
    iManufacturer 1 Phidgets Inc.
    iProduct 2 PhidgetServo
    iSerial 3 20536
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 23, 2008 3:57 pm 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
Any chance of updating to 2.6 on the router?


Top
 Profile Send private message  
 
 Post subject:
PostPosted: Wed Jan 23, 2008 11:01 pm 
Offline
Site Admin

Joined: Fri Dec 05, 2003 3:45 pm
Posts: 259
Location: Canada
It could be a power issue as well - try using an external power supply and plugging into Servo ports 1..3

Chester


Top
 Profile Send private message  
 
 Post subject:
PostPosted: Thu Jan 24, 2008 3:19 am 
Offline
Phidgetly

Joined: Wed Jan 23, 2008 2:07 pm
Posts: 15
Location: UK
Thank you for replay guys.

Patric - yes, this is my plan B, I already started to look at openwrt firmware, it seems they have stable 2.6 firmware. It won't be painless becasue currently my asus is running very customized OS and I'll have to do everything from scratch but of course this is something I'll try to do if no other solution is available.

Fitchett - yes, I have already tried that, this is exactly what I thought - servo looks like broken or not getting enough power. I used external power supply and plugged into port 1 but still the same problem.
Could lack of power explain strange values I'm getting from getMotorPosition?


Thanks,

Mike


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 24, 2008 10:04 am 
Offline
Phidgetly

Joined: Wed Jan 23, 2008 2:07 pm
Posts: 15
Location: UK
It seems I'm out of luck. According to some websites, Linux based firmware for Broadcom (ie. openwrt) can run on 2.6 kernels but they don't support wifi at the moment.
It looks I have to find a solution for my 2.4 setup.
Any suggestions on how could I debug it are very welcome.
Could it be that strange values returned by getMotorPosition have something to do with
the uhci kernel module not functioning properly? Timing issues maybe?

Cheers,
Mike


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 24, 2008 10:34 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
It could be a problem with the USB driver - are there any USB logs showing up in syslog, or the kernel log? Do other USB devices work fine? Anything at all showing up in the phidget21 log?

-Patrick


Top
 Profile Send private message  
 
 Post subject:
PostPosted: Thu Jan 24, 2008 12:40 pm 
Offline
Phidgetly

Joined: Wed Jan 23, 2008 2:07 pm
Posts: 15
Location: UK
There is one message from the kernel:
<7>usbdevfs: USBDEVFS_CONTROL failed dev 2 rqt 128 rq 6 len 255 ret -32

I have added many sleep() calls to my code and I was able to confirm
that the above message shows up when the application makes
CPhidget_open() call. The kernel message is always exactly the same (same dev, rqt, rq, len, ret) and it seems that only CPhidget_open() call causes it.

CPhidget_open() returns OK, then I call CPhidget_getDeviceName
and it returns: "Phidget Servo Controller 4-motor"

phidgetlog.txt contain only those 3 messages:
Thu Jan 24 18:32:48 2008,0,"clog.c(46)",INFO,"Enabling logging"
Thu Jan 24 18:32:48 2008,0,"cthread.c(199)",INFO,"WriteThreadFunction running"
Thu Jan 24 18:32:48 2008,0,"cthread.c(175)",INFO,"ReadThreadFunction running"

Mike


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 24, 2008 12:43 pm 
Offline
Phidgetly

Joined: Wed Jan 23, 2008 2:07 pm
Posts: 15
Location: UK
I forgot to mention that the other USB devices seems to work fine.
I've got USB webcam connected to it and 2GB USB flash memory.
Just to be 100% sure I'll try connect the servo to a different usb port
which currently is used by a pen drive.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 24, 2008 3:23 pm 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
Does the servo's position change event ever fire?


Top
 Profile Send private message  
 
 Post subject:
PostPosted: Thu Jan 24, 2008 5:58 pm 
Offline
Phidgetly

Joined: Wed Jan 23, 2008 2:07 pm
Posts: 15
Location: UK
Yes, not very often though.
I've modified my program to read command line: start & end position, step inside a loop and usleep. for example: ./myprog 20 190 0.1 20000 (will go from 20 to 190 stepping by 0.1, sleeping 20ms)
If I run it, let say, 5 times then once I'll see output like below, that has position hander called couple of times. First number in "Current position" message (which is inside a loop) is
the argument to setMotorPosition, second is the value returned by getMotorPosition (called right after setposition)

    ...
    [ setMotorPosition(82.6) called, then getMotorPosition that returns 0.000 ]

    Current position is 82.600000 0.000000

    [ setMotorPosition(82.9) not returning error ]
    [ geMotorPosition() called, returned error ]

    9: Value is Unknown (State not yet received from device).
    Current position is 82.900000 0.000000
    position handler : index 0, position -23.000000
    position handler : index 1, position -23.000000
    position handler : index 2, position -23.000000
    position handler : index 3, position -23.000000
    position handler : index 0, position 82.850000
    Current position is 83.200000 82.850000
    position handler : index 0, position -23.000000
    Current position is 83.500000 -23.000000
    Current position is 83.800000 -23.000000
    ... 10 more lines with -23 ...
    Current position is 87.100000 -23.000000
    Current position is 87.400000 -23.000000
    position handler : index 0, position 87.090000
    position handler : index 0, position -23.000000
    Current position is 87.700000 -23.000000
    Current position is 88.000000 -23.000000
    Current position is 88.300000 -23.000000
    position handler : index 0, position 87.940000
    position handler : index 0, position -23.000000
    Current position is 88.600000 -23.000000
    ... 6 more lines with -23 ...
    Current position is 90.700000 -23.000000
    position handler : index 0, position 90.680000
    Current position is 91.000000 90.680000
    position handler : index 0, position -23.000000
    Current position is 91.300000 -23.000000
    Current position is 91.600000 -23.000000
    ... more lines with -23 ..

4 times I run the program it gives me -23 or 0.000, no position handler called whatsoever.
So far when I get first "position handler" it is always
called for indexes from zero to three, e.g. :
    Current position is 10.300000 0.000000
    position handler : index 0, position -23.000000
    position handler : index 1, position -23.000000
    position handler : index 2, position -23.000000
    position handler : index 3, position -23.000000


BTW, I've tried to other USB port, still the same.

Michal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 25, 2008 11:08 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
Can you try upgrading to the latest library? What version is your servo controller (software version)? I'm a bit stumped.

-Patrick


Top
 Profile Send private message  
 
 Post subject:
PostPosted: Fri Jan 25, 2008 5:02 pm 
Offline
Phidgetly

Joined: Wed Jan 23, 2008 2:07 pm
Posts: 15
Location: UK
I've upgraded to the latest version.
    Device name: Phidget Servo Controller 4-motor
    Device type: PhidgetServo
    Library version: Phidget21 - Version 2.1.3 - Built Jan 25 2008 21:48:00
    Device version: 313
    Device serial number: 20536

Now something is different. My program can finish abnormally in CPhidget_waitForAttachment or CPhidget_open. It happens about 50% of all runs.
I've enabled libusb debugging (USB_DEBUG environment) and this is
how it looks

    Will be waiting... [ output from my prog, just before entering waitForAttachement]
    ... output from libusb ...
    usb_os_init: Found USB VFS at /proc/bus/usb
    usb_os_find_busses: Skipping non bus directory devices
    usb_os_find_busses: Skipping non bus directory drivers
    usb_os_find_busses: Found 003
    usb_os_find_busses: Found 002
    usb_os_find_busses: Found 001
    usb_os_find_devices: Found 001 on 003
    usb_os_find_devices: Found 001 on 002
    usb_os_find_devices: Found 002 on 002
    skipped 1 class/vendor specific interface descriptors
    usb_os_find_devices: Found 001 on 001
    usb_os_find_devices: Found 002 on 001
    USB error: could not get bound driver: No data available
    USB error: error sending control message: Broken pipe
    ... program finishes ...

With USB_DEBUG enabled I can see the usb_os_init, usb_os_find_busses sequence couple of time during execution of my loop (if the application
doesn't finish abnormally).

I have enabled uhci kernel module debugging.
Messages are very cryptic to me, I don't want to copy too much, basically
they show up when the program calls CPhidget_open


    [a13770c0] link (01377032) element (013b5214)
    Depth traverse
    Element != First TD

    0: [a13b51e0] link (013b5214) e3 LS Length=7 MaxLen=7 DT0 EndPt=0 Dev=2, PID=2d(SETUP) (buf=01ddf600)

    1: [a13b5210] link (013b5244) e3 LS Stalled Length=7ff MaxLen=7 DT1 EndPt=0 Dev=2, PID=69(IN) (buf=00f8e000)
    2: [a13b5240] link (013b5274) e3 SPD LS Active Length=0 MaxLen=7 DT0 EndPt=0 Dev=2, PID=69(IN) (buf=00f8e008)

    ... several similar lines (SPD LS..) , with different values ...

    32: [a13b57e0] link (013b5814) e3 SPD LS Active Length=0 MaxLen=6 DT0 EndPt=0 Dev=2, PID=69(IN) (buf=00ffb0f8)

    33: [a13b5810] link (00000001) e3 LS IOC Active Length=0 MaxLen=7ff DT1 EndPt=0 Dev=2, PID=e1(OUT) (buf=00000000)


and then shows up usbdevfs: USBDEVFS_CONTROL failed dev message.
Above kernel messages appear every time Cphidget_open is called.

No changes in phidgetlog.txt whatsover.

I noticed the servo motion has some regularities. It's a little bit like breathing, about 0.5 sec of the rotation, then 1.5 pause, then 0.5 again.

This is a bit frustrating, I don't know exactly where to look for the problem.


Top
 Profile  
 
 Post subject: Similar problem here
PostPosted: Fri Jan 25, 2008 5:59 pm 
Offline
Fresh meat

Joined: Fri Jan 25, 2008 5:34 pm
Posts: 3
Hi Mike - I too am trying to get my RFID phidgets working on an Asus WL-500G Premium, and I'm having a problem very much like yours. One difference is that I'm using OpenWRT.

With the latest Phidgets library, I'm trying to get the sample C application RFID-simple (I renamed rfidtest) working. Most of the time it just detects the phidget, then exits. Below is what I get with libusb debugging on. I've not gotten it to read a tag; it always just exits without error.

Code:
root@OpenWrt:~# rfidtest
usb_set_debug: Setting debugging level to 9 (on)
usb_os_init: Found USB VFS at /proc/bus/usb
usb_os_find_busses: Skipping non bus directory devices
usb_os_find_busses: Skipping non bus directory drivers
usb_os_find_busses: Found 003
usb_os_find_busses: Found 002
usb_os_find_busses: Found 001
usb_os_find_devices: Found 001 on 003
usb_os_find_devices: Found 001 on 002
usb_os_find_devices: Found 001 on 001
usb_os_find_devices: Found 002 on 001
skipped 1 class/vendor specific interface descriptors
usb_set_debug: Setting debugging level to 9 (on)
usb_os_init: Found USB VFS at /proc/bus/usb
usb_os_find_busses: Skipping non bus directory devices
usb_os_find_busses: Skipping non bus directory drivers
usb_os_find_busses: Found 003
usb_os_find_busses: Found 002
usb_os_find_busses: Found 001
usb_os_find_devices: Found 001 on 003
usb_os_find_devices: Found 001 on 002
usb_os_find_devices: Found 001 on 001
usb_os_find_devices: Found 002 on 001
skipped 1 class/vendor specific interface descriptors
USB error: could not get bound driver: No data available
Waiting for RFID to be attached....Phidget RFID       2147 attached!
root@OpenWrt:~#


Here's the phidget debug log from this run. There are a number of errors, plus some apparent garbage characters on line 2.

Code:
root@OpenWrt:~# cat plog.txt
Sat Jan  1 00:18:44 2000,0,"clog.c(46)",INFO,"Enabling logging"
Sat Jan  1 00:18:44 2000,0,"cusblinux.c(346)",INFO,"New device in CUSBBuildList: 002*
     Á*`"
Sat Jan  1 00:18:44 2000,0,"cusblinux.c(437)",WARN,"usb_get_driver_np failed with error code: -61 "No data available""
Sat Jan  1 00:18:44 2000,0,"cusblinux.c(249)",ERR,"usb_get_string_simple failed in CUSBGetDeviceCapabilities with error code: -27 "File too large""
Sat Jan  1 00:18:44 2000,0,"cusblinux.c(481)",ERR,"CUSBGetDeviceCapabilities returned nonzero code: 3"
Sat Jan  1 00:18:44 2000,0,"cthread.c(281)",INFO,"WriteThread running"
Sat Jan  1 00:18:44 2000,0,"cthread.c(307)",INFO,"WriteThread exiting normally (Not Needed for this device)"
root@OpenWrt:~#


Here are my installed packages:

Code:
root@OpenWrt:/# ipkg list_installed
base-files-brcm-2.4 - 10-9078 -
bridge - 1.0.6-1 -
busybox - 1.4.2-2 -
dnsmasq - 2.39-1 -
dropbear - 0.50-2 -
iptables - 1.3.7-1 -
kernel - 2.4.34-brcm-1 -
kmod-brcm-wl - 2.4.34+4.80.53.0-1 -
kmod-diag - 2+2.4.34-brcm-1 -
kmod-ipt-nathelper - 2.4.34-brcm-1 -
kmod-ppp - 2.4.34-brcm-1 -
kmod-pppoe - 2.4.34-brcm-1 -
kmod-switch - 2.4.34-brcm-1 -
kmod-usb-core - 2.4.34-brcm-1 -
kmod-usb-uhci-iv - 2.4.34-brcm-1 -
kmod-usb2 - 2.4.34-brcm-1 -
kmod-wlcompat - 2.4.34+brcm-6 -
libgcc - 3.4.6-10 -
libpthread - 0.9.28-10 -
libusb - 0.1.12-1 -
mtd - 5 -
nas - 4.80.53.0-1 -
nvram - 1 -
phidgets - 2.1-1 -
ppp - 2.4.3-8 -
ppp-mod-pppoe - 2.4.3-8 -
rfidtest - 1.0-1 -
uclibc - 0.9.28-10 -
wireless-tools - 29-1 -
wlc - 4.80.53.0-1 -
Done.
root@OpenWrt:/#


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 25, 2008 6:20 pm 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
It's starting to look like either the kernel is missing some required support or there is a bug in the host controller.


Top
 Profile Send private message  
 
 Post subject:
PostPosted: Sat Jan 26, 2008 6:16 am 
Offline
Phidgetly

Joined: Wed Jan 23, 2008 2:07 pm
Posts: 15
Location: UK
Hi sgm, I'm sorry you've got this problem too, but it's nice to know I'm not alone :wink:

Would it be hard for you to try 2.6 kernel? I think kamikaze branch have 2.6 firmware. This could eliminate (or confirm) that it's a hardware problem.
I see you're using usb-uhci (kmod-usb-uhci-iv), AFAIK it doesn't have debug option. If you could try to use kmod-usb-uhci with a debug option
insmod uhci.o debug=10
then maybe you could get some messages in /var/log/messages.

I've downloaded openwrt sources with the 2.4.35.4 kernel. I will try
to run newer uhci module or at least compare the source code with my current kernel code (2.4.34-pre2)

It would be great to know that it's not a hardware bug. If it's not hardware that probably I would buy another asus to try different software on it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 38 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 7 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group