Removed all real work, now just echo
This commit is contained in:
@@ -146,7 +146,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// For the example
|
// For the example
|
||||||
#define BASE_PERIOD 40000 // 40000 is max
|
#define BASE_PERIOD 40000
|
||||||
#define SERVO_PERIOD 1000000
|
#define SERVO_PERIOD 1000000
|
||||||
#define JOINT_X_STEPGEN_MAXACCEL 0.0
|
#define JOINT_X_STEPGEN_MAXACCEL 0.0
|
||||||
#define JOINT_Z_STEPGEN_MAXACCEL 0.0
|
#define JOINT_Z_STEPGEN_MAXACCEL 0.0
|
||||||
|
|||||||
@@ -7,12 +7,15 @@ extern "C"
|
|||||||
};
|
};
|
||||||
_Objects Obj;
|
_Objects Obj;
|
||||||
|
|
||||||
|
#define NEEDED 0
|
||||||
|
|
||||||
HardwareSerial Serial1(PA10, PA9);
|
HardwareSerial Serial1(PA10, PA9);
|
||||||
|
|
||||||
volatile uint16_t ALEventIRQ; // ALEvent that caused the interrupt
|
volatile uint16_t ALEventIRQ; // ALEvent that caused the interrupt
|
||||||
HardwareTimer *baseTimer; // The base period timer
|
HardwareTimer *baseTimer; // The base period timer
|
||||||
HardwareTimer *syncTimer; // The timer that syncs "with linuxcnc cycle"
|
HardwareTimer *syncTimer; // The timer that syncs "with linuxcnc cycle"
|
||||||
|
uint16_t sync0CycleTime; // usecs
|
||||||
|
#if NEEDED
|
||||||
#include "MyEncoder.h"
|
#include "MyEncoder.h"
|
||||||
void indexPulseEncoderCB1(void);
|
void indexPulseEncoderCB1(void);
|
||||||
MyEncoder Encoder1(TIM2, PA2, indexPulseEncoderCB1);
|
MyEncoder Encoder1(TIM2, PA2, indexPulseEncoderCB1);
|
||||||
@@ -26,13 +29,13 @@ RunningAverage cycleTimes(1000); // To have a running average of the cycletime o
|
|||||||
#include "StepGen3.h"
|
#include "StepGen3.h"
|
||||||
StepGen3 *Step = 0;
|
StepGen3 *Step = 0;
|
||||||
|
|
||||||
#include "extend32to64.h"
|
|
||||||
|
|
||||||
CircularBuffer<uint64_t, 200> Tim;
|
CircularBuffer<uint64_t, 200> Tim;
|
||||||
|
#endif
|
||||||
|
#include "extend32to64.h"
|
||||||
|
|
||||||
volatile uint64_t irqTime = 0, thenTime = 0, nowTime = 0, irqCnt = 0, prevSyncTime = 0, syncTime = 0, deltaSyncTime;
|
volatile uint64_t irqTime = 0, thenTime = 0, nowTime = 0, irqCnt = 0, prevSyncTime = 0, syncTime = 0, deltaSyncTime;
|
||||||
extend32to64 longTime;
|
extend32to64 longTime;
|
||||||
volatile uint16_t isrTime = 0;
|
|
||||||
void setFrequencyAdjustedMicrosSeconds(HardwareTimer *timer, uint32_t usecs);
|
void setFrequencyAdjustedMicrosSeconds(HardwareTimer *timer, uint32_t usecs);
|
||||||
|
|
||||||
void cb_set_outputs(void) // Master outputs gets here, slave inputs, first operation
|
void cb_set_outputs(void) // Master outputs gets here, slave inputs, first operation
|
||||||
@@ -48,7 +51,7 @@ void cb_set_outputs(void) // Master outputs gets here, slave inputs, first opera
|
|||||||
volatile uint16_t basePeriodCnt;
|
volatile uint16_t basePeriodCnt;
|
||||||
volatile uint64_t makePulsesCnt = 0, prevMakePulsesCnt = 0;
|
volatile uint64_t makePulsesCnt = 0, prevMakePulsesCnt = 0;
|
||||||
volatile uint16_t deltaMakePulsesCnt;
|
volatile uint16_t deltaMakePulsesCnt;
|
||||||
|
#if NEEDED
|
||||||
volatile double pos_cmd1, pos_cmd2;
|
volatile double pos_cmd1, pos_cmd2;
|
||||||
void syncWithLCNC()
|
void syncWithLCNC()
|
||||||
{
|
{
|
||||||
@@ -74,7 +77,7 @@ void basePeriodCB(void)
|
|||||||
else
|
else
|
||||||
baseTimer->pause();
|
baseTimer->pause();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
uint64_t timeDiff; // Timediff in microseconds
|
uint64_t timeDiff; // Timediff in microseconds
|
||||||
int32_t delayT;
|
int32_t delayT;
|
||||||
uint16_t avgCycleTime, thisCycleTime; // In usecs
|
uint16_t avgCycleTime, thisCycleTime; // In usecs
|
||||||
@@ -88,11 +91,13 @@ void handleStepper(void)
|
|||||||
if (oldIrqTime != 0)
|
if (oldIrqTime != 0)
|
||||||
{
|
{
|
||||||
thisCycleTime = irqTime - oldIrqTime;
|
thisCycleTime = irqTime - oldIrqTime;
|
||||||
|
#if NEEDED
|
||||||
cycleTimes.add(thisCycleTime);
|
cycleTimes.add(thisCycleTime);
|
||||||
nLoops = 1 + (irqTime - oldIrqTime) / 960;
|
#endif
|
||||||
|
nLoops = round(float(thisCycleTime) / float(sync0CycleTime));
|
||||||
}
|
}
|
||||||
oldIrqTime = irqTime;
|
oldIrqTime = irqTime;
|
||||||
|
#if NEEDED
|
||||||
if (cycleTimes.bufferIsFull()) // Do max calcs, just waiting a second
|
if (cycleTimes.bufferIsFull()) // Do max calcs, just waiting a second
|
||||||
{
|
{
|
||||||
avgCycleTime = cycleTimes.getFastAverage();
|
avgCycleTime = cycleTimes.getFastAverage();
|
||||||
@@ -103,9 +108,10 @@ void handleStepper(void)
|
|||||||
|
|
||||||
pos_cmd1 = Obj.CommandedPosition1;
|
pos_cmd1 = Obj.CommandedPosition1;
|
||||||
pos_cmd2 = Obj.CommandedPosition2;
|
pos_cmd2 = Obj.CommandedPosition2;
|
||||||
|
#endif
|
||||||
Obj.ActualPosition1 = Obj.CommandedPosition1;
|
Obj.ActualPosition1 = Obj.CommandedPosition1;
|
||||||
Obj.ActualPosition2 = Obj.CommandedPosition2;
|
Obj.ActualPosition2 = Obj.CommandedPosition2;
|
||||||
|
#if NEEDED
|
||||||
Step->stepgen_array[0].pos_scale = -Obj.StepsPerMM1;
|
Step->stepgen_array[0].pos_scale = -Obj.StepsPerMM1;
|
||||||
Step->stepgen_array[1].pos_scale = -Obj.StepsPerMM2;
|
Step->stepgen_array[1].pos_scale = -Obj.StepsPerMM2;
|
||||||
|
|
||||||
@@ -123,18 +129,20 @@ void handleStepper(void)
|
|||||||
{
|
{
|
||||||
syncWithLCNC();
|
syncWithLCNC();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
uint16_t oldCnt = 0;
|
uint16_t oldCnt = 0;
|
||||||
uint64_t startTime = 0;
|
uint64_t startTime = 0;
|
||||||
uint16_t avgTime = 0;
|
uint16_t avgTime = 0;
|
||||||
void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
|
void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
|
||||||
{
|
{
|
||||||
// Obj.IndexStatus = Encoder1.indexHappened();
|
// Obj.IndexStatus = Encoder1.indexHappened();
|
||||||
// Obj.EncPos = Encoder1.currentPos();
|
// Obj.EncPos = Encoder1.currentPos();
|
||||||
// Obj.EncFrequency = Encoder1.frequency(ESCvar.Time);
|
// Obj.EncFrequency = Encoder1.frequency(ESCvar.Time);
|
||||||
// Obj.IndexByte = Encoder1.getIndexState();
|
// Obj.IndexByte = Encoder1.getIndexState();
|
||||||
float_t ap2 = Obj.ActualPosition2;
|
|
||||||
#if 0
|
#if 0
|
||||||
|
float_t ap2 = Obj.ActualPosition2;
|
||||||
|
|
||||||
uint64_t dTim = irqTime - thenTime; // Debug. Getting jitter over the last 200 milliseconds
|
uint64_t dTim = irqTime - thenTime; // Debug. Getting jitter over the last 200 milliseconds
|
||||||
Tim.push(dTim);
|
Tim.push(dTim);
|
||||||
uint64_t max_Tim = 0, min_Tim = UINT64_MAX;
|
uint64_t max_Tim = 0, min_Tim = UINT64_MAX;
|
||||||
@@ -153,15 +161,12 @@ void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
|
|||||||
if (irqCnt == 11000)
|
if (irqCnt == 11000)
|
||||||
avgTime = (irqTime - startTime) / 1000;
|
avgTime = (irqTime - startTime) / 1000;
|
||||||
|
|
||||||
Obj.DiffT = longTime.extendTime(micros()) - irqTime; // max_Tim - min_Tim; // Debug
|
// Obj.DiffT = longTime.extendTime(micros()) - irqTime; // max_Tim - min_Tim; // Debug
|
||||||
uint16_t newCnt = isrTime;
|
|
||||||
// Obj.D1 = newCnt - oldCnt;
|
|
||||||
oldCnt = newCnt;
|
|
||||||
Obj.DiffT = nLoops;
|
Obj.DiffT = nLoops;
|
||||||
Obj.D1 = 1000 * Obj.CommandedPosition2; // abs(1000 * (ap2 - Obj.CommandedPosition2)); // Step2.actPos();
|
Obj.D1 = 1000 * Obj.CommandedPosition2; // abs(1000 * (ap2 - Obj.CommandedPosition2)); // Step2.actPos();
|
||||||
Obj.D2 = 1000 * Step->stepgen_array[1].pos_fb; // Step->stepgen_array[1].rawcount % INT16_MAX; // Step->stepgen_array[1].freq;
|
Obj.D2 = 1000 * Obj.ActualPosition2; // Step->stepgen_array[1].pos_fb; // Step->stepgen_array[1].rawcount % INT16_MAX; // Step->stepgen_array[1].freq;
|
||||||
Obj.D3 = Step->stepgen_array[1].freq;
|
Obj.D3 = nLoops; // Step->stepgen_array[1].freq;
|
||||||
Obj.D4 = deltaMakePulsesCnt; // Step->stepgen_array[1].rawcount % UINT16_MAX;
|
Obj.D4 = 0; // deltaMakePulsesCnt; // Step->stepgen_array[1].rawcount % UINT16_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESC_interrupt_enable(uint32_t mask);
|
void ESC_interrupt_enable(uint32_t mask);
|
||||||
@@ -206,17 +211,18 @@ void setup(void)
|
|||||||
pinMode(PA12, OUTPUT); // Dir X
|
pinMode(PA12, OUTPUT); // Dir X
|
||||||
pinMode(PC9, OUTPUT); // Step Z
|
pinMode(PC9, OUTPUT); // Step Z
|
||||||
pinMode(PC10, OUTPUT); // Dir Z
|
pinMode(PC10, OUTPUT); // Dir Z
|
||||||
|
#if NEEDED
|
||||||
Step = new StepGen3;
|
Step = new StepGen3;
|
||||||
|
|
||||||
baseTimer = new HardwareTimer(TIM11); // The base period timer
|
baseTimer = new HardwareTimer(TIM11); // The base period timer
|
||||||
uint32_t usecs = BASE_PERIOD / 1000;
|
uint32_t usecs = BASE_PERIOD / sync0CycleTime;
|
||||||
// setFrequencyAdjustedMicrosSeconds(baseTimer, usecs);
|
// setFrequencyAdjustedMicrosSeconds(baseTimer, usecs);
|
||||||
baseTimer->setOverflow(20, MICROSEC_FORMAT);
|
baseTimer->setOverflow(20, MICROSEC_FORMAT);
|
||||||
baseTimer->attachInterrupt(basePeriodCB);
|
baseTimer->attachInterrupt(basePeriodCB);
|
||||||
|
|
||||||
syncTimer = new HardwareTimer(TIM3); // The Linuxcnc servo period sync timer
|
syncTimer = new HardwareTimer(TIM3); // The Linuxcnc servo period sync timer
|
||||||
syncTimer->attachInterrupt(syncWithLCNC);
|
syncTimer->attachInterrupt(syncWithLCNC);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(void)
|
void loop(void)
|
||||||
@@ -297,7 +303,7 @@ uint16_t dc_checker(void)
|
|||||||
{
|
{
|
||||||
// Indicate we run DC
|
// Indicate we run DC
|
||||||
ESCvar.dcsync = 1;
|
ESCvar.dcsync = 1;
|
||||||
// StepGen3::sync0CycleTime = ESC_SYNC0cycletime(); // nsecs
|
sync0CycleTime = ESC_SYNC0cycletime() / 1000; // usecs
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user