G-codes/offsets/tools with .Net

Moderators: TomKerekes, dynomotion

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

Re: G-codes/offsets/tools with .Net

Post by TomKerekes » Thu Feb 08, 2024 12:07 am

ok thanks.

Added to comment:

Code: Select all

        /// To set int value in KFLOP in C do:
        /// persist.UserData[index] = i;
Regards,

Tom Kerekes
Dynomotion, Inc.

Moray
Posts: 298
Joined: Thu Apr 26, 2018 10:16 pm

Re: G-codes/offsets/tools with .Net

Post by Moray » Sun Mar 17, 2024 9:02 pm

Latest update on this, is I'm 95% happy with my screen designer (I have added buttons to move controls a chosen distance, however I need to split up another function to implement the code).

However, I have (probably foolishly!) gained another full time job, along with some more part time work, so my time to do any work to this is now non-existent for the foreseeable future :(
So If anybody would like access to the source code, let me know your GitHub user details, and I can add you as a collaborator.

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

Re: G-codes/offsets/tools with .Net

Post by TomKerekes » Mon Mar 18, 2024 11:59 pm

Hi Moray,

Sounds like good news for you, bad news for us :)

Is there a reason you don't just make it public?
Regards,

Tom Kerekes
Dynomotion, Inc.

Moray
Posts: 298
Joined: Thu Apr 26, 2018 10:16 pm

Re: G-codes/offsets/tools with .Net

Post by Moray » Thu Mar 21, 2024 9:16 pm

TomKerekes wrote:
Mon Mar 18, 2024 11:59 pm
Hi Moray,

Sounds like good news for you, bad news for us :)

Is there a reason you don't just make it public?
There's some code/functionality that I don't really want to make public yet.
The main bit is I started work on making the main init.c being automatically generated a while ago, and I can't actually remember how far I got with that as it's so long ago, so I'd want to at least strip that code out. However I just don't have the time to do so.
Plus there's a few sections that still need tidied up, with some functions needing split out more to make more sense (the main screen designer function is currently somewhat unwieldy!)

Moray
Posts: 298
Joined: Thu Apr 26, 2018 10:16 pm

Re: G-codes/offsets/tools with .Net

Post by Moray » Tue Dec 10, 2024 10:31 pm

So after a bit of a hiatus from working on this, I've spent the past few weeks working on one of the things I've wanted to code for a while, the ability to create an Init file, without having to write/copy/paste/edit any C.

This code has been created using the functionality-

Code: Select all

//KMoCNC Autogenerated Init file
#include "KMotionDef.h"

int main()
{
	
	ch0->InputMode = NO_INPUT_MODE;
	ch0->OutputMode = STEP_DIR_MODE;
	ch0->Vel = 40000;
	ch0->Accel = 400000;
	ch0->Jerk = 4000000;
	ch0->P = 0;
	ch0->I = 0.01;
	ch0->D = 0;
	ch0->FFAccel = 0;
	ch0->FFVel = 0;
	ch0->MaxI = 200;
	ch0->MaxErr = 1000000;
	ch0->MaxOutput = 200;
	ch0->DeadBandGain = 1;
	ch0->DeadBandRange = 0;
	ch0->InputChan0 = 0;
	ch0->InputChan1 = 0;
	ch0->OutputChan0 = 18;
	ch0->OutputChan1 = 0;
	ch0->MasterAxis = -1;
	ch0->LimitSwitchOptions = 0x0;
	ch0->LimitSwitchNegBit = 0;
	ch0->LimitSwitchPosBit = 0;
	ch0->SoftLimitPos = 1000000000;
	ch0->SoftLimitNeg = -1000000000;
	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 = 1;
	ch0->Lead = 0;
	ch0->MaxFollowingError = 1000000000;
	ch0->StepperAmplitude = 0;
	
	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 = 0.000768788;
	ch0->iir[2].B1 = 0.00153758;
	ch0->iir[2].B2 = 0.000768788;
	ch0->iir[2].A1 = 1.92076;
	ch0->iir[2].A2 = -0.923833;
	
	EnableAxis(0)
	
	
	ch1->InputMode = ENCODER_MODE;
	ch1->OutputMode = NO_OUTPUT_MODE;
	ch1->Vel = 40000;
	ch1->Accel = 400000;
	ch1->Jerk = 4000000;
	ch1->P = 0;
	ch1->I = 0.01;
	ch1->D = 0;
	ch1->FFAccel = 0;
	ch1->FFVel = 0;
	ch1->MaxI = 200;
	ch1->MaxErr = 1000000;
	ch1->MaxOutput = 200;
	ch1->DeadBandGain = 1;
	ch1->DeadBandRange = 0;
	ch1->InputChan0 = 1;
	ch1->InputChan1 = 0;
	ch1->OutputChan0 = 1;
	ch1->OutputChan1 = 0;
	ch1->MasterAxis = -1;
	ch1->LimitSwitchOptions = 0x0;
	ch1->LimitSwitchNegBit = 0;
	ch1->LimitSwitchPosBit = 0;
	ch1->SoftLimitPos = 1000000000;
	ch1->SoftLimitNeg = -1000000000;
	ch1->InputGain0 = 1;
	ch1->InputGain1 = 1;
	ch1->InputOffset0 = 0;
	ch1->InputOffset1 = 0;
	ch1->OutputGain = 1;
	ch1->OutputOffset = 0;
	ch1->SlaveGain = 1;
	ch1->BacklashMode = BACKLASH_OFF;
	ch1->BacklashAmount = 0;
	ch1->BacklashRate = 0;
	ch1->invDistPerCycle = 1;
	ch1->Lead = 0;
	ch1->MaxFollowingError = 1000000000;
	ch1->StepperAmplitude = 0;
	
	ch1->iir[0].B0 = 1;
	ch1->iir[0].B1 = 0;
	ch1->iir[0].B2 = 0;
	ch1->iir[0].A1 = 0;
	ch1->iir[0].A2 = 0;
	
	ch1->iir[1].B0 = 1;
	ch1->iir[1].B1 = 0;
	ch1->iir[1].B2 = 0;
	ch1->iir[1].A1 = 0;
	ch1->iir[1].A2 = 0;
	
	ch1->iir[2].B0 = 0.000768788;
	ch1->iir[2].B1 = 0.00153758;
	ch1->iir[2].B2 = 0.000768788;
	ch1->iir[2].A1 = 1.92076;
	ch1->iir[2].A2 = -0.923833;
	
	EnableAxisDest(1,ch1->Position)
	
	
	ch2->InputMode = NO_INPUT_MODE;
	ch2->OutputMode = NO_OUTPUT_MODE;
	ch2->Vel = 40000;
	ch2->Accel = 400000;
	ch2->Jerk = 4000000;
	ch2->P = 0;
	ch2->I = 0.01;
	ch2->D = 0;
	ch2->FFAccel = 0;
	ch2->FFVel = 0;
	ch2->MaxI = 200;
	ch2->MaxErr = 1000000;
	ch2->MaxOutput = 200;
	ch2->DeadBandGain = 1;
	ch2->DeadBandRange = 0;
	ch2->InputChan0 = 2;
	ch2->InputChan1 = 0;
	ch2->OutputChan0 = 2;
	ch2->OutputChan1 = 0;
	ch2->MasterAxis = -1;
	ch2->LimitSwitchOptions = 0x0;
	ch2->LimitSwitchNegBit = 0;
	ch2->LimitSwitchPosBit = 0;
	ch2->SoftLimitPos = 1000000000;
	ch2->SoftLimitNeg = -1000000000;
	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.000768788;
	ch2->iir[2].B1 = 0.00153758;
	ch2->iir[2].B2 = 0.000768788;
	ch2->iir[2].A1 = 1.92076;
	ch2->iir[2].A2 = -0.923833;
	
	
	

	DefineCoordSystem(0, 1, 2, -1);	//Define axes
	for (;;)
	{
	}
}
To use the Init builder functionality, copy the attached ZIP file contents to the Release directory of your KMotion install (currently C:\KMotion5.3.6\KMotion\Release), and run KMoCNC.
You'll be greeted by a popup saying "Failed to open Config File", click OK and the default will be created, and then the garish default screen should appear (the default screen is hardcoded, and is on my todo list to make less garish, now I know that functionality works!).

Click the Config Tab at the top, then on the Machine Config row, click New to create a new Machine Config profile.
Then click Edit, which will open the MachineConfig window.

At the moment, all you need to do is set the channels on the Config tab, along with the C directory (you don't have to set the directory, if you don't want any files written).
Then on the Channels tab, configure each channel (The limit switch functionality hasn't been added yet), which is a similar layout to KMotion, with the exception of the Enable drop down menu in the top right. For those familiar with KMotion, the options should be apparent.
Then finally, on the C Output tab, click the Generate Init buttong. This will create the C code in the window, and if the C directory has been set on the Config tab, create an init.c file in that directory.

As for the other functionality, on the Config tab, you can select your mainboard, and add Expansion boards (only Kanalog and Konnect have been added so far). This will then create a TreeView off all connectors, with details of every pin.
The next step is to have any Expansion boards added to the init.c, so you can create a basic init file to customise.
MachineConfig.png
Attachments
KMoCNC_241210.zip
(1.2 MiB) Downloaded 18 times

Moray
Posts: 298
Joined: Thu Apr 26, 2018 10:16 pm

Re: G-codes/offsets/tools with .Net

Post by Moray » Fri Jan 17, 2025 1:43 am

So I've been working on this whenever I get some time, and have now added the next few bits of functionality, and fixed a significant bug in the previous version.
250117_MachineConfigTree.png
+ Any pins used by channels, are now highlighted with a grey background in the Tree View.
+ You can now add a description, and if needed, a Definition to each pin, along with a description.
Any definitions added, will be added to the init.c
Description is purely for your own reference purposes.
+ Should a pin be used by a channel, and you also set a custom name/definition for it, it will be highlighted in red.
+ Any Konnect boards added, will now add the relevant code to the init.C to enable them.

And the big bug fix was on the channel configuration page.
I had wrongly coded it so the channel output options were configured based on the channel number, and not the output channel number.

Couple current limitations are-
- Output pins are only highlighted for channels where the output mode is Step/Dir, and only for OutputChan0
- Input pins are only highlighted for channels where the input mode is Encoder, and only for InputChan0

Next plans are to get the final bits of channel configuration functionality added (limit switches, and filters), and have any pin definitions output to a separate .h file
Then I hope to get back into the core functionality.

Note - Anybody trying to use any previously created MachineConfig files might find they either crash or fail to load. I changed the structure, and I think any issues should be caught and fail to load any old config files, but there is a possibility I've not caught all the changes.
Attachments
KMoCNC_250117.zip
(1.2 MiB) Downloaded 3 times

Post Reply