need serious help again

Moderators: TomKerekes, dynomotion

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

Re: need serious help again

Post by turbothis » Tue Mar 19, 2019 9:41 pm

ok good progress

i got this C program driving the servo on the bench with great performance

Code: Select all

#include "KMotionDef.h"

// Home and set the commutation for a 3 phase brushless motor
// that is driven using two DAC Outputs
//
// Phase rotates until index mark is located and Encoder Zeroed 


// Function definitions

// x must be in the range 0->1 returns sin(x) and sin(x+120 degrees)
float Sine3PH (float x, float *sin2);

// put a voltage v on a 3 Phase motor at specified commutation angle
void Write3PH_DACs(CHAN *ch0, float v, double angle_in_cycles); 

// return fractional part of a huge number accurately
float fractionf(double v);

void main() 
{
	float k=0,A=200;   // set coil current amplitude DAC units
	double p0;

	// define the axis as 3 phase BRUSHLESS_3PH_MODE
	

	ch0->InputMode=ENCODER_MODE;
	ch0->OutputMode=NO_OUTPUT_MODE;
	ch0->Vel=5000;
	ch0->Accel=5000000;
	ch0->Jerk=30000000;
	ch0->P=1;
	ch0->I=0;
	ch0->D=4;
	ch0->FFAccel=0;
	ch0->FFVel=0;
	ch0->MaxI=200;
	ch0->MaxErr=1e+006;
	ch0->MaxOutput=1000;
	ch0->DeadBandGain=1;
	ch0->DeadBandRange=0;
	ch0->InputChan0=0;
	ch0->InputChan1=0;
	ch0->OutputChan0=0;
	ch0->OutputChan1=1;
	ch0->MasterAxis=-1;
	ch0->LimitSwitchOptions=0x0;
	ch0->SoftLimitPos=1e+030;
	ch0->SoftLimitNeg=-1e+030;
	ch0->InputGain0=-1;
	ch0->InputGain1=1;
	ch0->InputOffset0=0;
	ch0->InputOffset1=0;
	ch0->OutputGain=1;
	ch0->OutputOffset=0;
	ch0->SlaveGain=1;
	ch0->BacklashMode=BACKLASH_OFF;
	ch0->BacklashAmount=0;
	ch0->BacklashRate=0;
	ch0->invDistPerCycle=-0.0004;
	ch0->Lead=0;
	ch0->MaxFollowingError=400000000;
	ch0->StepperAmplitude=20;

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

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

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

	// rotate until we find the index mark

	ch0->Enable=FALSE;
	for (;;)
	{
		WaitNextTimeSlice();

		Write3PH_DACs(ch0,A, ++k/1000.0);  // move the pole 

		if (ReadBit(36))  // check for index mark
		{
			p0=ch0->Position; // save position
			ch0->Position=0;  // set current position to Zero

			ch0->CommutationOffset = 658;  // from auto phase find

			printf("Position = %f\n",p0);
			break;
		}
	}

	EnableAxisDest(0,0.0f);  // Enable servo at destination of 0
	DefineCoordSystem(0,-1,-1,-1); // define which axes are in use

	// Loop forever outputting Servo output to dual DAC_SERVO_MODE

	for (;;)
	{
		CHAN *ch=ch0;

		if (ch->Enable)  // if axis enabled commutate and output else command zero to DACs
			Write3PH_DACs(ch, ch->Output, (ch->Position + ch->CommutationOffset) * ch->invDistPerCycle);		
		else
			Write3PH_DACs(ch, 0.0, 0.0);		
	}
}


// put a voltage v on a 3 Phase motor at specified commutation angle
void Write3PH_DACs(CHAN *ch, float v, double angle_in_cycles)
{
	float theta,sin1f;

	if (angle_in_cycles<0)
		theta = 1.0f-fractionf(-angle_in_cycles);
	else
		theta = fractionf(angle_in_cycles);

	DAC(ch->OutputChan0, (int)(v * Sine3PH(theta,&sin1f)));
	DAC(ch->OutputChan1, (int)(v * sin1f));
}


i just did some hand motor tuning in the C program and not in the step/response tab as i could not figure out anything productive in there at all.
the step/response just tests your motor action and then if you like the settings just paste them in the C program right? like i did not skip some step in the middle of this?

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

Re: need serious help again

Post by turbothis » Tue Mar 19, 2019 9:44 pm

TomKerekes wrote:
Tue Mar 19, 2019 9:19 pm
Hi turbothis,

No. To commutate properly all that is required is the encoder counts per cycle. But that is why the report shows the phases going through 4 complete cycles to cause one motor revolution.
so i have some 4 pole servos to use down the road and this would show 2 complete cycles per rev?

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

Re: need serious help again

Post by turbothis » Tue Mar 19, 2019 9:55 pm

i got a small issue with the "step size" feature on the main screen. it does not reflect what i have set in the traj. planner page
in fact when i click the tab to move by the increment it does nothing, on all step settings...

Image

Image

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

Re: need serious help again

Post by TomKerekes » Tue Mar 19, 2019 10:49 pm

Hi turbothis,
ok good progress

i got this C program driving the servo on the bench with great performance
Great :)
i just did some hand motor tuning in the C program and not in the step/response tab as i could not figure out anything productive in there at all.
You should optimize and verify the motor tuning (of all axes) with the Step Response Screen before trying to run KMotionCNC. If you post the results we can help. See also here.
i just did some hand motor tuning in the C program and not in the step/response tab as i could not figure out anything productive in there at all.
the step/response just tests your motor action and then if you like the settings just paste them in the C program right? like i did not skip some step in the middle of this?
That is correct. But I highly recommend using the Step Response Screen instead.
so i have some 4 pole servos to use down the road and this would show 2 complete cycles per rev?
correct
i got a small issue with the "step size" feature on the main screen. it does not reflect what i have set in the traj. planner page
in fact when i click the tab to move by the increment it does nothing, on all step settings...
It seems the Z axis is disabled. Is it included in the Coordinate System? All axes in the Coordinate System must be enabled to do Step Moves.

Note you also might set the Axis Resolutions of unused axes to a non-zero value such as 1000 counts/inch. Zeroes might cause division by zero issues.
Regards,

Tom Kerekes
Dynomotion, Inc.

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

Re: need serious help again

Post by turbothis » Tue Mar 19, 2019 11:04 pm

great
i got some work to do on this and i will get back when i have troubles
thanks

Post Reply