analog axis select
02 Apr 2013 03:35 #32164
by ericson
analog axis select was created by ericson
Hi I have a question about saving inputs.
I have an Arduino connected
and intend to use a rotary selector switch
with resistors,
is it possible to take an analog signal to
for example axis select.
1 volt = x axis, 2 volt = y axis, and so on.
Is there anyone who have a hal example
I would be happy.
I have an Arduino connected
and intend to use a rotary selector switch
with resistors,
is it possible to take an analog signal to
for example axis select.
1 volt = x axis, 2 volt = y axis, and so on.
Is there anyone who have a hal example
I would be happy.
Please Log in or Create an account to join the conversation.
02 Apr 2013 20:01 #32182
by ArcEye
Replied by ArcEye on topic analog axis select
Hi
You probably need to explain exactly what you are looking to do.
On the face of it there is no advantage to generating an analog signal that will need to be converted to get a digital trigger signal,
when you could just apply that signal through your rotary switch.
If it were necessary, the arduino board might be the best way to handle it, triggering different digital outputs based upon the analog voltage read.
regards
You probably need to explain exactly what you are looking to do.
On the face of it there is no advantage to generating an analog signal that will need to be converted to get a digital trigger signal,
when you could just apply that signal through your rotary switch.
If it were necessary, the arduino board might be the best way to handle it, triggering different digital outputs based upon the analog voltage read.
regards
Please Log in or Create an account to join the conversation.
03 Apr 2013 03:09 #32188
by ericson
Replied by ericson on topic analog axis select
I use Jeff Eplers configuration for arduino.
What I was thinking is to connect one analog signal
from the Rotary selector switch and let the hal file
read the float value and change the signal halui.joint.0.select,
to halui.joint.1.select. and so on.
And maybe one analog signal for manual,mdi,auto mode.
If it is possible, it would save many iputs.
I know it is possible to write your own configuration for arduino
but I'm not good at programming.
So I thought there might be a way to do it in the hal file.
What I was thinking is to connect one analog signal
from the Rotary selector switch and let the hal file
read the float value and change the signal halui.joint.0.select,
to halui.joint.1.select. and so on.
And maybe one analog signal for manual,mdi,auto mode.
If it is possible, it would save many iputs.
I know it is possible to write your own configuration for arduino
but I'm not good at programming.
So I thought there might be a way to do it in the hal file.
Please Log in or Create an account to join the conversation.
03 Apr 2013 14:40 #32203
by ArcEye
Replied by ArcEye on topic analog axis select
HAL does not use analogue voltage signals much, then mostly in the area of drive control.
Afraid I think my initial reaction stands, makes little sense to implement an switched analogue signal and then convert it, when what you want is a digital one, which is easily achieved.
You can implement the switching within HAL, using something like the multiswitch component or just have a plain mechanical switch.
The advantage of switching within a component, is that you can connect all the halui........ pins to it directly and the position of the 'switch' determines which is triggered.
Manual, MDI, Auto mode can similarly be toggled in HAL using physical or HAL switches
See this for example
www.linuxcnc.org/index.php/english/forum...t-playing-nice#29216
To get this working, you may need to wet your feet in the programming sea, but I still don't know overall what you are trying to achieve or what part the arduino plays
regards
Afraid I think my initial reaction stands, makes little sense to implement an switched analogue signal and then convert it, when what you want is a digital one, which is easily achieved.
You can implement the switching within HAL, using something like the multiswitch component or just have a plain mechanical switch.
The advantage of switching within a component, is that you can connect all the halui........ pins to it directly and the position of the 'switch' determines which is triggered.
Manual, MDI, Auto mode can similarly be toggled in HAL using physical or HAL switches
See this for example
www.linuxcnc.org/index.php/english/forum...t-playing-nice#29216
To get this working, you may need to wet your feet in the programming sea, but I still don't know overall what you are trying to achieve or what part the arduino plays
regards
Please Log in or Create an account to join the conversation.
03 Apr 2013 22:19 #32227
by ArcEye
Replied by ArcEye on topic analog axis select
Also see
www.linuxcnc.org/index.php/english/forum...ton-multiple-outputs
www.linuxcnc.org/index.php/english/forum...p-holdresume-buttons
www.linuxcnc.org/index.php/english/forum...lood-with-one-button
www.linuxcnc.org/index.php/english/forum...tton-using-one-input
www.linuxcnc.org/index.php/english/forum...ples/10935-lube-pump
Give multiple examples of strategies for switching / toggling using hal components
regards
www.linuxcnc.org/index.php/english/forum...ton-multiple-outputs
www.linuxcnc.org/index.php/english/forum...p-holdresume-buttons
www.linuxcnc.org/index.php/english/forum...lood-with-one-button
www.linuxcnc.org/index.php/english/forum...tton-using-one-input
www.linuxcnc.org/index.php/english/forum...ples/10935-lube-pump
Give multiple examples of strategies for switching / toggling using hal components
regards
Please Log in or Create an account to join the conversation.
04 Apr 2013 02:55 #32244
by ericson
Replied by ericson on topic analog axis select
Thanks for the examples they will be useful.
I complicate it because I've run out of inputs
and would like rotary switches on my machine panel
but should probably reconsider.
look at the picture to see how I thought
Thanks for the replies.
I complicate it because I've run out of inputs
and would like rotary switches on my machine panel
but should probably reconsider.
look at the picture to see how I thought
Thanks for the replies.
Please Log in or Create an account to join the conversation.
04 Apr 2013 17:59 - 04 Apr 2013 23:06 #32268
by ArcEye
Replied by ArcEye on topic analog axis select
Hi
Your picture is fine, as far as it goes.
The only proper way to use an arduino and save on inputs is to have a component that receives the return from the arduino and sets the appropriate pin, connected via HAL, to HIGH.
The arduino will do the ADC (Analogue to Digital Conversion) easily enough into a 10bit ADC
You would need to experiment to determine what value range each pole on the switch resulted in.
The below give an idea of the code required, they compile, but I have not tested the logic.
They may inspire you to get your feet wet on the programming front
ADCsend.pde (arduino script)
ADCreceive.comp (userspace hal component)
regards
Your picture is fine, as far as it goes.
The only proper way to use an arduino and save on inputs is to have a component that receives the return from the arduino and sets the appropriate pin, connected via HAL, to HIGH.
The arduino will do the ADC (Analogue to Digital Conversion) easily enough into a 10bit ADC
You would need to experiment to determine what value range each pole on the switch resulted in.
The below give an idea of the code required, they compile, but I have not tested the logic.
They may inspire you to get your feet wet on the programming front
ADCsend.pde (arduino script)
// Script takes the analogue value of switch pin
// and changes value of buf[0] to indicate
// which axis selection it represents
// Example only - ArcEye 2013
int switchPin = A0; // select the input pin from the switch
float switchValue = 0; // variable to store the value coming from the switch
int Xthreshold, Ythreshold, Zthreshold, Athreshold;
char buf;
void setup() {
// Xthreshold, Ythreshold, Zthreshold, Athreshold need to be determined by
// experimentation with the switch and initialised as the
// value beyond which the next axis is being selected
// Xthreshold = xxx
// Ythreshold = xxx
// Zthreshold = xxx
// Athreshold = xxx
// initialize serial communication:
Serial.begin(9600);
}
void loop()
{
delay(500);
switchValue = analogRead(switchPin);
// if an axis is selected
if(switchValue > 0 && switchValue < Athreshold)
{
buf = 0; // defaults to Off
if(switchValue > 0 && switchValue < Xthreshold)
buf = 1;
else if(switchValue > Xthreshold && switchValue < Ythreshold)
buf = 2;
else if(switchValue > Ythreshold && switchValue < Zthreshold)
buf = 3;
else if(switchValue > Zthreshold && switchValue < Athreshold)
buf = 4;
Serial.print(buf);
}
}
ADCreceive.comp (userspace hal component)
component ADCreceive "Receives serial byte from Arduino running ADC-send.ino and sets selected pin";
pin out bit Offselect = 0 "TRUE if Off";
pin out bit Xselect = 0 "TRUE if X selected";
pin out bit Yselect = 0 "TRUE if Y selected";
pin out bit Zselect = 0 "TRUE if Z selected";
pin out bit Aselect = 0 "TRUE if A selected";
option singleton yes;
option userspace yes;
option extra_setup yes; // use this to open port
option extra_cleanup yes; // use this to close port
author "ArcEye arceye@mgware.co.uk 2013";
license "GPL";
;;
#include <stdio.h> /* Standard input/output definitions */
#include <stdlib.h>
#include <stdint.h> /* Standard types */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
#include <sys/ioctl.h>
#include <sys/signal.h>
#include <sys/types.h>
#define BAUDRATE B9600
#define DEVICE "/dev/ttyUSB0"
int fd; // file descriptor
struct termios oldtio,newtio; // new and saved old port setup
hal_bit_t pins[5];
int setupSerialPort()
{
fd = open(DEVICE, O_RDWR | O_NOCTTY );
if (fd <0)
{
perror(DEVICE);
exit(-1);
}
tcgetattr(fd,&oldtio); /* save current port settings */
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
/* set input mode (non-canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
newtio.c_cc[VMIN] = 5; /* blocking read until 5 chars received */
tcflush(fd, TCIFLUSH);
return( tcsetattr(fd,TCSANOW,&newtio) ); // -1 for error 0 is OK
}
void user_mainloop(void)
{
int c, x;
char ch;
pins[0] = Offselect; pins[1] = Xselect; pins[2] = Yselect; pins[3] = Zselect; pins[4] = Aselect;
while (fd != -1)
{
read(fd,&ch,1);
for(x = 0; x < 5; x++)
{
if(ch == x)
pins[x] = 1;
else
pins[x] = 0;
}
usleep(500000); // 1/2 sec
}
fprintf(stderr, "Exiting");
exit(0);
}
EXTRA_SETUP()
{
if(setupSerialPort() == -1)
{
fprintf(stderr,"Error opening ttyUSB0");
}
}
EXTRA_CLEANUP()
{
tcsetattr(fd, TCSANOW, &oldtio);
close(fd);
fprintf(stderr,"All cleaned up");
}
regards
Last edit: 04 Apr 2013 23:06 by ArcEye. Reason: Tidy typos and logic oops
Please Log in or Create an account to join the conversation.
05 Apr 2013 03:38 #32283
by ericson
Replied by ericson on topic analog axis select
Thanks a lot
I'll try if I can make it work
it will probably take many hours for me.
I'll try if I can make it work
it will probably take many hours for me.
Please Log in or Create an account to join the conversation.
05 Aug 2013 05:16 #37403
by jorgea
Replied by jorgea on topic analog axis select
Have you fixed this problem?
Please Log in or Create an account to join the conversation.
06 Aug 2013 19:12 #37434
by andypugh
Replied by andypugh on topic analog axis select
I only just spotted this thread.
I thought that the Arduino interface from Jeff already handle analogue input, so shouldn't it be possible to just use a wcomp component in HAL for each desired voltage range to set the associated HAL pin?
I thought that the Arduino interface from Jeff already handle analogue input, so shouldn't it be possible to just use a wcomp component in HAL for each desired voltage range to set the associated HAL pin?
Please Log in or Create an account to join the conversation.
Time to create page: 0.169 seconds