custom hal component failed to compile, undeclared (first use in this function)

More
21 Dec 2022 15:00 #260018 by andypugh
default. It is the (optional) case for if all other case tests fail.

generally, it prints an error and the what the unhandled progress_level (or whatever) was so that you can debug it.

Please Log in or Create an account to join the conversation.

More
21 Dec 2022 16:48 #260025 by smc.collins
that's what i thought you meant. I'll look over it tonight 

Please Log in or Create an account to join the conversation.

More
22 Dec 2022 02:07 - 22 Dec 2022 02:09 #260056 by smc.collins
ok, I went through and I saw what you were talking about with the loops. coding style matter here to keep things organized with the loops. I moved a lot of the loops around into what seemed like vastly more rationally organized executions for me to keep track of. 

 I think it's almost ready to try now. If you see any glaring error, copy and paste them so I can follow along a bit easier. On a good note, at the end of this there will be a relatively easy to modify turret control that should work on a lot of lathes. 
Attachments:
Last edit: 22 Dec 2022 02:09 by smc.collins.

Please Log in or Create an account to join the conversation.

More
22 Dec 2022 10:36 - 22 Dec 2022 10:37 #260069 by andypugh
Your switch statement is still completely messed up.

Also, your pin decoding is mad.
if (! strobe) position = !bcd1 + 2 * !bcd2 + 4 * !bcd3

(Though I would use the inverted inputs and positive logic in the component)
Last edit: 22 Dec 2022 10:37 by andypugh.

Please Log in or Create an account to join the conversation.

More
22 Dec 2022 13:41 #260079 by smc.collins
exactly how is my switch statement incorrect, because looking at all the books and articles i have here on C, it doesn't.

logically speaking, there's bo difference in either decoding of the switch table, it's exactly the same

the statement

if all these things are true = X.

doesn't change by putting strobe as a condition ahead of the statement.

Please Log in or Create an account to join the conversation.

More
22 Dec 2022 14:03 - 22 Dec 2022 14:17 #260080 by JPL

exactly how is my switch statement incorrect, because looking at all the books and articles i have here on C, it doesn't.

 


First thing I see is that you are using switch statement much like an 'if' statement. You should have only one switch statement, with multiple 'case' under it, not 3 switch statements with each a single 'case'.  This way the program doesn't need to re-evaluates the 'case' 3 times in a row.

Changing the value of the expression evaluated used in the switch make it difficult to clearly follow the logic of the program and is generally considered bad practice. And in this case there is no 'case' for progress_level =3 or progress_level =4,

ref.: www.tutorialspoint.com/cprogramming/switch_statement_in_c.htm

 
Last edit: 22 Dec 2022 14:17 by JPL.
The following user(s) said Thank You: smc.collins

Please Log in or Create an account to join the conversation.

More
22 Dec 2022 14:19 #260081 by Grotius
Hi,

I share a little experience with you.

When coding in .comp language, there is no editor syntax plugin available.
As a result coding is a struggle.
To make life easyer while coding a more complex component i think you can
consider the following :

1. preprocess your component to .c with halcompile. Then use a code editor like qt.
There are example .c components, that are human readable.
The problems you then have is setting the correct
includepath's etc. Then create a makefile wich an sich is quite difficult for a lcnc component.
After the preprocess, you will be able to extend code in the function area.
Then also qt can help you with the "switch case" function. It has build in auto complete for this.

2. A more powerfull way to create a component is using cmake. This is in my view the most
elegant solution to create a component. Where halcompile gives to user power, using the cmake way
gives you full power and a bird eye view right away.

A example for a cmake component (lcnc compatible) :
github.com/grotius-cnc/hal-core-2.0/blob...mponents/test/test.c
A example for lcnc in cmake, including components etc. (good excersize to compile this, and try out a little bit)
github.com/grotius-cnc/linuxcnc

For what i have seen in your last few posts. You could open a new nml channel inside your new component, to
set the initial tool values, or do other nml related things.

Here you can see how to use nml into your component :
github.com/grotius-cnc/linuxcnc/blob/mai...rojects/qt_nml/nml.h

If you want to try it in your current lcnc install. Try to use a example cmakefile.txt for a component and edit the includepath's, libdir's to your needs.

The only thing i can say, have a try. If you got it running, you won't regret the effort.






 

Please Log in or Create an account to join the conversation.

More
22 Dec 2022 18:40 - 22 Dec 2022 18:41 #260091 by andypugh

exactly how is my switch statement incorrect, because looking at all the books and articles i have here on C, it doesn't.


You have "switch(progress_level)" three times.
You do not have the contents of the switch in {braces}

the statement
if all these things are true = X.
doesn't change by putting strobe as a condition ahead of the statement.


No, but my single "if" replaces _all_ of yours.

I am tired of this. I am dropping out of this thread.
Last edit: 22 Dec 2022 18:41 by andypugh.

Please Log in or Create an account to join the conversation.

More
22 Dec 2022 21:21 - 22 Dec 2022 21:26 #260109 by rodw
I am a bit like Andy and don't want to wade in either but I suspect the current decoding algorithm is not a good choice.
So many ways to do this.
I think I would convert bcd1-bcd4 to an integer and use an enum (which might need changing around a bit so the case statement is arranged better.)
I might not quite understand the bcd states, but something like this....

enum tool_state(T0, T1, T2, T3, T4, T5, T6, T7,T8, T9, T10, T11, T12, T13, T14, T15);

/*
Tool States where bcd1 = rightmost (bit0)
T0  = 0000
T1  = 0001
T2  = 0010
T3  = 0011
T4  = 0100
T5  = 0101
T6  = 0110
T7  = 0111
T8  = 1000
T9  = 1001
T10 = 1010
T11 = 1011
T12 = 1100
T13 = 1101
T14 = 1110
T15 = 1111
*/
enum tool_state tool_idx;
tool_idx = (tool_state) bcd1 & (bcd2 << 1) & (bcd3 << 2) & (bcd4 << 3);
if(!strobe){
  switch(tool_idx){
    case T6:        // 0b0110
      position = 1;
      break;
    case T5:
      position = 2; // 0b0101 
      break;
    // .......
  }
}

This should end up with clearer code
Last edit: 22 Dec 2022 21:26 by rodw.
The following user(s) said Thank You: smc.collins

Please Log in or Create an account to join the conversation.

More
24 Dec 2022 01:43 #260209 by smc.collins
I'm not really interested or concerned with writing the smallest possible version of a program, particularly when I am prototyping it. I am absolutely choosing to use a very big version of this truth table until I decide that optimizing it is a priority, which it isn't. What is a priority, is having high legible easy to understand code that is easily readable to look for faults. I do appreciate your input Rod, thank you, I will consider adding the lookup table design at a later date. My comments are not directed at you.

so I decided after wading through more of hal, that it would be easier to train the new GPTchat bot with it. BTW this makes writing components easier as you can sketch your code, explain to the chat bot what you are trying to make and it will help you with debugging, logic etc, and it now knows the hal syntax, or my version of the bot does. It is a tremendous learning aid to say the least.

anyhow. I will be testing this version and the powerchuck comp " which I need to work out the gcode mapping for" once this -4 F weather clears out. powerchuck is a chucker program for hydrualic and pnuematic chucks, very simple clean and elegant. offer manual and gcode control options and is stone simple. I am very suprised no one has posted a chuck control component yet, maybe I missed it ?

For those who have contributed positive and helpful comments, thank you very much for your time it is appreciated greatly.

 
Attachments:

Please Log in or Create an account to join the conversation.

Time to create page: 0.085 seconds
Powered by Kunena Forum