Works with simple/no kinematics

This commit is contained in:
IMback 2017-09-19 16:16:54 +02:00
parent dd6f37a960
commit 471d018bfe
7 changed files with 221 additions and 245 deletions

View file

@ -1,11 +1,10 @@
#include "plotter.h"
const int SCALEX=5;
const int SCALEY=5;
const int SCALEX=2;
const int SCALEY=3;
Plotter::Plotter(volatile unsigned char *penPort, const char penPin, Serial* serial): _pwm( &TCCR1A, &TCCR1B, &OCR1A, &OCR1B, &ICR1, 0b00000001)
Plotter::Plotter(volatile unsigned char *penPort, const char penPin): _pwm( &TCCR1A, &TCCR1B, &OCR1A, &OCR1B, &ICR1, 0b00000001)
{
_serial=serial;
_penPort=penPort;
_penPin=penPin;
basicposition();
@ -34,16 +33,20 @@ void Plotter::basicposition()
void Plotter::pd()
{
_delay_us(1000);
writePin(_penPort, _penPin, true);
_delay_us(1000);
if(!readPin(_penPort, _penPin))
{
writePin(_penPort, _penPin, true);
_delay_us(500);
}
}
void Plotter::pu()
{
_delay_us(1000);
if(readPin(_penPort, _penPin))
{
writePin(_penPort, _penPin, false);
_delay_us(1000);
_delay_us(500);
}
}
void Plotter::moveto(Point *pt)
@ -56,7 +59,7 @@ void Plotter::moveto(const uint16_t nx, const uint16_t ny)
int deltaX = nx - currentPos.x; //-5100
int deltaY = ny - currentPos.y; //0
int steps;
int steps = 0;
int32_t StepSizeX=0;
int32_t StepSizeY=0;
@ -77,13 +80,20 @@ void Plotter::moveto(const uint16_t nx, const uint16_t ny)
{
_pwm.setDutyA(65535-(currentPos.x+i*StepSizeX)*SCALEX);
_pwm.setDutyB(65535-(currentPos.y+i*StepSizeY)*SCALEY);
_delay_us(10000);
_delay_us(5000);
}
_pwm.setDutyA(65535-nx*SCALEX);
_pwm.setDutyB(65535-ny*SCALEY);
if( abs((currentPos.x+steps*StepSizeX) - nx) > 10 || abs((currentPos.y+steps*StepSizeY) - ny) > 10 ) _delay_us(200000);
_delay_us(10000);
if(steps < 50) for(int i = 0; i < steps; i++)_delay_us(11000);
else if(steps < 5) _delay_us(10000*5);
else _delay_us(200000);
//_delay_us(500000);
//else _delay_us(10000);
currentPos.x = nx;
currentPos.y = ny;