create GUI and use hal library!
- veroski
- Topic Author
- Offline
- New Member
Less
More
- Posts: 13
- Thank you received: 1
22 Mar 2021 18:14 #203274
by veroski
create GUI and use hal library! was created by veroski
Hello everybody. i am new to linuxcnc and i have a question for you. can i create a GUI and use linucnc libraries and then hal? I would like to control my parallel port stepper motors at the moment using my graphical interface. I have the basic knowledge of c. can you give me some ideas? which manual to follow or documentation? thank you
Please Log in or Create an account to join the conversation.
- Grotius
- Offline
- Platinum Member
Less
More
- Posts: 2251
- Thank you received: 1990
22 Mar 2021 19:12 - 22 Mar 2021 19:27 #203283
by Grotius
Replied by Grotius on topic create GUI and use hal library!
Hi,
i am new to linuxcnc
Welcome at the linuxcnc forum. You can start with c. But you better start with c++ right away, unless
you want to become the kernel module specialist of this forum. Then please stay at c.
Anyway i hope you will enjoy it over here for many years to come !!
If you install linuxcnc, you have hal working.
You don't have to use linuxcnc in fact, you can only profit from the hal environment this way.
Then create hal file with stepgenerator, ltp port(s) etc.
Test this hal file with existing linuxcnc solutions, to be sure the halfile is ok.
You can also let linuxcnc stepconf. wizard produce a halfile for you. Ltp halfile's work trough this way.
Then connect your c app to hal and you are ready.
This is a c++ example. But for c you know what to do.
Use compile flags. And be sure you have linuxcnc build from source. (dev)
This should be oke to compile your c app.
header file :
source file :
In the source file. First a user hal component is made.
When this is okey at the end. It load's your halfile.
Then everything is working.
So realize yourself this is a 2 stage HAL startup sequence.
Oke good luck !!
i am new to linuxcnc
Welcome at the linuxcnc forum. You can start with c. But you better start with c++ right away, unless
you want to become the kernel module specialist of this forum. Then please stay at c.
Anyway i hope you will enjoy it over here for many years to come !!
If you install linuxcnc, you have hal working.
You don't have to use linuxcnc in fact, you can only profit from the hal environment this way.
Then create hal file with stepgenerator, ltp port(s) etc.
Test this hal file with existing linuxcnc solutions, to be sure the halfile is ok.
You can also let linuxcnc stepconf. wizard produce a halfile for you. Ltp halfile's work trough this way.
Then connect your c app to hal and you are ready.
This is a c++ example. But for c you know what to do.
Use compile flags. And be sure you have linuxcnc build from source. (dev)
This should be oke to compile your c app.
Warning: Spoiler!
INCLUDEPATH += /usr/include/ \
/usr/share/ethercat/oce/inc/ \
/usr/local/include/oce/ \
/usr/local/include/kdl/ \
/usr/include/eigen3/ \
/usr/local/lib/ \
LIBS += -L/usr/local/lib/ \
INCLUDEPATH += /usr/lib/ \
/usr/lib/linuxcnc/modules/ \
/usr/include/ \
/usr/include/linuxcnc/
LIBS += -llinuxcnchal -Iinclude -Isrc/emc/rs274ngc -Llib -lnml -llinuxcnc -llinuxcnchal -llinuxcncini -lposemath
header file :
Warning: Spoiler!
#ifndef HALIO_H
#define HALIO_H
#ifndef ULAPI
#define ULAPI
#endif
//! Hal:
#include "hal.h"
typedef struct {
hal_float_t *Pin;
} float_data_t;
typedef struct {
hal_bit_t *Pin;
} bit_data_t;
//! Various c++ includes:
#include <iostream>
#include <list>
#include <vector>
extern int comp_id;
//! These list's are storing the hal pin's by index:
extern std::vector<float_data_t*> FloatOutList;
extern std::vector<float_data_t*> FloatFbList;
class halio
{
public:
int Init();
int Update();
};
#endif // HALIO_H
source file :
Warning: Spoiler!
#include "halio.h"
#include <vector>
//! Make conversion's easy:
#define toRadians M_PI/180.0
#define toDegrees (180.0/M_PI)
int comp_id=0;
std::vector<float_data_t*> FloatOutList;
std::vector<float_data_t*> FloatFbList;
std::vector<bit_data_t*> BitInList;
int halio::Init(){
system("halrun -U");
comp_id = hal_init("veroski_halio");
//! bit pins
bit_data_t *BitInList0 = (bit_data_t*)hal_malloc(sizeof(bit_data_t));
hal_pin_bit_new("Pulse",HAL_IN,&(BitInList0->Pin),comp_id);
BitInList.push_back(BitInList0);
//! Float output pins
float_data_t *FloatOutList0 = (float_data_t*)hal_malloc(sizeof(float_data_t));
hal_pin_float_new("J0_PosCmd",HAL_OUT,&(FloatOutList0->Pin),comp_id);
FloatOutList.push_back(FloatOutList0);
float_data_t *FloatOutList1 = (float_data_t*)hal_malloc(sizeof(float_data_t));
hal_pin_float_new("J1_PosCmd",HAL_OUT,&(FloatOutList1->Pin),comp_id);
FloatOutList.push_back(FloatOutList1);
float_data_t *FloatOutList2 = (float_data_t*)hal_malloc(sizeof(float_data_t));
hal_pin_float_new("J2_PosCmd",HAL_OUT,&(FloatOutList2->Pin),comp_id);
FloatOutList.push_back(FloatOutList2);
float_data_t *FloatOutList3 = (float_data_t*)hal_malloc(sizeof(float_data_t));
hal_pin_float_new("J3_PosCmd",HAL_OUT,&(FloatOutList3->Pin),comp_id);
FloatOutList.push_back(FloatOutList3);
float_data_t *FloatOutList4 = (float_data_t*)hal_malloc(sizeof(float_data_t));
hal_pin_float_new("J4_PosCmd",HAL_OUT,&(FloatOutList4->Pin),comp_id);
FloatOutList.push_back(FloatOutList4);
float_data_t *FloatOutList5 = (float_data_t*)hal_malloc(sizeof(float_data_t));
hal_pin_float_new("J5_PosCmd",HAL_OUT,&(FloatOutList5->Pin),comp_id);
FloatOutList.push_back(FloatOutList5);
float_data_t *FloatOutList6 = (float_data_t*)hal_malloc(sizeof(float_data_t));
hal_pin_float_new("J6_PosCmd",HAL_OUT,&(FloatOutList6->Pin),comp_id);
FloatOutList.push_back(FloatOutList6);
//! Float input pins
float_data_t *FloatInList0 = (float_data_t*)hal_malloc(sizeof(float_data_t));
hal_pin_float_new("J0_PosFb",HAL_IN,&(FloatInList0->Pin),comp_id);
FloatFbList.push_back(FloatInList0);
float_data_t *FloatInList1 = (float_data_t*)hal_malloc(sizeof(float_data_t));
hal_pin_float_new("J1_PosFb",HAL_IN,&(FloatInList1->Pin),comp_id);
FloatFbList.push_back(FloatInList1);
float_data_t *FloatInList2 = (float_data_t*)hal_malloc(sizeof(float_data_t));
hal_pin_float_new("J2_PosFb",HAL_IN,&(FloatInList2->Pin),comp_id);
FloatFbList.push_back(FloatInList2);
float_data_t *FloatInList3 = (float_data_t*)hal_malloc(sizeof(float_data_t));
hal_pin_float_new("J3_PosFb",HAL_IN,&(FloatInList3->Pin),comp_id);
FloatFbList.push_back(FloatInList3);
float_data_t *FloatInList4 = (float_data_t*)hal_malloc(sizeof(float_data_t));
hal_pin_float_new("J4_PosFb",HAL_IN,&(FloatInList4->Pin),comp_id);
FloatFbList.push_back(FloatInList4);
float_data_t *FloatInList5 = (float_data_t*)hal_malloc(sizeof(float_data_t));
hal_pin_float_new("J5_PosFb",HAL_IN,&(FloatInList5->Pin),comp_id);
FloatFbList.push_back(FloatInList5);
float_data_t *FloatInList6 = (float_data_t*)hal_malloc(sizeof(float_data_t));
hal_pin_float_new("J6_PosFb",HAL_IN,&(FloatInList6->Pin),comp_id);
FloatFbList.push_back(FloatInList6);
int error = hal_ready(comp_id);
if(error==0){
std::cout << "Hal component ok" << std::endl;
// Load hal file
system("halcmd \-f config/veroskis_stepper_tryout.hal");
system("halcmd start");
return 1; //ok go on
} else {
std::cout << "Hal component error, performing [halrun -U] now." << std::endl;
system("halrun -U");
std::cout << "Restart application required." << std::endl;
return 0; //not good, show error output in terminal.
}
// Normally we don't get here.
return 1;
}
int halio::Update(){
// std::string str1 = "halcmd setp stepgen.0.maxvel ";
// std::string str2 = std::to_string(VelRatio*450);
// std::string str3 = str1+str2;
// system(str3.c_str());
return 1;
}
In the source file. First a user hal component is made.
When this is okey at the end. It load's your halfile.
Then everything is working.
So realize yourself this is a 2 stage HAL startup sequence.
Oke good luck !!
Last edit: 22 Mar 2021 19:27 by Grotius.
Please Log in or Create an account to join the conversation.
- newbynobi
- Offline
- Platinum Member
Less
More
- Posts: 2072
- Thank you received: 408
22 Mar 2021 22:12 #203304
by newbynobi
Replied by newbynobi on topic create GUI and use hal library!
It might be easier to use python as interface to the GUI, as there are tutorials and also ready to use Guis to steel code from
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
Less
More
- Posts: 23178
- Thank you received: 4860
23 Mar 2021 01:05 #203326
by andypugh
Replied by andypugh on topic create GUI and use hal library!
Most of the GUIs in LinuxCNC use Python. Though Axis makes use of Tcl, and the original Mocca GUI (that Gmoccapy is styled after) was written in Pascal.
I do a lot of C, but for a GUI I would go straight to Python.
I haven't been keeping up to date with the developments in QT, but you can look at Gscreen as a good starting point for a custom GUI. (but it might be outmoded now)
linuxcnc.org/docs/2.8/html/gui/gscreen.html
Talking of QT:
linuxcnc.org/docs/2.8/html/gui/qtdragon.html
I do a lot of C, but for a GUI I would go straight to Python.
I haven't been keeping up to date with the developments in QT, but you can look at Gscreen as a good starting point for a custom GUI. (but it might be outmoded now)
linuxcnc.org/docs/2.8/html/gui/gscreen.html
Talking of QT:
linuxcnc.org/docs/2.8/html/gui/qtdragon.html
Please Log in or Create an account to join the conversation.
- newbynobi
- Offline
- Platinum Member
Less
More
- Posts: 2072
- Thank you received: 408
23 Mar 2021 05:12 #203349
by newbynobi
Replied by newbynobi on topic create GUI and use hal library!
may be there is already exactly the GUI you need, but to check we would need to know exactly what requirements you have to your GUI. Also my GUI gmoccapy may be a starting point, as it is highly customizable.
Norbert
Norbert
Please Log in or Create an account to join the conversation.
- veroski
- Topic Author
- Offline
- New Member
Less
More
- Posts: 13
- Thank you received: 1
23 Mar 2021 12:00 #203380
by veroski
Replied by veroski on topic create GUI and use hal library!
thanks to all guys I will update you on this
Please Log in or Create an account to join the conversation.
Time to create page: 0.068 seconds