how to change direction of the servo

Moderators: TomKerekes, dynomotion

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: how to change direction of the servo

Post by turbothis » Tue Jul 16, 2019 5:40 pm

OUTSTANDING!
i included a unique CH2 servo tune into each mode and also an enable in the A axis mode

"turning"

Code: Select all

#include "KMotionDef.h"

void main()
{
	    // A  axis / spindle

	ch2->InputMode=ENCODER_MODE;
	ch2->OutputMode=NO_OUTPUT_MODE;
	ch2->Vel=  300000;
	ch2->Accel=100000;
	ch2->Jerk= 2000000;
	ch2->P=10;
	ch2->I=0;
	ch2->D=20;
	ch2->FFAccel=0;
	ch2->FFVel=0;
	ch2->MaxI=200;
	ch2->MaxErr=1e+006;
	ch2->MaxOutput=2000;
	ch2->DeadBandGain=1;
	ch2->DeadBandRange=0;
	ch2->InputChan0=2;
	ch2->InputChan1=2;
	ch2->OutputChan0=5;
	ch2->OutputChan1=4;
	ch2->MasterAxis=-1;
	ch2->LimitSwitchOptions=0x0;
	ch2->SoftLimitPos=1e+030;
	ch2->SoftLimitNeg=-1e+030;
	ch2->InputGain0=-1;
	ch2->InputGain1=1;
	ch2->InputOffset0=0;
	ch2->InputOffset1=0;
	ch2->OutputGain=1;
	ch2->OutputOffset=0;
	ch2->SlaveGain=1;
	ch2->BacklashMode=BACKLASH_OFF;
	ch2->BacklashAmount=0;
	ch2->BacklashRate=0;
	ch2->invDistPerCycle=0.0003662109375;
	ch2->Lead=0;
	ch2->MaxFollowingError=1000000;
	ch2->StepperAmplitude=20;

	ch2->iir[0].B0=1;
	ch2->iir[0].B1=0;
	ch2->iir[0].B2=0;
	ch2->iir[0].A1=0;
	ch2->iir[0].A2=0;

	ch2->iir[1].B0=1;
	ch2->iir[1].B1=0;
	ch2->iir[1].B2=0;
	ch2->iir[1].A1=0;
	ch2->iir[1].A2=0;

	ch2->iir[2].B0=1;
	ch2->iir[2].B1=0;
	ch2->iir[2].B2=0;
	ch2->iir[2].A1=0;
	ch2->iir[2].A2=0;

	DefineCoordSystem(1,-1,0,-1);  // define the coordinate system
}

"indexing"

Code: Select all

#include "KMotionDef.h"

void main()
{
	     // A  axis / spindle
	     
    
    
	
	ch2->InputMode=ENCODER_MODE;
	ch2->OutputMode=NO_OUTPUT_MODE;
	ch2->Vel=  3000;
	ch2->Accel=300000;
	ch2->Jerk= 3000000;
	ch2->P=20;
	ch2->I=0;
	ch2->D=40;
	ch2->FFAccel=0;
	ch2->FFVel=0;
	ch2->MaxI=200;
	ch2->MaxErr=1e+006;
	ch2->MaxOutput=2000;
	ch2->DeadBandGain=1;
	ch2->DeadBandRange=0;
	ch2->InputChan0=2;
	ch2->InputChan1=2;
	ch2->OutputChan0=5;
	ch2->OutputChan1=4;
	ch2->MasterAxis=-1;
	ch2->LimitSwitchOptions=0x0;
	ch2->SoftLimitPos=1e+030;
	ch2->SoftLimitNeg=-1e+030;
	ch2->InputGain0=-1;
	ch2->InputGain1=1;
	ch2->InputOffset0=0;
	ch2->InputOffset1=0;
	ch2->OutputGain=1;
	ch2->OutputOffset=0;
	ch2->SlaveGain=1;
	ch2->BacklashMode=BACKLASH_OFF;
	ch2->BacklashAmount=0;
	ch2->BacklashRate=0;
	ch2->invDistPerCycle=0.0003662109375;
	ch2->Lead=0;
	ch2->MaxFollowingError=1000000;
	ch2->StepperAmplitude=20;

	ch2->iir[0].B0=1;
	ch2->iir[0].B1=0;
	ch2->iir[0].B2=0;
	ch2->iir[0].A1=0;
	ch2->iir[0].A2=0;

	ch2->iir[1].B0=1;
	ch2->iir[1].B1=0;
	ch2->iir[1].B2=0;
	ch2->iir[1].A1=0;
	ch2->iir[1].A2=0;

	ch2->iir[2].B0=1;
	ch2->iir[2].B1=0;
	ch2->iir[2].B2=0;
	ch2->iir[2].A1=0;
	ch2->iir[2].A2=0;
	
	    EnableAxis(2);
	 	DefineCoordSystem(1,-1,0,2);  // define the coordinate system

}

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: how to change direction of the servo

Post by turbothis » Tue Jul 16, 2019 5:50 pm

my last question is how do i include a command to set ch2 to be set to position 0.0 each time i go from index or turning mode?

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: how to change direction of the servo

Post by TomKerekes » Tue Jul 16, 2019 7:58 pm

Hi turbothis,
my last question is how do i include a command to set ch2 to be set to position 0.0 each time i go from index or turning mode?
You might add:

Zero(2);

But are you sure you want to do this? After Jogging as a Spindle the axis is likely to be at some random angle so setting the machine coordinate to zero doesn't seem right. Unless you intend to reference the angle somehow. You might want to set it to a modulo of 360 degrees of where it is, and/or then physically move to zero.
Regards,

Tom Kerekes
Dynomotion, Inc.

turbothis
Posts: 325
Joined: Fri Mar 15, 2019 4:07 pm
Location: southern oregon

Re: how to change direction of the servo

Post by turbothis » Tue Jul 16, 2019 9:28 pm

ya, not 100% what i want or can do yet but just thought it would be nice to switch modes and have it start at 0
thanks

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: how to change direction of the servo

Post by TomKerekes » Tue Jul 16, 2019 9:54 pm

You might try this code to reset A to between 0-360 degrees where it actually is:
(you will need to change CNTS_PER_DEG for whatever your system is)

Code: Select all

#include "KMotionDef.h"

#define CNTS_PER_DEG 1000.0
#define AXISA 2

double modf(double, double *);    // returns integer part with more than 32-bit precision

double floor(double x)            // truncate down toward -infinity
{
    double y;
    return (modf(x, &y) < 0 ? y - 1 : y);
}

void main()
{
    double dest = chan[AXISA].Dest;
    double cnts = CNTS_PER_DEG * 360.0;
    double delta = (floor(dest / cnts)) * cnts;
    WaitNextTimeSlice();        // Avoid interrupts
    DisableAxis(AXISA);
    chan[AXISA].Position -= delta;
    EnableAxisDest(AXISA, dest - delta);
}
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply