Products for USB Sensing and Control
It is currently Wed May 22, 2013 10:09 pm

All times are UTC - 7 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: SetPosition
PostPosted: Thu Jun 21, 2012 3:19 pm 
Offline
Fresh meat

Joined: Thu Jun 21, 2012 3:09 pm
Posts: 4
Hello,

Can somebody tell me why, when I run my code, I'm using a camer to tell me where my head is located. and based on different intervals of x axis I want the servo motor to turn to a certain degree. But It seems like it only turns when I first run the code. After that it doesn't turn. I know it is not my code because I have printf in there and I can see that it works properly when I move my head but The servo motor doesn't move at all. Thanks in advance.

here is the servo motor part of the code:
Code:
   int v=0;
   int result;
   double curr_pos;
   const char *err;
   double minAccel, maxVel;

   //Declare an advanced servo handle
   CPhidgetAdvancedServoHandle servo = 0;

   //create the advanced servo object
   CPhidgetAdvancedServo_create(&servo);
   
   //open the device for connections
   CPhidget_open((CPhidgetHandle)servo, -1);

if (head > 0.0150)      //if the head is anywhere between 0.0150 to infiniti then declare that as left
         {
            //printf("hey I'm on left\n");
            CPhidgetAdvancedServo_setEngaged(servo, v, 1);
            CPhidgetAdvancedServo_setPosition (servo, v, 40.00);
                        
                     }

      
         else if((0.0150 >= head) && (head >= (-0.0400))) //if the head is anywhere between 0.0150 to -0.0400 then declare that as middle
         {
             //printf("hey I'm in the middle\n");
            CPhidgetAdvancedServo_setEngaged(servo, v, 1);
            CPhidgetAdvancedServo_setPosition (servo, v,150.00);
            
            
            
         }

         else         //if the head is anywhere between -0.0400 to -infiniti then declare that as Right
         {
            //printf("I'm ON RIGHT\n");

            CPhidgetAdvancedServo_setEngaged(servo, 0, 1);
            CPhidgetAdvancedServo_setPosition (servo, 0, 210.00);
            
         }


Top
 Profile Send private message  
 
 Post subject: Re: SetPosition
PostPosted: Fri Jun 22, 2012 7:34 am 
Offline
Human-Cyborg Relations
User avatar

Joined: Tue Sep 27, 2011 2:37 pm
Posts: 324
Location: Calgary
Try putting a short pause between the setEngaged and setPosition. It is likely that the motor is not finished engaging before you try to set the position which would result in the motor not moving.

_________________
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com


Top
 Profile Send private message  
 
 Post subject: Re: SetPosition
PostPosted: Fri Jun 22, 2012 8:31 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
No, that doesn't make sense. You need to add a waitForAttachement after calling open.

Also, you should check the return value on your Phidgets calls. These would probably explain the error (by returning EPHIDGET_NOTATTACHED).

-Patrick


Top
 Profile Send private message  
 
 Post subject: Re: SetPosition
PostPosted: Mon Jun 25, 2012 8:26 am 
Offline
Fresh meat

Joined: Thu Jun 21, 2012 3:09 pm
Posts: 4
Thanks for the suggestions.

I'm sure it is not the delay, because my other code works just fine without a delay.

As for waitForAttachment, I orginally had that in my code but I commented it out. i know that was not quite the greatest idea. But it causes error and it returns this (Problem waiting for the attachment: Given timeout has been exceeded.) What would cause this problem?

Thanks.


Top
 Profile Send private message  
 
 Post subject: Re: SetPosition
PostPosted: Mon Jun 25, 2012 8:28 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
Make sure that the timeout is at least 500. If you set it to 2500 and still get a timeout - that probably means that the Phidget is either not attached, or being used by another program.

-Patrick


Top
 Profile Send private message  
 
 Post subject: Re: SetPosition
PostPosted: Mon Jun 25, 2012 8:55 am 
Offline
Fresh meat

Joined: Thu Jun 21, 2012 3:09 pm
Posts: 4
I tried but it seems to be not working.
I emailed you my code. Would you be kind enough to take a look at it and send your feedbacks?

Thanks a lot.


Top
 Profile Send private message  
 
 Post subject: Re: SetPosition
PostPosted: Mon Jun 25, 2012 9:11 am 
Offline
Lead Developer
User avatar

Joined: Mon Jun 20, 2005 8:46 am
Posts: 2351
Location: Canada
Feedback sent.

-Patrick


Top
 Profile Send private message  
 
 Post subject: Re: SetPosition
PostPosted: Mon Jun 25, 2012 9:52 am 
Offline
Fresh meat

Joined: Thu Jun 21, 2012 3:09 pm
Posts: 4
Thanks a lot Patrick. Now it works! :D I really appreciate your feedback and help.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 7 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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