Go Down

Topic: Decoding Radio Control signal pulses (Read 74300 times) previous topic - next topic

gmv

Hi guys, i´ve playing with the Arduino with the servo decoder sketch and while connecting the 2 servos i tried to disconnect the radio to test the "fail safe" feature but i noticed that the servos don´t stay at middle position, they move to the maximum position(2,1ms), my question is.....how can i activate this feature for each servo ?  :o

thanks in advance

mem

#76
May 26, 2009, 07:31 am Last Edit: May 26, 2009, 07:32 am by mem Reason: 1
The failsafe value can be set for any channel by calling the setFailsafe() method with the desired channel and value:
[font=Courier New]  ServoDecode.setFailsafe(3,1234); // set channel 3 failsafe pulse  width to 1234[/font]
Calling  setFailsafe with just the channel sets the failsafe to the last valid received pulse width
[font=Courier New]   ServoDecode.setFailsafe(4); // set channel 4 failsafe to use the last received pulse  width[/font]

By default, all channels are set with a failsafe pulse width of 1500.

gmv

Hi mem, well this is what i´ve tested but the problem persist,...when i disconnect the radio the servo just doesn´t stays at center position, in the sketch, when i declare to use the last received position,..the arduino just return and error message while compiling.

thanks

mem

Quote
when i declare to use the last received position,..the arduino just return and error message while compiling.

Could you clarify what you mean by 'last received position'.
What error message did you get?
Can you post a fragment of the sketch that illustrates the change that is causing the problem?

gmv

#79
May 26, 2009, 08:09 pm Last Edit: May 26, 2009, 08:10 pm by gmv Reason: 1
I ment "last pulse width" received, today i could finally get failsafe on channel 1 but thats all, how can i put the others with failsafe as well ?

here is a part of the sketch :

Code: [Select]
void setup()  
{
 Serial.begin(115200);
 

 servoA.attach(servoApin);
 servoB.attach(servoBpin);
 servoC.attach(servoCpin);
 servoD.attach(servoDpin);
 servoE.attach(servoEpin);
 servoF.attach(servoFpin);
 servoG.attach(servoGpin);

 ServoDecode.begin();
 
 ServoDecode.setFailsafe(1,1234); // set channel 1 failsafe pulse  width
 ServoDecode.setFailsafe(2,1234); // set channel 2 failsafe pulse  width
 ServoDecode.setFailsafe(3,1234); // set channel 3 failsafe pulse  width
 ServoDecode.setFailsafe(4,1234); // set channel 4 failsafe pulse  width
 ServoDecode.setFailsafe(5,1234); // set channel 5 failsafe pulse  width
 ServoDecode.setFailsafe(6,1234); // set channel 6 failsafe pulse  width
 ServoDecode.setFailsafe(7,1234); // set channel 7 failsafe pulse  width  
 ServoDecode.setFailsafe(8,1234); // set channel 8 failsafe pulse  width


 thanks


mem

#80
May 26, 2009, 09:16 pm Last Edit: May 26, 2009, 09:18 pm by mem Reason: 1
It works for me, running this code:
Code: [Select]
// ServoDecodeTest

#include <ServoDecode.h>

char * stateStrings[] = {
 "NOT_SYNCHED", "ACQUIRING", "READY", "in Failsafe"};

void setup()  
{
 Serial.begin(9600);
 ServoDecode.begin();
 for( int i=1; i <=8; i++){
    ServoDecode.setFailsafe(i,1230 + i);
 }
}


void loop()      
{
 int pulsewidth;

 // print the decoder state
 if( ServoDecode.getState()!= READY_state) {
   Serial.print("The decoder is ");
   Serial.println(stateStrings[ServoDecode.getState()]);
   for ( int i =1; i <=MAX_CHANNELS; i++ ){ // print the status of the first four channels
     Serial.print("Cx"); // if you see this, the decoder does not have a valid signal
     Serial.print(i);
     Serial.print("= ");
     pulsewidth = ServoDecode.GetChannelPulseWidth(i);
     Serial.print(pulsewidth);
     Serial.print("  ");
   }
   Serial.println("");
 }
 else {
   // decoder is ready, print the channel pulse widths
   for ( int i =1; i <=MAX_CHANNELS; i++ ){ // print the status of the first four channels
     Serial.print("Ch");
     Serial.print(i);
     Serial.print("= ");
     pulsewidth = ServoDecode.GetChannelPulseWidth(i);
     Serial.print(pulsewidth);
     Serial.print("  ");
   }
   Serial.println("");
 }
 delay(500); // update 2 times a second        
}



I get this ouput:
Code: [Select]

The decoder is ACQUIRING
Cx1= 0  Cx2= 0  Cx3= 0  Cx4= 0  Cx5= 0  Cx6= 0  Cx7= 0  Cx8= 0  
Ch1= 1504  Ch2= 1509  Ch3= 1562  Ch4= 1489  Ch5= 1124  Ch6= 1041  Ch7= 1500  Ch8= 1500  
Ch1= 1505  Ch2= 1509  Ch3= 1561  Ch4= 1490  Ch5= 1123  Ch6= 1041  Ch7= 1500  Ch8= 1500  
Ch1= 1506  Ch2= 1507  Ch3= 1562  Ch4= 1489  Ch5= 1123  Ch6= 1039  Ch7= 1500  Ch8= 1500  
<transmitter switch off here>
The decoder is in Failsafe
Cx1= 1231  Cx2= 1232  Cx3= 1233  Cx4= 1234  Cx5= 1235  Cx6= 1236  Cx7= 1237  Cx8= 1238  
The decoder is in Failsafe
Cx1= 1231  Cx2= 1232  Cx3= 1233  Cx4= 1234  Cx5= 1235  Cx6= 1236  Cx7= 1237  Cx8= 1238  
The decoder is in Failsafe
Cx1= 1231  Cx2= 1232  Cx3= 1233  Cx4= 1234  Cx5= 1235  Cx6= 1236  Cx7= 1237  Cx8= 1238  



gmv

Thanks mem, i guess i'm missing something here, i still have no failsafe besides channel 1, are using the same libraries for servodecoder and servotimer2 placed before on this thread, is any update for these two ?

I'll give it a try later and see whats is going wrong.

thanks

mem

gmv, did you try the test sketch posted above?

I would be interested to see the output when the transmitter is on and then when it is switched off

gmv

#83
May 29, 2009, 11:22 am Last Edit: May 29, 2009, 11:22 am by gmv Reason: 1
Hi mem, finally i could make it work, just changed the delay =50, i was using 500, also i changed the speed to 57600.
I used your sketch above.

thanks a lot for your help. :D

mem

#84
May 29, 2009, 01:05 pm Last Edit: May 29, 2009, 01:45 pm by mem Reason: 1
Hmmm, I am curious to know why it started working. Changing the delay should only increase how often the information is printed. And the baud rate shouldn't affect the failsafe. Did anything else change?  

If you change the delay in that sketch back to 500 and the baud to 9600 would it stop working?

gmv

Hi mem, in fact at first attempt i couldn't make it start, then i reload the code in to the chip and it started working but the servos didn't seem to responde as quickly as i moved the sticks, so i tried to increase the speed and it worked, but then when i switched off and on the radio, sometimes i had failsafe and some others none, tried several delays and it worked out with 50, now if you ask me why,..... ???  ::) ::) ::)

GMV

mem

Hi gmv, for the benefit of others that read this thread and think you had a problem with the test sketch posted in #reply 80, could you try it and it confirm if it works with the values as posted. Your posts seem to say that you needed to change the values in that sketch to get it to work.

If that sketch works but yours has a problem when the values change, then we would need to look at your code to see what the problem is.

alpha_tayyab

can u explain me ur problem, may be i help you!!!!!!!!!

mem

Hi TAYTAB, I think gmv has fixed his problem; it's just not clear what he has changed to get it working.

zitron

Hi,

Sorry for digging this up, I spent ages trying to get MEM's ServoDecode to work, sometimes it worked fine, other times not at all. In the end, it turns out the problem was my receiver's PPM "HIGH" was not quite enough for the 168. So all I had to do to get it working was to add digitalWrite(icpPin, HIGH) in servodecode.begin() to enable the internal pull-up resistor. Now it's perfect.

Hope this helps someone.

-Z-


Go Up