Skip to content

Galvo’s movement using the G-Code #16

Open
@jojoxyz

Description

@jojoxyz

Can anyone help me?
This is the code that controls Galvo's movement using the G-Code.
The base code works, but only in a simple form. Galvo jump between positions. It is not possible to control the speed.
I want Galvo to move smoothly. (Code part deactivated) It works in another code, but not in this one. Galvo doesn't move at all.
I don't know what I'm doing wrong.

`#include <gcode.h>
#include <MCP48xx.h>

MCP4822 dac(53); // CS Pin 53

#define LDAC 48 // LDAC Pin
#define Laser 47 // Laser Pin

unsigned int x_i = 0;
unsigned int y_i = 0;
#define F_mSec 10

#define STEPS_MM 10

float stepsx;
float stepsy;

double X;
double Y;

void moviment_0();
void moviment_1();
void gotoLocation();

#define NUMCOMMANDS 2

commandscallback commands[NUMCOMMANDS] = { { "G1",moviment_1} , {"G0", moviment_0} };
gcode Commands(NUMCOMMANDS,commands);

void setup()
{
Commands.begin();

pinMode      ( Laser ,  OUTPUT ) ;
pinMode      ( LDAC  ,  OUTPUT ) ;
digitalWrite ( LDAC  ,     LOW ) ;      

dac.init();
dac.turnOnChannelA();
dac.turnOnChannelB();

digitalWrite( Laser , HIGH );  
delay(500);  
digitalWrite( Laser , LOW );

}

void loop() { Commands.available(); }

void gotoLocation(double x,double y)
{
stepsx = xSTEPS_MM; // In value X mm to DAC Output 0 = 4000mV
stepsy = y
STEPS_MM; // In value Y mm to DAC Output 0 = 4000mV

/*
//#### X
if (stepsx >= x_i ){x_i ++ ; if (x_i >= stepsx) x_i = stepsx; delayMicroseconds(F_mSec); } // Move X ++
else
if (stepsx <= x_i ){x_i -- ; if (x_i <= stepsx) x_i = stepsx; delayMicroseconds(F_mSec); } // Move X --

//#### Y
if (stepsy >= y_i ){y_i ++ ; if (y_i >= stepsy) y_i = stepsy; delayMicroseconds(F_mSec); } // Move Y ++
else
if (stepsy <= y_i ){y_i -- ; if (y_i <= stepsy) y_i = stepsy; delayMicroseconds(F_mSec); } // Move Y --

dac.setVoltageA(x_i);       
dac.setVoltageB(y_i);
dac.updateDAC();

*/
delay(10);

dac.setVoltageA(stepsx);       
dac.setVoltageB(stepsy);      
dac.updateDAC();

}

//### G00
void moviment_0()
{
double new_0_XValue = X;
double new_0_YValue = Y;
if(Commands.availableValue('X')) // ADDED parameter X in G0
new_0_XValue = Commands.GetValue('X');
if(Commands.availableValue('Y')) // ADDED parameter Y in G0
new_0_YValue = Commands.GetValue('Y');

  digitalWrite( Laser , LOW );
  gotoLocation(new_0_XValue,new_0_YValue);

}

//### G01
void moviment_1()
{
double new_1_XValue = X;
double new_1_YValue = Y;
if(Commands.availableValue('X')) // ADDED parameter X in G1
new_1_XValue = Commands.GetValue('X');
if(Commands.availableValue('Y')) // ADDED parameter Y in G1
new_1_YValue = Commands.GetValue('Y');

  digitalWrite( Laser , HIGH );
  gotoLocation(new_1_XValue,new_1_YValue);

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions