Skip to content

Commit ebeb04c

Browse files
author
Erik Kettenburg
committed
added RC Navy's libs
1 parent 11378a1 commit ebeb04c

File tree

27 files changed

+2074
-0
lines changed

27 files changed

+2074
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#include <RcSeq.h>
2+
#include <TinyPinChange.h>
3+
#include <SoftRcPulseIn.h>
4+
#include <SoftRcPulseOut.h>
5+
6+
/*
7+
This sketch demonstrates how to easily transform a proportionnal RC channel into 5 digital commands with an ATtiny85.
8+
RC Navy (2013)
9+
http://P.loussouarn.free.fr
10+
11+
COMMMAND OF 5 digital outputs from 5 push button replacing a potentiometer in the RC transmitter:
12+
================================================================================================
13+
Output pins: #1, #2, #3, #4, #5 of an ATtiny85 or a Digispark
14+
The receiver output channel is connected to pin#0 of an ATtiny85 or a Digispark
15+
A furtive pressure on the push button on the transmitter toggles the corresponding output on the ATtiny85 or a Digispark
16+
connected to the receiver output channel.
17+
Version with RcSeq library inspired by: http://bateaux.trucs.free.fr/huit_sorties.html
18+
19+
Modification at RC Transmitter side:
20+
===================================
21+
Custom keyboard with push buttons
22+
=================================
23+
Stick Potentiometer 1K 1K 1K 1K 1K 1K
24+
=================== .--###---+---###---+---###---+---###---+---###---+---###---.
25+
.-. .--. .-. | _.| _.| _.| _.| _.| |
26+
|O|--' | |O|-' PB1 |_| PB2 |_| PB3 |_| PB4 |_| PB5 |_| | PB# = Push Button #
27+
| | # Replaced with | | '| '| '| '| '| |
28+
|O|----># ============> |O|----------+---------+---------+---------+---------+---###---+
29+
| | # | | 100K |
30+
|O|-- | |O|------------------------------------------------------------'
31+
'-' '--' '-'
32+
33+
34+
At RC Receiver side: (The following sketch is related to this ATtiny85 or Digispark)
35+
===================
36+
37+
.---------------.
38+
| |
39+
| ,------+------.
40+
| | VDD |1
41+
| | +-- LED, Relay, etc...
42+
| | |
43+
| | |2
44+
| | +-- LED, Relay, etc...
45+
| | |
46+
| | ATtiny85 |3
47+
| | or +-- LED, Relay, etc...
48+
.------------. | | Digispark |
49+
| |-----' 0| |4
50+
| Channel#1|--------------+ +-- LED, Relay, etc...
51+
| |-----. | |
52+
| RC | | | |5
53+
| RECEIVER | | | +-- LED, Relay, etc...
54+
| | | | GND |
55+
| |- | '------+------'
56+
| Channel#2|- | |
57+
| |- '---------------'
58+
'------------'
59+
60+
Note:
61+
====
62+
- Decoupling capacitors are not drawn.
63+
- This sketch can easily be extended to 8 outputs by using an ATtiny84 which has more pins.
64+
- This sketch cannot work if you are using DigiUSB library as this one monopolizes the "pin change interrupt vector" (which is very time sensitive).
65+
- On the other side, its possible to communicate with exterior world by using <SoftSerial>, a library mainly derived from <SoftwareSerial>, but which
66+
allow to share the pin change interrupt vector through the <TinyPinChange> library.
67+
68+
================================================================================================*/
69+
70+
/* Channel Declaration */
71+
enum {RC_CHANNEL, RC_CHANNEL_NB}; /* Here, as there is a single channel, we could used a simple "#define RC_CHANNEL 0" rather an enumeration */
72+
73+
//==============================================================================================
74+
/* Channel Signal of the Receiver */
75+
#define RX_CHANNEL_SIGNAL_PIN 0
76+
77+
//==============================================================================================
78+
/* Declaration of the custom keyboard": the pulse width of the push buttons do not need to be equidistant */
79+
enum {PUSH_BUTTON1, PUSH_BUTTON2, PUSH_BUTTON3, PUSH_BUTTON4, PUSH_BUTTON5, PUSH_BUTTON_NBR};
80+
#define TOLERANCE 40 /* Tolerance +/- (in microseconds): CAUTION, no overlap allowed between 2 adjacent active areas . active area width = 2 x TOLERANCE (us) */
81+
KeyMap_t CustomKeyboard[] PROGMEM ={ {CENTER_VALUE_US(1100,TOLERANCE)}, /* PUSH_BUTTON1: +/-40 us */
82+
{CENTER_VALUE_US(1300,TOLERANCE)}, /* PUSH_BUTTON2: +/-40 us */
83+
{CENTER_VALUE_US(1500,TOLERANCE)}, /* PUSH_BUTTON3: +/-40 us */
84+
{CENTER_VALUE_US(1700,TOLERANCE)}, /* PUSH_BUTTON4: +/-40 us */
85+
{CENTER_VALUE_US(1900,TOLERANCE)}, /* PUSH_BUTTON5: +/-40 us */
86+
};
87+
88+
//==============================================================================================
89+
/* Trick: a macro to write a single time the ToggleAction#() function */
90+
#define DECLARE_TOGGLE_ACTION(Idx) \
91+
void ToggleAction##Idx(void) \
92+
{ \
93+
static boolean Etat=HIGH; \
94+
digitalWrite(Idx, Etat); \
95+
Etat=!Etat; \
96+
}
97+
98+
/* Declaration of the actions using the DECLARE_TOGGLE_ACTION(Idx) macro with Idx = The number of the action and the pin number (The ##Idx will be automatically replaced with the Idx value */
99+
DECLARE_TOGGLE_ACTION(1)
100+
DECLARE_TOGGLE_ACTION(2)
101+
DECLARE_TOGGLE_ACTION(3)
102+
DECLARE_TOGGLE_ACTION(4)
103+
DECLARE_TOGGLE_ACTION(5)
104+
105+
//==============================================================================================
106+
void setup()
107+
{
108+
RcSeq_Init();
109+
RcSeq_DeclareSignal(RC_CHANNEL, RX_CHANNEL_SIGNAL_PIN); /* RC_CHANNEL Channel is assigned to RX_CHANNEL_SIGNAL_PIN pin */
110+
RcSeq_DeclareCustomKeyboard(RC_CHANNEL, RC_CUSTOM_KEYBOARD(CustomKeyboard)); /* The CustomKeyboard map is assigned to the RC_CHANNEL Channel */
111+
RcSeq_DeclareCommandAndShortAction(RC_CHANNEL, PUSH_BUTTON1, ToggleAction1);pinMode(1,OUTPUT); /* The ToggleAction1 is assigned to the PUSH_BUTTON1 push button #1 */
112+
RcSeq_DeclareCommandAndShortAction(RC_CHANNEL, PUSH_BUTTON2, ToggleAction2);pinMode(2,OUTPUT); /* The ToggleAction2 is assigned to the PUSH_BUTTON1 push button #2 */
113+
RcSeq_DeclareCommandAndShortAction(RC_CHANNEL, PUSH_BUTTON3, ToggleAction3);pinMode(3,OUTPUT); /* The ToggleAction3 is assigned to the PUSH_BUTTON1 push button #3 */
114+
RcSeq_DeclareCommandAndShortAction(RC_CHANNEL, PUSH_BUTTON4, ToggleAction4);pinMode(4,OUTPUT); /* The ToggleAction4 is assigned to the PUSH_BUTTON1 push button #4 */
115+
RcSeq_DeclareCommandAndShortAction(RC_CHANNEL, PUSH_BUTTON5, ToggleAction5);pinMode(5,OUTPUT); /* The ToggleAction5 is assigned to the PUSH_BUTTON1 push button #5 */
116+
}
117+
//==============================================================================================
118+
void loop()
119+
{
120+
RcSeq_Refresh(); /* This function performs all the needed job asynchronously (non blocking) */
121+
}
122+
//============================ END OF SKETCH =================================================
123+
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
Ce sketch de demo de la librairie RcSeq montre comment configurer tres facilement la commande d'actions ou de sequences de servo predefinies.
3+
La commande peut etre:
4+
- un manche de l'emetteur RC avec possibilité de definir jusqu'a 8 positions "actives" (le nombre de position doit etre pair: neutre au milieu)
5+
- un clavier: un montage resistances/boutons-poussoirs remplacant le potentiometre du manche d'un emetteur RC
6+
(les resistances doivent etre d'egales valeurs avec une 2 resistances identiques "au centre/neutre" pour la zone inactive)
7+
- un clavier "maison": un montage resistances/boutons-poussoirs remplacant le potentiometre du manche d'un emetteur RC avec des resistances pas forcement identiques
8+
(la largeur d'impulsion pour chaque bouton-poussoir est define dans une table, une tolerance est egalement prevue)
9+
Les 3 exemples sont traites dans ce sketch de demo.
10+
*/
11+
#include <RcSeq.h>
12+
#include <TinyPinChange.h> /* Ne pas oublier d'inclure la librairie <TinyPinChange> qui est utilisee par la librairie <RcSeq> */
13+
#include <SoftRcPulseIn.h> /* Ne pas oublier d'inclure la librairie <SoftRcPulseIn> qui est utilisee par la librairie <RcSeq> */
14+
#include <SoftRcPulseOut.h> /* Ne pas oublier d'inclure la librairie <SoftRcPulseOut> qui est utilisee par la librairie <RcSeq> */
15+
16+
enum {RC_VOIE1, RC_VOIE2, RC_VOIE3, NBR_VOIES_RC}; /* Declaration des voies */
17+
18+
enum {BP1, BP2, NBR_BP}; /* Declaration des Boutons-Poussoirs (On peut aller jusqu'à BP8) */
19+
20+
enum {POS_MINUS1, POS_PLUS1,NBR_POS}; /* Declaration des positions du Manche on peut aller de POS_MOINS2 à POS_PLUS2 (4 Positions actives Max)*/
21+
22+
23+
/* Declaration d'un clavier "Maison": les impulsions des Boutons-Poussoirs n'ont pas besoin d'etre equidistantes */
24+
enum {BP_MAISON1, BP_MAISON2, BP_MAISON3, NBR_BP_MAISON};
25+
#define TOLERANCE 40 /* Tolerance en + ou en - (en micro-seconde) */
26+
KeyMap_t ClavierMaison[] PROGMEM ={ {VALEUR_CENTRALE_US(1100,TOLERANCE)}, /* BP_MAISON1: 1100 +/-40 us */
27+
{VALEUR_CENTRALE_US(1300,TOLERANCE)}, /* BP_MAISON2: 1300 +/-40 us */
28+
{VALEUR_CENTRALE_US(1700,TOLERANCE)}, /* BP_MAISON3: 1700 +/-40 us */
29+
};
30+
31+
enum {AZIMUT=0, ELEVATION , NBR_SERVO}; /* Delaration de tous les servos, 2 dans cet exemple (On peut déclaer jusqu'à 8 servos) */
32+
33+
/* Declaration des broches reliees aux sorties du recepteur RC */
34+
#define BROCHE_SIGNAL_RECEPTEUR_VOIE1 8
35+
#define BROCHE_SIGNAL_RECEPTEUR_VOIE2 2
36+
#define BROCHE_SIGNAL_RECEPTEUR_VOIE3 9
37+
38+
/* Declaration des broches de commande des servos */
39+
#define BROCHE_SIGNAL_SERVO_EL 3
40+
#define BROCHE_SIGNAL_SERVO_AZ 4
41+
42+
/* Declaration des differents angles des servos */
43+
#define ELEVATION_POS_PONT 120 /* position zodiac sur pont (Pos A) */
44+
#define ELEVATION_POS_HAUT 180 /* position zodiac en haut (Pos B) */
45+
#define ELEVATION_POS_MER 0 /* position zodiac dans l'eau (pos C) */
46+
47+
#define AZIMUT_POS_PONT 90 /* position rotation sur pont */
48+
#define AZIMUT_POS_MER 0 /* position rotation sur mer */
49+
50+
/* Declaration des moments de demarrage ainsi que la duree des mouvement de servo */
51+
#define DEMARRAGE_MONTEE_PONT_HAUT_MS 0L /* 0 pour demarrage immediat, mais on peut mettre une tempo ici. Ex 2000L, va differer la sequence complete de 2 secondes */
52+
#define DUREE_MONTEE_PONT_HAUT_MS 3000L
53+
54+
#define DEMARRAGE_ROTATION_PONT_MER_MS (DEMARRAGE_MONTEE_PONT_HAUT_MS+DUREE_MONTEE_PONT_HAUT_MS)
55+
#define DUREE_ROTATION_PONT_MER_MS 3000L
56+
57+
#define DEMARRAGE_DESCENTE_HAUT_MER_MS (DEMARRAGE_ROTATION_PONT_MER_MS+DUREE_ROTATION_PONT_MER_MS)
58+
#define DUREE_DESCENTE_HAUT_MER_MS 9000L
59+
60+
#define ATTENTE_AVANT_REMONTEE_MS 6000L /* Exemple d'utilisation d'une temporisation */
61+
62+
#define DEMARRAGE_MONTEE_MER_HAUT_MS (DEMARRAGE_DESCENTE_HAUT_MER_MS+DUREE_DESCENTE_HAUT_MER_MS+ATTENTE_AVANT_REMONTEE_MS)
63+
#define DUREE_MONTEE_MER_HAUT_MS 9000L
64+
65+
#define DEMARRAGE_ROTATION_MER_PONT_MS (DEMARRAGE_MONTEE_MER_HAUT_MS+DUREE_MONTEE_MER_HAUT_MS)
66+
#define DUREE_ROTATION_MER_PONT_MS 3000L
67+
68+
69+
#define DEMARRAGE_DESCENTE_HAUT_PONT_MS (DEMARRAGE_ROTATION_MER_PONT_MS+DUREE_ROTATION_MER_PONT_MS)
70+
#define DUREE_DESCENTE_HAUT_PONT_MS 3000L
71+
72+
#define DEM_ARRET_POUR_CENT 5 /* Pourcentage du mouvement devant etre effectue a mi-vitesse pour demarrage servo et arret servo (Soft start et Soft stop) */
73+
74+
/* Declaration de la table de sequence des mouvements des servo et des actions courtes */
75+
SequenceSt_t SequenceServoEtActionCourte[] PROGMEM = {
76+
ACTION_COURTE_A_EFFECTUER(InverseLed,DEMARRAGE_MONTEE_PONT_HAUT_MS)
77+
/* Montee du Zodiac du pont vers la position haute */
78+
MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(ELEVATION,ELEVATION_POS_PONT,ELEVATION_POS_HAUT,DEMARRAGE_MONTEE_PONT_HAUT_MS,DUREE_MONTEE_PONT_HAUT_MS,DEM_ARRET_POUR_CENT)
79+
/* Rotation Grue du pont vers la mer */
80+
MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(AZIMUT,AZIMUT_POS_PONT,AZIMUT_POS_MER,DEMARRAGE_ROTATION_PONT_MER_MS,DUREE_ROTATION_PONT_MER_MS,DEM_ARRET_POUR_CENT)
81+
/* Descente du Zodiac depuis la position haute vers la la mer */
82+
MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(ELEVATION,ELEVATION_POS_HAUT,ELEVATION_POS_MER,DEMARRAGE_DESCENTE_HAUT_MER_MS,DUREE_DESCENTE_HAUT_MER_MS,DEM_ARRET_POUR_CENT)
83+
ACTION_COURTE_A_EFFECTUER(InverseLed,DEMARRAGE_DESCENTE_HAUT_MER_MS+DUREE_DESCENTE_HAUT_MER_MS)
84+
ACTION_COURTE_A_EFFECTUER(InverseLed,DEMARRAGE_MONTEE_MER_HAUT_MS)
85+
/* Montee du Zodiac de la mer vers la position haute */
86+
MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(ELEVATION,ELEVATION_POS_MER,ELEVATION_POS_HAUT,DEMARRAGE_MONTEE_MER_HAUT_MS,DUREE_MONTEE_MER_HAUT_MS,DEM_ARRET_POUR_CENT)
87+
/* Rotation Grue de la mer vers le pont */
88+
MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(AZIMUT,AZIMUT_POS_MER,AZIMUT_POS_PONT,DEMARRAGE_ROTATION_MER_PONT_MS,DUREE_ROTATION_MER_PONT_MS,DEM_ARRET_POUR_CENT)
89+
/* Descente du Zodiac de la position haute vers le pont */
90+
MVT_AVEC_DEBUT_ET_FIN_MVT_LENTS(ELEVATION,ELEVATION_POS_HAUT,ELEVATION_POS_PONT,DEMARRAGE_DESCENTE_HAUT_PONT_MS,DUREE_DESCENTE_HAUT_PONT_MS,DEM_ARRET_POUR_CENT)
91+
ACTION_COURTE_A_EFFECTUER(InverseLed,DEMARRAGE_DESCENTE_HAUT_PONT_MS+DUREE_DESCENTE_HAUT_PONT_MS)
92+
};
93+
94+
#define LED 13
95+
96+
void setup()
97+
{
98+
#if !defined(__AVR_ATtiny24__) && !defined(__AVR_ATtiny44__) && !defined(__AVR_ATtiny84__) && !defined(__AVR_ATtiny25__) && !defined(__AVR_ATtiny45__) && !defined(__AVR_ATtiny85__)
99+
Serial.begin(9600);
100+
Serial.print("RcSeq library V");Serial.print(RcSeq_LibTextVersionRevision());Serial.print(" demo: RcSeqDemo");
101+
#endif
102+
RcSeq_Init();
103+
104+
/* Declaration des Servos */
105+
RcSeq_DeclareServo(ELEVATION, BROCHE_SIGNAL_SERVO_EL);
106+
RcSeq_DeclareServo(AZIMUT, BROCHE_SIGNAL_SERVO_AZ);
107+
108+
/* Commande d'une action courte et d'une sequence de servos avec 2 BP du clavier de la VOIE1 */
109+
RcSeq_DeclareSignal(RC_VOIE1,BROCHE_SIGNAL_RECEPTEUR_VOIE1);
110+
RcSeq_DeclareClavier(RC_VOIE1, 1000, 2000, NBR_BP);
111+
RcSeq_DeclareCommandeEtActionCourte(RC_VOIE1, BP1, InverseLed);
112+
RcSeq_DeclareCommandeEtSequence(RC_VOIE1, BP2, RC_SEQUENCE(SequenceServoEtActionCourte));
113+
114+
/* Commande d'une action courte et d'une sequence de servos avec le manche de la VOIE2 */
115+
RcSeq_DeclareSignal(RC_VOIE2,BROCHE_SIGNAL_RECEPTEUR_VOIE2);
116+
RcSeq_DeclareManche(RC_VOIE2, 1000, 2000, NBR_POS);
117+
RcSeq_DeclareCommandeEtActionCourte(RC_VOIE2, POS_MINUS1, InverseLed);
118+
RcSeq_DeclareCommandeEtSequence(RC_VOIE2, POS_PLUS1, RC_SEQUENCE(SequenceServoEtActionCourte));
119+
120+
/* Commande d'une action courte et d'une sequence de servos avec le clavier "maison" de la VOIE3 */
121+
RcSeq_DeclareSignal(RC_VOIE3,BROCHE_SIGNAL_RECEPTEUR_VOIE3);
122+
RcSeq_DeclareClavierMaison(RC_VOIE3, RC_CLAVIER_MAISON(ClavierMaison));
123+
RcSeq_DeclareCommandeEtActionCourte(RC_VOIE3, BP_MAISON1, InverseLed);
124+
RcSeq_DeclareCommandeEtSequence(RC_VOIE3, BP_MAISON3, RC_SEQUENCE(SequenceServoEtActionCourte));
125+
126+
pinMode(LED, OUTPUT);
127+
}
128+
129+
void loop()
130+
{
131+
RcSeq_Rafraichit();
132+
}
133+
134+
/* Action associee au BP1 de la VOIE1 ou au manche position basse de la VOIE2 ou au BP_MAISON1 de la VOIE3 */
135+
void InverseLed(void)
136+
{
137+
static boolean Etat=HIGH; /* static, pour conserver l'etat entre 2 appels de la fonction */
138+
digitalWrite(LED, Etat);
139+
Etat=!Etat; /* AU prochain appel de InverseLed(), l'etat de la LED sera inverse */
140+
}

0 commit comments

Comments
 (0)