Multiswitch component, one button multiple outputs

More
18 Dec 2011 10:59 - 20 Dec 2011 09:46 #15803 by ArcEye
Hi

This component just demonstrates a one button toggling switch as discussed in this thread.
Can be expanded for more outputs if required.

www.linuxcnc.org/index.php/english/compo...10&id=10272&start=12

regards

(see post 15809 for updated version)
Attachments:
Last edit: 20 Dec 2011 09:46 by ArcEye.

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

More
18 Dec 2011 11:31 #15805 by BigJohnT
ArcEye,

That is pretty neat! Should that comp be added to master?

John

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

More
18 Dec 2011 12:30 #15806 by Rick G
ArcEye,

Cool, I will have to try that, I am running out of buttons on my joypad.

Rick G

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

More
18 Dec 2011 14:18 #15808 by andypugh
ArcEye wrote:

This component just demonstrates a one button toggling switch as discussed in this thread.
Can be expanded for more outputs if required.


Can we make it take a modparam for number of outputs?

Give me an hour, I will make a version which does it that way for evaluation.

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

More
18 Dec 2011 15:24 - 20 Dec 2011 09:45 #15809 by ArcEye
Hi John

Should that comp be added to master?


I have tested in simulation, setting the pins with halcmd and verifying it cycles and sets flags as it should.

It could do with a real world trial, if Rick is thinking of trying it, I can wait for any feedback first.

I will also wait to see what Andy comes up with, don't know if it is worth a modparam argv / argc type interface when there is only one settable param, but it would make it easier to use and more consistent with other components interfaces I suppose.

regards

Updated version of my offering with toggle set back to input here

File Attachment:

File Name: multiswitc...1dd.comp
File Size:3 KB
Attachments:
Last edit: 20 Dec 2011 09:45 by ArcEye.

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

More
18 Dec 2011 17:25 #15812 by andypugh
andypugh wrote:

[Give me an hour.


Make that three. I got distracted.
The only real advantage to doing it this way is that it supports up to 32 output bits.
It probably needs to support "names=" to be well-behaved component.
/*******************************************************************************

EMC2 HAL component to implement Multistate toggle switch
(c) ArcEye 15122011 schooner30@tiscali.co.uk

example Hal linkages required:-
################################
loadrt multiswitch cfg=4,6,8
addf multiswitch.0 servo-thread
...
net toggle-switch multiswitch.0.toggle <= parport.N.pin-nn-out
net state1 multiswitch.0.state1 => parport.N.pin-nn-in
net state1 multiswitch.0.state2 => parport.N.pin-nn-in
net state1 multiswitch.0.state3 => parport.N.pin-nn-in

If you require an "all off" state, then make the component one bit oversize and
 don't connect the extra pin. 

*******************************************************************************/

component multiswitch           """This component toggles between a specified number of output bits""";

pin in bit up = false           "Receives signal to toggle up";
pin in bit down = false         "Receives signal to toggle down";

param rw unsigned top-position  "Number of positions";
param rw signed position      "Current state (may be set in the HAL)";

pin out bit bit-##[32:personality] = false       "Output bits";

modparam dummy cfg              """cfg should be a comma-separated list of sizes
for example cfg=2,4,6 would create 3 instances of 2, 4 and 6 bits respectively.
 Ignore the "personality" parameter, that is auto-generated""";

function _ ;
option extra_setup yes;
option count_function yes;

variable int old_up = 0;
variable int old_down = 0;

author "ArcEye schooner30@tiscali.co.uk";
license "GPL";
;;

#define MAX_COUNT 32
int cfg[MAX_COUNT];
RTAPI_MP_ARRAY_INT(cfg, MAX_COUNT, "array of function sizes");

FUNCTION(_) {
    int i;
    
    // debounce
    if (up && !old_up) { position++; }
    if (down && !old_down) { position--;}
    old_up = up;
    old_down = down;
    
    if (position < 0) position = top_position;
    if (position > top_position) position = 0;
    
    for (i = 0 ; i < personality; i++){
        bit(i) = (i == position);
    }

}

EXTRA_SETUP(){
    personality = cfg[extra_arg];
    top_position = personality - 1;
    return 0;
}

int get_count(void){
    int i;
    for (i=0; cfg[i] != 0 && i < MAX_COUNT; i++){}
    if (i == 0){
        cfg[0] = 4;
        i = 1;
    }
    return i;
}

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

More
19 Dec 2011 08:45 #15832 by ArcEye
Hi Andy,

Personalities and modparams are not something I have played with yet in .comp programming.
The components I have written have been either, only intended for use as singletons, or I have manually set params etc.

It didn't make complete sense until I expanded the macros and generated a C file.

You polish it and publish as your own, there is nothing in there of mine, save the concept, which is hardly unique.

regards

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

More
19 Dec 2011 10:50 #15834 by andypugh
ArcEye wrote:

It didn't make complete sense until I expanded the macros and generated a C file.


Indeed. I am using at least two undocumented features there.
It is a pity that there is no way to omit "personality" from the auto-generated docs in cases where you are not using it (actually, it would also be nice to be able to alias "personality" to a modparam name of your choosing.
The following user(s) said Thank You: garylogan

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

More
20 Dec 2011 05:14 #15879 by fabworx
where can i find other .comp files i need or2 and probably others not sure yet till i get hal to load past the or2 that i dont have.

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

More
20 Dec 2011 08:11 #15882 by Rick G
You just need to load them with loadrt in your configuration file.

For example

loadrt or2 count=2


loads 2 or2 components.

Some good reading...

linuxcnc.org/docs/2.4/HAL_User_Manual.pdf

Rick G

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

Time to create page: 0.097 seconds
Powered by Kunena Forum