Merge pull request #84 from TimEvWw/master

Encoder positioning test code
pull/88/head
Tim Evers 2017-05-28 23:29:00 +02:00 committed by GitHub
commit 3e37984516
12 changed files with 117 additions and 43 deletions

View File

@ -43,6 +43,7 @@ const int COMM_REPORT_CALIBRATE_STATUS_TO_END = 2;
const int COMM_REPORT_CALIBRATE_STATUS_ERROR = -1;
const int MOVEMENT_INTERRUPT_SPEED = 64; // Interrupt cycle in micro seconds
//const int MOVEMENT_INTERRUPT_SPEED = 50; // Interrupt cycle in micro seconds
const unsigned int MOVEMENT_SPEED_BASE_TIME = 2000;
const unsigned int MOVEMENT_DELAY = 250;
@ -52,6 +53,7 @@ const long PARAM_TEST_DEFAULT = 0;
const long PARAM_CONFIG_OK_DEFAULT = 0;
const long PARAM_USE_EEPROM_DEFAULT = 1;
const long PARAM_E_STOP_ON_MOV_ERR_DEFAULT = 0;
const long MOVEMENT_TIMEOUT_X_DEFAULT = 120;
const long MOVEMENT_TIMEOUT_Y_DEFAULT = 120;

View File

@ -239,7 +239,10 @@ void ParameterList::loadDefaultValue(int id)
paramValues[id] = PARAM_CONFIG_OK_DEFAULT;
break;
case PARAM_USE_EEPROM:
paramValues[id] = PARAM_USE_EEPROM;
paramValues[id] = PARAM_USE_EEPROM_DEFAULT;
break;
case PARAM_E_STOP_ON_MOV_ERR:
paramValues[id] = PARAM_E_STOP_ON_MOV_ERR_DEFAULT;
break;
case MOVEMENT_TIMEOUT_X:
@ -504,6 +507,7 @@ bool ParameterList::validParam(int id)
case PARAM_VERSION:
case PARAM_CONFIG_OK:
case PARAM_USE_EEPROM:
case PARAM_E_STOP_ON_MOV_ERR:
case MOVEMENT_TIMEOUT_X:
case MOVEMENT_TIMEOUT_Y:
case MOVEMENT_TIMEOUT_Z:

View File

@ -15,6 +15,7 @@ enum ParamListEnum
PARAM_TEST = 1,
PARAM_CONFIG_OK = 2,
PARAM_USE_EEPROM = 3,
PARAM_E_STOP_ON_MOV_ERR = 4,
// stepper motor settings

View File

@ -343,6 +343,9 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
checkAxisSubStatus(&axisZ, &axisSubStep[2]);
//checkEncoders();
//axisX.checkTiming();
//axisY.checkTiming();
//axisZ.checkTiming();
if (axisX.isStepDone())
{
@ -1323,6 +1326,10 @@ void StepperControl::handleMovementInterrupt(void)
checkEncoders();
// handle motor timing
axisX.incrementTick();
axisY.incrementTick();
axisZ.incrementTick();
axisX.checkTiming();
axisY.checkTiming();
axisZ.checkTiming();
@ -1330,6 +1337,11 @@ void StepperControl::handleMovementInterrupt(void)
if (debugMessages)
{
i2 = micros();
i3 = i2 - i1;
if (i3 > i4)
{
i4 = i3;
}
}
}
@ -1338,9 +1350,9 @@ void StepperControl::checkEncoders()
// read encoder pins using the arduino IN registers instead of digital in
// because it used much fewer cpu cycles
encoderX.shiftChannels();
encoderY.shiftChannels();
encoderZ.shiftChannels();
//encoderX.shiftChannels();
//encoderY.shiftChannels();
//encoderZ.shiftChannels();
/*
Serial.print("R99");
@ -1356,13 +1368,18 @@ void StepperControl::checkEncoders()
*/
// A=16/PH1 B=17/PH0 AQ=31/PC6 BQ=33/PC4
encoderX.setChannels(PINH & 0x02, PINH & 0x01, PINC & 0x40, PINC & 0x10);
// A=23/PA1 B=25/PA3 AQ=35/PC2 BQ=37/PC0
encoderY.setChannels(PINA & 0x02, PINA & 0x08, PINC & 0x04, PINC & 0x01);
// A=27/PA5 B=29/PA7 AQ=39/PG2 BQ=41/PG0
encoderZ.setChannels(PINA & 0x20, PINA & 0x80, PING & 0x04, PING & 0x01);
encoderX.checkEncoder(PINH & 0x02, PINH & 0x01, PINC & 0x40, PINC & 0x10);
//encoderX.setChannels(PINH & 0x02, PINH & 0x01, PINC & 0x40, PINC & 0x10);
encoderX.readEncoder();
encoderY.readEncoder();
encoderZ.readEncoder();
// A=23/PA1 B=25/PA3 AQ=35/PC2 BQ=37/PC0
encoderY.checkEncoder(PINA & 0x02, PINA & 0x08, PINC & 0x04, PINC & 0x01);
//encoderY.setChannels(PINA & 0x02, PINA & 0x08, PINC & 0x04, PINC & 0x01);
// A=27/PA5 B=29/PA7 AQ=39/PG2 BQ=41/PG0
encoderZ.checkEncoder(PINA & 0x20, PINA & 0x80, PING & 0x04, PING & 0x01);
//encoderZ.setChannels(PINA & 0x20, PINA & 0x80, PING & 0x04, PING & 0x01);
//encoderX.processEncoder();
//encoderY.processEncoder();
//encoderZ.processEncoder();
}

View File

@ -59,7 +59,8 @@ public:
void test2();
unsigned long i1 = 0;
unsigned long i2 = 0;
unsigned long i3 = 0;
unsigned long i4 = 0;
private:
StepperControlAxis axisX;

View File

@ -269,6 +269,14 @@ void StepperControlAxis::checkMovement()
}
}
void StepperControlAxis::incrementTick()
{
if (axisActive)
{
moveTicks++;
}
}
void StepperControlAxis::checkTiming()
{
@ -277,7 +285,7 @@ void StepperControlAxis::checkTiming()
if (axisActive)
{
moveTicks++;
// moveTicks++;
if (moveTicks >= stepOffTick)
{

View File

@ -31,6 +31,7 @@ public:
void enableMotor();
void disableMotor();
void checkMovement();
void incrementTick();
void checkTiming();
void setTicks();

View File

@ -90,6 +90,14 @@ long StepperControlEncoder::currentPositionRaw()
return position * encoderInvert;
}
void StepperControlEncoder::checkEncoder(bool channelA, bool channelB, bool channelAQ, bool channelBQ)
{
shiftChannels();
setChannels(channelA, channelB, channelAQ, channelBQ);
processEncoder();
}
/* Check the encoder channels for movement according to this specification
________ ________
Channel A / \ / \
@ -105,14 +113,14 @@ rotation ----------------------------------------------------->
*/
void StepperControlEncoder::readEncoder()
void StepperControlEncoder::processEncoder()
{
// save the old values, read the new values
// shiftChannels();
// readChannels();
// shiftChannels();
// readChannels();
int delta = 0;
//int delta = 0;
// check for a position change
// no fancy code, just a few simple compares. sorry
@ -120,11 +128,13 @@ void StepperControlEncoder::readEncoder()
// Only detect edges on the A channel when the V channel is high
if (curValChannelB == true && prvValChannelA == false && curValChannelA == true)
{
delta--;
//delta--;
position--;
}
if (curValChannelB == true && prvValChannelA == true && curValChannelA == false)
{
delta++;
//delta++;
position++;
}
/*
@ -163,7 +173,7 @@ void StepperControlEncoder::readEncoder()
}
//*/
position += delta;
//position += delta;
}
void StepperControlEncoder::readChannels()

View File

@ -29,7 +29,8 @@ public:
long currentPosition();
long currentPositionRaw();
void readEncoder();
void checkEncoder(bool channelA, bool channelB, bool channelAQ, bool channelBQ);
void processEncoder();
void readChannels();
void setChannels(bool channelA, bool channelB, bool channelAQ, bool channelBQ);
void shiftChannels();

View File

@ -54,30 +54,30 @@ void interrupt(void)
if (interruptBusy == false)
{
interruptStartTime = micros();
//interruptStartTime = micros();
interruptBusy = true;
StepperControl::getInstance()->handleMovementInterrupt();
// Check the actions triggered once per second
if (interruptSecondTimer >= 1000000 / MOVEMENT_INTERRUPT_SPEED)
{
interruptSecondTimer = 0;
PinGuard::getInstance()->checkPins();
//blinkLed();
}
//if (interruptSecondTimer >= 1000000 / MOVEMENT_INTERRUPT_SPEED)
//{
// interruptSecondTimer = 0;
// PinGuard::getInstance()->checkPins();
// //blinkLed();
//}
interruptStopTime = micros();
//interruptStopTime = micros();
if (interruptStopTime > interruptStartTime)
{
interruptDuration = interruptStopTime - interruptStartTime;
}
//if (interruptStopTime > interruptStartTime)
//{
// interruptDuration = interruptStopTime - interruptStartTime;
//}
if (interruptDuration > interruptDurationMax)
{
interruptDurationMax = interruptDuration;
}
//if (interruptDuration > interruptDurationMax)
//{
// interruptDurationMax = interruptDuration;
//}
interruptBusy = false;
}
@ -141,6 +141,23 @@ void setup()
pinMode(UTM_K, INPUT_PULLUP);
pinMode(UTM_L, INPUT_PULLUP);
// Aux 1 pins to safer state
pinMode(AUX1_00, INPUT_PULLUP);
pinMode(AUX1_01, INPUT_PULLUP);
pinMode(AUX1_57, INPUT_PULLUP);
pinMode(AUX1_58, INPUT_PULLUP);
// Aux 3 pins to safer state
pinMode(AUX3_49, INPUT_PULLUP);
pinMode(AUX3_50, INPUT_PULLUP);
pinMode(AUX3_51, INPUT_PULLUP);
// Aux 4 pins to safer state
pinMode(AUX4_43, INPUT_PULLUP);
pinMode(AUX4_45, INPUT_PULLUP);
pinMode(AUX4_47, INPUT_PULLUP);
pinMode(AUX4_32, INPUT_PULLUP);
//pinMode(SERVO_0_PIN , OUTPUT);
//pinMode(SERVO_1_PIN , OUTPUT);

View File

@ -10,6 +10,10 @@
#define X_ENCDR_A_Q 31
#define X_ENCDR_B_Q 33
#define E_STEP_PIN 26
#define E_DIR_PIN 28
#define E_ENABLE_PIN 24
#define Y_STEP_PIN 60
#define Y_DIR_PIN 61
#define Y_ENABLE_PIN 56
@ -41,10 +45,6 @@
#define UTM_K 52
#define UTM_L 53
#define E_STEP_PIN 26
#define E_DIR_PIN 28
#define E_ENABLE_PIN 24
#define SDPOWER -1
#define SDSS 53
#define LED_PIN 13
@ -61,3 +61,15 @@
#define SERVO_0_PIN 4
#define SERVO_1_PIN 5
#define AUX1_00 0
#define AUX1_01 1
#define AUX1_57 57
#define AUX1_58 58
#define AUX3_49 49
#define AUX3_50 50
#define AUX3_51 51
#define AUX4_43 43
#define AUX4_45 45
#define AUX4_47 47
#define AUX4_32 32

View File

@ -173,7 +173,7 @@
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties vm.programmer_name="avrisp" arduino.upload.port="COM5" />
<UserProperties vm.programmer_name="avrisp" arduino.upload.port="COM6" />
</VisualStudio>
</ProjectExtensions>
</Project>