Axes Not Responding in C Program

Moderators: TomKerekes, dynomotion

Post Reply
egreenberg
Posts: 6
Joined: Fri Jun 26, 2020 3:18 pm

Axes Not Responding in C Program

Post by egreenberg » Tue Jul 07, 2020 4:08 pm

I'm trying to get a simple C program up and running to control 2 stepper motors to test something. I have 2 Ksteps attached to my Kflop and I am trying to control the motors connected to channels 2 and 7. I have successfully written and tested code to control 5 motors in the past. For whatever reason, my much simpler code to control channels 2 and 7 does no work. It compiles and runs, but the motors to not respond. What I want to happen is for the motors to jog while a button is pushed. I have confirmed from the Digital I/O screen that the button presses are registering. I'm sure that I am doing something stupid...thanks in advance!

Code: Select all

#include "KMotionDef.h"

main()
{
	KStepPresent=TRUE; //which tells KFLOP that KSTEP is connected
	FPGA(KAN_TRIG_REG)=4; //Mux PWM0 to JP7 Pin5 IO 44 for KSTEP
	FPGA(STEP_PULSE_LENGTH_ADD) = 63 + 0x80; //which sets polarity and pulse length to 4us

	ch2->InputMode=NO_INPUT_MODE;
	ch2->OutputMode=STEP_DIR_MODE;
	ch2->Vel=60000;
	ch2->Accel=600000;
	ch2->Jerk=4e+06;
	ch2->P=0;
	ch2->I=0.01;
	ch2->D=0;
	ch2->FFAccel=0;
	ch2->FFVel=0;
	ch2->MaxI=200;
	ch2->MaxErr=1e+06;
	ch2->MaxOutput=200;
	ch2->DeadBandGain=1;
	ch2->DeadBandRange=0;
	ch2->InputChan0=0;
	ch2->InputChan1=0;
	ch2->OutputChan0=10;
	ch2->OutputChan1=0;
	ch2->MasterAxis=-1;
	ch2->LimitSwitchOptions=0x100;
	ch2->LimitSwitchNegBit=0;
	ch2->LimitSwitchPosBit=0;
	ch2->SoftLimitPos=1e+09;
	ch2->SoftLimitNeg=-1e+09;
	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=1;
	ch2->Lead=0;
	ch2->MaxFollowingError=1000000000;
	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=0.000769;
	ch2->iir[2].B1=0.001538;
	ch2->iir[2].B2=0.000769;
	ch2->iir[2].A1=1.92076;
	ch2->iir[2].A2=-0.923833;

	EnableAxisDest(2, 0);
	
	ch7->InputMode=NO_INPUT_MODE;
	ch7->OutputMode=STEP_DIR_MODE;
	ch7->Vel=40000;
	ch7->Accel=400000;
	ch7->Jerk=4e+06;
	ch7->P=0;
	ch7->I=0.1;
	ch7->D=0;
	ch7->FFAccel=0;
	ch7->FFVel=0;
	ch7->MaxI=200;
	ch7->MaxErr=1e+06;
	ch7->MaxOutput=200;
	ch7->DeadBandGain=1;
	ch7->DeadBandRange=0;
	ch7->InputChan0=0;
	ch7->InputChan1=1;
	ch7->OutputChan0=15;
	ch7->OutputChan1=1;
	ch7->MasterAxis=-1;
	ch7->LimitSwitchOptions=0x100;
	ch7->LimitSwitchNegBit=0;
	ch7->LimitSwitchPosBit=0;
	ch7->SoftLimitPos=1e+09;
	ch7->SoftLimitNeg=-1e+09;
	ch7->InputGain0=1;
	ch7->InputGain1=1;
	ch7->InputOffset0=0;
	ch7->InputOffset1=0;
	ch7->OutputGain=1;
	ch7->OutputOffset=0;
	ch7->SlaveGain=1;
	ch7->BacklashMode=BACKLASH_OFF;
	ch7->BacklashAmount=0;
	ch7->BacklashRate=0;
	ch7->invDistPerCycle=1;
	ch7->Lead=0;
	ch7->MaxFollowingError=10000000;
	ch7->StepperAmplitude=250;

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

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

	ch7->iir[2].B0=1;
	ch7->iir[2].B1=0;
	ch7->iir[2].B2=0;
	ch7->iir[2].A1=0;
	ch7->iir[2].A2=0;
	EnableAxisDest(7, 0);
	
	DefineCoordSystem(2, 7, -1, -1);
	SetBitDirection(45, 1);
	SetBit(45);
	SetBitDirection(18, 0);
	while(1)
	{
		while(ReadBit(18))
		{
			Jog(2, 300);
			Jog(7, 10000);
		}
		Jog(2, 0);
		Jog(7, 0);
	}
	
}

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

Re: Axes Not Responding in C Program

Post by TomKerekes » Tue Jul 07, 2020 4:58 pm

Hi egreenberg,

Commanding Jogs continuously is not handled well by KFLOP. A Jog command while an axis is in motion involves a complex 3rd order blended trajectory from the current state (acceleration and velocity) to the desired new velocity while simultaneously ramping to zero acceleration which involves some calculation time. Commanding Jogs continuously basically results in all calculations and little time for motion. Only one Jog command needs to be commanded to Jog at some speed.

There is a Debounce() function that is used in many of the examples to detect when a button is pushed and when it is released you may find helpful. It returns 1 when an input does a valid transition to 1, 0 for a valid transition to 0, and -1 otherwise.

HTH
Regards,

Tom Kerekes
Dynomotion, Inc.

egreenberg
Posts: 6
Joined: Fri Jun 26, 2020 3:18 pm

Re: Axes Not Responding in C Program

Post by egreenberg » Tue Jul 07, 2020 6:03 pm

Thanks for your quick reply. I will implement that routine. Unfortunately, I don't think that is the (only) problem: if i remove any while loops and jog commands, and add instead a simple move command, the motors still do not respond. I can hear them become energized when the amplifiers turn on, but they don't move. Controlling them directly from console does work.

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

Re: Axes Not Responding in C Program

Post by TomKerekes » Tue Jul 07, 2020 7:11 pm

Hi egreenberg,

Hmmm. I don't see anything else wrong.

Can you show the Console Commands that work and the code that doesn't?
Regards,

Tom Kerekes
Dynomotion, Inc.

egreenberg
Posts: 6
Joined: Fri Jun 26, 2020 3:18 pm

Re: Axes Not Responding in C Program

Post by egreenberg » Tue Jul 07, 2020 7:20 pm

If I use any of the Jog(<2 or 7>, <velocity>) or Move(<2 or 7>, <steps>) in C, the motors do not respond.

If in console, I use Jog<2 or 7>=<velocity> or Move<2 or 7>=<steps> things work...

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

Re: Axes Not Responding in C Program

Post by TomKerekes » Tue Jul 07, 2020 7:59 pm

Hi egreenberg,

I don't know. Please post the complete C Program used to Initialize and the complete C Program used to Jog.

Do you have anything Flashed to KFLOP? If so re-Flash New Version to remove it.

Please do the following:

#1 cycle power on KFLOP
#2 compile/execute/run the initialization C Program in Thread #1
#3 compile/execute/run C Program to Jog in Thread #2

Did motor move? Does motor have holding torque? Is Bit 45 on? What does KMotion Axis Screen show
Regards,

Tom Kerekes
Dynomotion, Inc.

egreenberg
Posts: 6
Joined: Fri Jun 26, 2020 3:18 pm

Re: Axes Not Responding in C Program

Post by egreenberg » Tue Jul 07, 2020 9:28 pm

Hi Tom,

I reflashed Kflop and now everything is working as expected. Thanks!

Post Reply