Skip to content

Commit

Permalink
Try to reuce the Rx values passing jitter.
Browse files Browse the repository at this point in the history
  • Loading branch information
balrog-kun committed Jun 19, 2011
1 parent 82553db commit cab9779
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions rx.c
Expand Up @@ -69,7 +69,14 @@ ISR(PCINT0_vect) {
* the previous edge.
*/

if ((uint32_t) (now - rx_up) > F_CPU / 400) {
if ((uint32_t) (now - rx_up) > F_CPU / 400)
rx_chnum = 0;
else if ((uint32_t) (now - rx_up) < F_CPU / 2000)
return;
else {
/* XXX: should use F_CPU below */
rx_ch[rx_chnum ++] = now - rx_up - F_CPU / 1050;

/* Un-mix the channels. The ET6I trasmitter is made
* specifically for helicopters and mixes the channels on
* the tx side to produce signals for: the motor, the 4
Expand All @@ -86,25 +93,22 @@ ISR(PCINT0_vect) {
* for the left-right / front-back nick values we should
* compare th three servo angles.
*/
uint16_t up_raw = rx_ch[2] >= ((256 + 31) << 6) ?
((256 + 31) << 6) - 1 : rx_ch[2];
uint16_t back_raw = rx_ch[1] -
(rx_ch[2] >> 2) - (rx_ch[2] >> 4);
uint16_t left_raw = rx_ch[0] + (back_raw >> 1) -
(rx_ch[2] >> 2) - (rx_ch[2] >> 4);

rx_co_throttle = (up_raw >> 6) - 31;
rx_co_right = (rx_ch[3] >> 6) - 10;
rx_cy_front = ((~back_raw) >> 6) - 4;
rx_cy_right = ((~left_raw) >> 6) + 66;

rx_chnum = 0;
rx_no_signal = 0;
} else if ((uint32_t) (now - rx_up) > F_CPU / 2000)
/* XXX: should use F_CPU below */
rx_ch[rx_chnum ++] = now - rx_up - F_CPU / 1050;
else
return;
if (rx_chnum == 4) {
uint16_t up_raw = rx_ch[2] >= ((256 + 31) << 6) ?
((256 + 31) << 6) - 1 : rx_ch[2];
uint16_t back_raw = rx_ch[1] -
(rx_ch[2] >> 2) - (rx_ch[2] >> 4);
uint16_t left_raw = rx_ch[0] + (back_raw >> 1) -
(rx_ch[2] >> 2) - (rx_ch[2] >> 4);

rx_co_throttle = (up_raw >> 6) - 31;
rx_co_right = (rx_ch[3] >> 6) - 10;
rx_cy_front = ((~back_raw) >> 6) - 4;
rx_cy_right = ((~left_raw) >> 6) + 66;

rx_no_signal = 0;
}
}

rx_up = now;
}
Expand Down

0 comments on commit cab9779

Please sign in to comment.