Skip to content

Commit cda5631

Browse files
author
Erik Kettenburg
committed
2 parents 8036f1e + da65591 commit cda5631

File tree

35 files changed

+3383
-1064
lines changed

35 files changed

+3383
-1064
lines changed

hardware/digispark/cores/tiny/wiring.c

+15
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,22 @@
4848
#define MILLISTIMER_OVF_vect MILLISTIMER_(OVF_vect)
4949

5050

51+
#define MS_TIMER_TICK_EVERY_X_CYCLES 64 /* Shall be a within 1, 8, 64, 256 or 1024. (default = 64) If set to 1, HW PWM is around [email protected] with Digispark */
52+
5153
#if F_CPU >= 3000000L
54+
#if !defined(MS_TIMER_TICK_EVERY_X_CYCLES)
5255
#define MillisTimer_Prescale_Index MillisTimer_(Prescale_Value_64)
5356
#define MillisTimer_Prescale_Value (64)
5457
#define ToneTimer_Prescale_Index ToneTimer_(Prescale_Value_64)
5558
#define ToneTimer_Prescale_Value (64)
59+
#else
60+
#define Prescaler_Value(Val) PRESCALER_VALUE(Val)
61+
#define PRESCALER_VALUE(Val) Prescale_Value_##Val
62+
#define MillisTimer_Prescale_Index MillisTimer_(Prescaler_Value(MS_TIMER_TICK_EVERY_X_CYCLES))
63+
#define MillisTimer_Prescale_Value (MS_TIMER_TICK_EVERY_X_CYCLES)
64+
#define ToneTimer_Prescale_Index ToneTimer_(Prescaler_Value(MS_TIMER_TICK_EVERY_X_CYCLES))
65+
#define ToneTimer_Prescale_Value (MS_TIMER_TICK_EVERY_X_CYCLES)
66+
#endif
5667
#else
5768
#define MillisTimer_Prescale_Index MillisTimer_(Prescale_Value_8)
5869
#define MillisTimer_Prescale_Value (8)
@@ -140,7 +151,11 @@ unsigned long micros()
140151

141152
SREG = oldSREG;
142153

154+
#if (MillisTimer_Prescale_Value >= clockCyclesPerMicrosecond())
143155
return ((m << 8) + t) * (MillisTimer_Prescale_Value / clockCyclesPerMicrosecond());
156+
#else
157+
return ((m << 8) + t) / (clockCyclesPerMicrosecond() / MillisTimer_Prescale_Value);
158+
#endif
144159
}
145160

146161
void delay(unsigned long ms)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*
2+
Sketch using <RcSeq> library, for automatically dropping a pneumatic Zodiac at sea and returning for it back to the deck of a supply vessel.
3+
The sequence is launched after sending the 'g' (Go) character at the USB interface.
4+
5+
In this example, the declared sequence is:
6+
1) The crane lifts the pneumatic Zodiac from the deck to the air and stops
7+
2) The crane rotates (90°) to locate the pneumatic Zodiac above the sea
8+
3) The crane drops down the pneumatic Zodiac at sea level
9+
4) The crane stops during 6 seconds
10+
5) The crane lifts up the pneumatic Zodiac from sea level to the air and stops
11+
6) The crane rotates (90°) to locate the pneumatic Zodiac above the deck
12+
7) The crane drops down the pneumatic Zodiac on the deck and stops. The sequence ends.
13+
This sequence uses:
14+
- 2 commands from USB interface ('g' and 't' characters from Digiterm or Digi Monitor)
15+
- 2 servos (a "ROTATION" servo for the crane rotation and an "UP/DOWN" servo to drop and lift the pneumatic Zodiac)
16+
17+
IMPORTANT:
18+
=========
19+
For this sketch, which is using <DigiUSB> library:
20+
1) Comment "#define RC_SEQ_WITH_SOFT_RC_PULSE_IN_SUPPORT" in "arduino-1.xx\libraries\RcSeq.h".
21+
This will disable the code to manage incoming RC pulses and save some flash memory.
22+
2) Replace #define RING_BUFFER_SIZE 128 with #define RING_BUFFER_SIZE 32 in "arduino-1.xx\libraries\DigisparkUSB\DigiUSB.h".
23+
3) The sequence will be launch by sending "g" character through USB link (using Digiterm or Digi Monitor).
24+
To check all the sequence is performed asynchronously, you can send 't' to toggle the LED during servo motion!
25+
If step 1) and 2) are not done, this sketch won't compile because won't fit in programm memory of the DigiSpark!
26+
27+
RC Navy 2013
28+
http://p.loussouarn.free.fr
29+
*/
30+
31+
static void ToggleLed(void); /* Declare Short Action: Toggle a LED */
32+
33+
/*************************************************/
34+
/* STEP #1: Include the needed libraries */
35+
/*************************************************/
36+
#include <DigiUSB.h> /* The Servo Sequence will be launched by sending "g" character (Go) at the USB interface */
37+
#include <RcSeq.h>
38+
#include <SoftRcPulseOut.h>
39+
40+
#define LED_PIN 1
41+
42+
/*****************************************************************/
43+
/* STEP #2: Enumeration of the servos used in the sequence */
44+
/*****************************************************************/
45+
enum {ROTATION_SERVO=0, UP_DOWN_SERVO , SERVO_NB};
46+
47+
/*****************************************************************/
48+
/* STEP #3: Servos Digital Pins assignment */
49+
/*****************************************************************/
50+
#define UP_DOWN_SERVO_PIN 2
51+
/* /!\ Do not use Pin 3 (used by USB) /!\ */
52+
/* /!\ Do not use Pin 4 (used by USB) /!\ */
53+
#define ROTATION_SERVO_PIN 5
54+
55+
/**************************************************************************************/
56+
/* STEP #4: Declaration of the angles of the servos for the different motions (in °) */
57+
/**************************************************************************************/
58+
#define UP_DOWN_ON_DECK_POS 120 /* Zodiac on the deck */
59+
#define UP_DOWN_ON_AIR_POS 180 /* Zodiac in the air */
60+
#define UP_DOWN_ON_SEA_POS 0 /* Zodiac at sea level */
61+
62+
#define ROTATION_ABOVE_DECK_POS 90 /* crane at deck side */
63+
#define ROTATION_ABOVE_SEA_POS 0 /* crane at sea side */
64+
65+
66+
/***************************************************************************************************************************************/
67+
/* STEP #5: Do a temporal diagram showing the start up and the duration of each motions of each servo */
68+
/***************************************************************************************************************************************/
69+
/*
70+
All the start up values (time stamp) have as reference the moment of the sequence startup order (t=0).
71+
72+
UP_DOWN_SERVO MOTION ROTATION_SERVO MOTION UP_DOWN_SERVO MOTION NO MOTION MOUVEMENT(WAITING) UP_DOWN_SERVO MOTION ROTATION_SERVO MOTION UP_DOWN_SERVO MOTION
73+
Order <--DECK_TO_AIR_DURATION_MS--> <--DECK_TO_SEA_ROTATION_DURATION_MS--> <--AIR_TO_SEA_FALLING_DURATION_MS--> <--DELAY_BEFORE_RISING_UP_MS--> <--SEA_TO_AIR_RISING_DURATION_MS--> <--SEA_TO_DECK_ROTATION_DURATION_MS--> <--AIR_TO_DECK_FALLING_DURATION_MS-->
74+
|-------------------|-----------------------------|--------------------------------------|------------------------------------|-------------------------------|-----------------------------------|--------------------------------------|-------------------------------------|-->Time Axis
75+
0 START_UP_DECK_TO_AIR_MS START_UP_DECK_TO_SEA_ROTATION_MS START_UP_AIR_TO_SEA_FALLING_MS START_UP_SEA_TO_AIR_RISING_MS START_UP_SEA_TO_DECK_ROTATION_MS START_UP_AIR_TO_DECK_FALLING_MS
76+
*/
77+
78+
/**************************************************************************************************************************************************/
79+
/* STEP #6: With the help of the temporal diagram, declare start up time, the motion duration of servo and optional delay */
80+
/**************************************************************************************************************************************************/
81+
/* Tune below all the motion duration. Do not forget to add a trailer 'UL' for each value to force them in Unsigned Long type */
82+
#define START_UP_DECK_TO_AIR_MS 0UL /* 0 for immediate start up, but you can put a delay here. Ex: 2000UL, will delay the startup of the whole sequence after 2 seconds */
83+
#define DECK_TO_AIR_DURATION_MS 3000UL
84+
85+
#define START_UP_DECK_TO_SEA_ROTATION_MS (START_UP_DECK_TO_AIR_MS + DECK_TO_AIR_DURATION_MS)
86+
#define DECK_TO_SEA_ROTATION_DURATION_MS 3000UL
87+
88+
#define START_UP_AIR_TO_SEA_FALLING_MS (START_UP_DECK_TO_SEA_ROTATION_MS + DECK_TO_SEA_ROTATION_DURATION_MS)
89+
#define AIR_TO_SEA_FALLING_DURATION_MS 9000UL
90+
91+
#define DELAY_BEFORE_RISING_UP_MS 6000UL
92+
93+
#define START_UP_SEA_TO_AIR_RISING_MS (START_UP_AIR_TO_SEA_FALLING_MS + AIR_TO_SEA_FALLING_DURATION_MS + DELAY_BEFORE_RISING_UP_MS)
94+
#define SEA_TO_AIR_RISING_DURATION_MS 9000UL
95+
96+
#define START_UP_SEA_TO_DECK_ROTATION_MS (START_UP_SEA_TO_AIR_RISING_MS + SEA_TO_AIR_RISING_DURATION_MS)
97+
#define SEA_TO_DECK_ROTATION_DURATION_MS 3000UL
98+
99+
100+
#define START_UP_AIR_TO_DECK_FALLING_MS (START_UP_SEA_TO_DECK_ROTATION_MS + SEA_TO_DECK_ROTATION_DURATION_MS)
101+
#define AIR_TO_DECK_FALLING_DURATION_MS 3000UL
102+
103+
/********************************************************************************************************************/
104+
/* STEP #7: Declare here the percentage of motion to be performed at half speed for servo start up and stop */
105+
/********************************************************************************************************************/
106+
#define START_STOP_PER_CENT 5L /* Percentage of motion performed at half speed for servo start and servo stop (Soft start and Soft stop) */
107+
/* Note: due to the lack of programm memory on the DigiSpark, this feature is not used */
108+
109+
/************************************************************************************************************/
110+
/* STEP #11: Use a "SequenceSt_t" structure table to declare the servo sequence */
111+
/* For each table entry, arguments are: */
112+
/* - Servo Index */
113+
/* - Initial Servo Position in ° */
114+
/* - Final Servo Position in ° */
115+
/* - Motion Start Time Stamp in ms */
116+
/* - Motion duration in ms between initial and final position */
117+
/* - Percentage of motion performed at half speed for servo start and servo stop (Soft start and Soft stop) */
118+
/* Note: START_STOP_PER_CENT not used (MOTION_WITHOUT_SOFT_START_AND_STOP() macro used) */
119+
/************************************************************************************************************/
120+
SequenceSt_t ZodiacSequence[] PROGMEM = {
121+
SHORT_ACTION_TO_PERFORM(ToggleLed, START_UP_DECK_TO_AIR_MS) /* Switch ON the Led at the beginning of the sequence */
122+
SHORT_ACTION_TO_PERFORM(ToggleLed, START_UP_AIR_TO_DECK_FALLING_MS+AIR_TO_DECK_FALLING_DURATION_MS) /* Switch OFF the Led at the beginning of the sequence: You are not obliged to put this line at the end of the table */
123+
/* 1) The crane lifts the pneumatic Zodiac from the deck to the air and stops */
124+
MOTION_WITHOUT_SOFT_START_AND_STOP(UP_DOWN_SERVO, UP_DOWN_ON_DECK_POS, UP_DOWN_ON_AIR_POS, START_UP_DECK_TO_AIR_MS, DECK_TO_AIR_DURATION_MS)
125+
/* 2) The crane rotates (90°) to locate the pneumatic Zodiac above the sea */
126+
MOTION_WITHOUT_SOFT_START_AND_STOP(ROTATION_SERVO, ROTATION_ABOVE_DECK_POS, ROTATION_ABOVE_SEA_POS, START_UP_DECK_TO_SEA_ROTATION_MS, DECK_TO_SEA_ROTATION_DURATION_MS)
127+
/* 3) The crane drops down the pneumatic Zodiac at sea level */
128+
MOTION_WITHOUT_SOFT_START_AND_STOP(UP_DOWN_SERVO, UP_DOWN_ON_AIR_POS, UP_DOWN_ON_SEA_POS, START_UP_AIR_TO_SEA_FALLING_MS, AIR_TO_SEA_FALLING_DURATION_MS)
129+
/* 4) The crane stops during 6 seconds and 5) The crane lifts up the pneumatic Zodiac from sea level to the air and stops */
130+
MOTION_WITHOUT_SOFT_START_AND_STOP(UP_DOWN_SERVO, UP_DOWN_ON_SEA_POS, UP_DOWN_ON_AIR_POS, START_UP_SEA_TO_AIR_RISING_MS, SEA_TO_AIR_RISING_DURATION_MS)
131+
/* 6) The crane rotates (90°) to locate the pneumatic Zodiac above the deck */
132+
MOTION_WITHOUT_SOFT_START_AND_STOP(ROTATION_SERVO, ROTATION_ABOVE_SEA_POS, ROTATION_ABOVE_DECK_POS, START_UP_SEA_TO_DECK_ROTATION_MS, SEA_TO_DECK_ROTATION_DURATION_MS)
133+
/* 7) The crane drops down the pneumatic Zodiac on the deck and stops. The sequence ends. */
134+
MOTION_WITHOUT_SOFT_START_AND_STOP(UP_DOWN_SERVO, UP_DOWN_ON_AIR_POS, UP_DOWN_ON_DECK_POS, START_UP_AIR_TO_DECK_FALLING_MS, AIR_TO_DECK_FALLING_DURATION_MS)
135+
};
136+
137+
void setup()
138+
{
139+
pinMode(LED_PIN, OUTPUT);
140+
141+
DigiUSB.begin();
142+
143+
/***************************************************************************/
144+
/* STEP #9: Init <RcSeq> library */
145+
/***************************************************************************/
146+
RcSeq_Init();
147+
148+
/****************************************************************************************/
149+
/* STEP #10: declare the servo command signals with their digital pin number */
150+
/****************************************************************************************/
151+
RcSeq_DeclareServo(UP_DOWN_SERVO, UP_DOWN_SERVO_PIN);
152+
RcSeq_DeclareServo(ROTATION_SERVO, ROTATION_SERVO_PIN);
153+
154+
/**************************************************************************************************************************/
155+
/* STEP #11: declare the sequence command signal (0), the stick level (0), and the sequence to call */
156+
/**************************************************************************************************************************/
157+
RcSeq_DeclareCommandAndSequence(0, 0, RC_SEQUENCE(ZodiacSequence)); /* 0,0 since there's no RC command */
158+
}
159+
160+
void loop()
161+
{
162+
char RxChar;
163+
164+
/***********************************************************************************************************************************/
165+
/* STEP #12: call the refresh function inside the loop() to catch RC commands and to manage the servo positions */
166+
/***********************************************************************************************************************************/
167+
RcSeq_Refresh();
168+
169+
/****************************************************************************************************************/
170+
/* STEP #13: the sequence can be launched directly by calling the RcSeq_LaunchSequence() function */
171+
/****************************************************************************************************************/
172+
if(DigiUSB.available())
173+
{
174+
RxChar=DigiUSB.read();
175+
if(RxChar=='g') /* Go ! */
176+
{
177+
RcSeq_LaunchSequence(ZodiacSequence);
178+
}
179+
if(RxChar=='t') /* Toggle LED ! */
180+
{
181+
RcSeq_LaunchShortAction(ToggleLed); /* You can toggle LED during Servo Motion! */
182+
}
183+
}
184+
DigiUSB.refresh();
185+
}
186+
187+
static void ToggleLed(void)
188+
{
189+
static boolean Status=LOW;
190+
Status=!Status; /* Toggle Status */
191+
digitalWrite(LED_PIN, Status);
192+
}

0 commit comments

Comments
 (0)