Legacy Forum: Preserving Nearly 20 Years of Community History - A Time Capsule of Discussions, Memories, and Shared Experiences.

Control RC servos with one PWM pulse

Based on DMP's Vortex processor / SoC this board is a full computer capable of running a standard Windows and Linux installation on the backpack of your robot.
7 postsPage 1 of 1
7 postsPage 1 of 1

Control RC servos with one PWM pulse

Post by romayiii » Wed Feb 03, 2010 8:04 pm

Post by romayiii
Wed Feb 03, 2010 8:04 pm

Hi!

I've been working with rc servo lib to control HITEC HSR8498 RC servos. However this lib controls the servos sending pulses inside a while() until the end position is reached. example code:


Code: Select all

if(rcservo_Initialize(RCSERVO_USECHANNEL9)){
      unsigned long motion[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
      //set motion for playing
      
      rcservo_EnterPlayMode();
      motion[9]=650;
      while(true){
         if(motion[9]!=650)
            motion[9]=650;
         else
            motion[9]=2400;   
         rcservo_SetAction(motion, 50);//play motion in 500ms
         while (rcservo_PlayAction() != RCSERVO_PLAYEND) { //I dont want to use this line.
            //
            //can do something here when sending PWM pulses
            //
            printf("Setting motion[9] = %ld \n",motion[9]);
         }
         delay(1);
      }   
   }
   rcservo_Close();



What I want to do is to control the HSR8498 RC servo with just one pulse, without using the while() because the program waits here until it finish and doesn't let me do anything else, and I don't want to put extra code inside the while (where it says "can do something here when sending PWM pulses") . I know that HITEC HSR8498 can move with just one pulse but I don't know how to do it with the roboard.

Thanks
Hi!

I've been working with rc servo lib to control HITEC HSR8498 RC servos. However this lib controls the servos sending pulses inside a while() until the end position is reached. example code:


Code: Select all

if(rcservo_Initialize(RCSERVO_USECHANNEL9)){
      unsigned long motion[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
      //set motion for playing
      
      rcservo_EnterPlayMode();
      motion[9]=650;
      while(true){
         if(motion[9]!=650)
            motion[9]=650;
         else
            motion[9]=2400;   
         rcservo_SetAction(motion, 50);//play motion in 500ms
         while (rcservo_PlayAction() != RCSERVO_PLAYEND) { //I dont want to use this line.
            //
            //can do something here when sending PWM pulses
            //
            printf("Setting motion[9] = %ld \n",motion[9]);
         }
         delay(1);
      }   
   }
   rcservo_Close();



What I want to do is to control the HSR8498 RC servo with just one pulse, without using the while() because the program waits here until it finish and doesn't let me do anything else, and I don't want to put extra code inside the while (where it says "can do something here when sending PWM pulses") . I know that HITEC HSR8498 can move with just one pulse but I don't know how to do it with the roboard.

Thanks
romayiii
Robot Builder
Robot Builder
Posts: 7
Joined: Wed Feb 03, 2010 7:45 pm

Post by Sazabi » Thu Feb 04, 2010 4:36 am

Post by Sazabi
Thu Feb 04, 2010 4:36 am

I've been looking in rcservo.h yeasterday and found rcservo_MoveTo() command in Play Mode functions. It has two arguments - unsigned long *width and unsigned long playtime. Heven't tried it yet, but looks like that's what you're looking for.
I've been looking in rcservo.h yeasterday and found rcservo_MoveTo() command in Play Mode functions. It has two arguments - unsigned long *width and unsigned long playtime. Heven't tried it yet, but looks like that's what you're looking for.
Sazabi
Savvy Roboteer
Savvy Roboteer
Posts: 73
Joined: Mon Jan 07, 2008 8:57 am

Post by romayiii » Thu Feb 04, 2010 8:11 pm

Post by romayiii
Thu Feb 04, 2010 8:11 pm

Thanks Sazabi,

I will try it right now and post my results later. Although I've recieved response directly from roboard tech support and they answer this:

Code: Select all
        rcservo_SendPWMPulses(9, 10000L, motion[9], 1);
        rcservo_SendPWMPulses(10, 10000L, motion[10], 1);


I will try this to and post results.

Thanks!
Thanks Sazabi,

I will try it right now and post my results later. Although I've recieved response directly from roboard tech support and they answer this:

Code: Select all
        rcservo_SendPWMPulses(9, 10000L, motion[9], 1);
        rcservo_SendPWMPulses(10, 10000L, motion[10], 1);


I will try this to and post results.

Thanks!
romayiii
Robot Builder
Robot Builder
Posts: 7
Joined: Wed Feb 03, 2010 7:45 pm

Post by romayiii » Thu Feb 04, 2010 8:54 pm

Post by romayiii
Thu Feb 04, 2010 8:54 pm

Hi,

I've just tested the rcservo_MoveTo() function and inside this function it is still this while() cicle that waits until the end psotition is reached. However I've tested the rcservo_SendPWMPulses() function and it worked. it needs preconfiguration for counting mode but at least it dones'nt need any cicle to reach the end position. I will continue my test in order too get my code pretty tune.

This is what I've tested and worked:

Code: Select all
if(rcservo_Initialize(RCSERVO_USECHANNEL9)){
      unsigned long motion[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
      //set motion for playing
      
      rcservo_EnterPlayMode();
      rcservo_SetServo(9, RCSERVO_HITEC_HSR8498);
      pwm_SetCountingMode(9, PWM_CONTINUE_MODE);
      rcservo_EnterPWMMode();
      while(true){
         if(motion[9]!=650)
            motion[9]=650;
         else
            motion[9]=2400;   
         rcservo_SendPWMPulses(9, 20000L, motion[9],1);
         usleep(100000);
      }
   }   
   rcservo_Close();


It moves servo 9 frome one postition to another without while().[/code]
Hi,

I've just tested the rcservo_MoveTo() function and inside this function it is still this while() cicle that waits until the end psotition is reached. However I've tested the rcservo_SendPWMPulses() function and it worked. it needs preconfiguration for counting mode but at least it dones'nt need any cicle to reach the end position. I will continue my test in order too get my code pretty tune.

This is what I've tested and worked:

Code: Select all
if(rcservo_Initialize(RCSERVO_USECHANNEL9)){
      unsigned long motion[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
      //set motion for playing
      
      rcservo_EnterPlayMode();
      rcservo_SetServo(9, RCSERVO_HITEC_HSR8498);
      pwm_SetCountingMode(9, PWM_CONTINUE_MODE);
      rcservo_EnterPWMMode();
      while(true){
         if(motion[9]!=650)
            motion[9]=650;
         else
            motion[9]=2400;   
         rcservo_SendPWMPulses(9, 20000L, motion[9],1);
         usleep(100000);
      }
   }   
   rcservo_Close();


It moves servo 9 frome one postition to another without while().[/code]
romayiii
Robot Builder
Robot Builder
Posts: 7
Joined: Wed Feb 03, 2010 7:45 pm

Post by Sazabi » Sat Feb 06, 2010 12:16 pm

Post by Sazabi
Sat Feb 06, 2010 12:16 pm

How is it works for you, if channel 9 is actually channel 8 (because first channel of roboard is 0)? and when you initialize channel 9, which is actually 10 and changing motion[9] should not affect it.
How is it works for you, if channel 9 is actually channel 8 (because first channel of roboard is 0)? and when you initialize channel 9, which is actually 10 and changing motion[9] should not affect it.
Sazabi
Savvy Roboteer
Savvy Roboteer
Posts: 73
Joined: Mon Jan 07, 2008 8:57 am

Post by romayiii » Sat Feb 06, 2010 8:30 pm

Post by romayiii
Sat Feb 06, 2010 8:30 pm

Hi Sazabi,

Yes it was a little truble at first time, but I figured out that PWM Slot 10 on the board is actually RCSERVO_USECHANNEL9 and it is moved with motion[9].

So when I change motion[9] the rc servo that moves in the board is the 10th.

In the board, S1 is moved in the code by CHANNEL0
Hi Sazabi,

Yes it was a little truble at first time, but I figured out that PWM Slot 10 on the board is actually RCSERVO_USECHANNEL9 and it is moved with motion[9].

So when I change motion[9] the rc servo that moves in the board is the 10th.

In the board, S1 is moved in the code by CHANNEL0
romayiii
Robot Builder
Robot Builder
Posts: 7
Joined: Wed Feb 03, 2010 7:45 pm

Post by Sazabi » Sun Feb 07, 2010 12:23 pm

Post by Sazabi
Sun Feb 07, 2010 12:23 pm

Strange, because motion[] starts from 1 and motion[1] should move channel 0, etc, motion[9] moves channel 10. Maybe that is the reason of all my trounles) Should check it today. Thanks!
Strange, because motion[] starts from 1 and motion[1] should move channel 0, etc, motion[9] moves channel 10. Maybe that is the reason of all my trounles) Should check it today. Thanks!
Sazabi
Savvy Roboteer
Savvy Roboteer
Posts: 73
Joined: Mon Jan 07, 2008 8:57 am


7 postsPage 1 of 1
7 postsPage 1 of 1