- Posts: 2419
- Thank you received: 0
How would you design a real time application for cnc control in c / c++ ???
5 years 4 months ago #211615
by Grotius
Replied by Grotius on topic How would you design a real time application for cnc control in c / c++ ???
Hi,
Just leave the opencascade.h untouched.
I want to connect slider to 3d model, but this string crash all compile
Ah. This make sence.
For example how to connect a button, the .cpp file :
has a slot in the .h file:
is controlled by the .qml file :
Personally i never pass argument's in button's themself. Qt has no interface for this. But if above example works it's ok for me.
For a slider you have information like a float value for the slider value. It is no string value !
You just use a float value. Hal has no double value's present.
For info : It's not always a good idea to use onClicked. the "on" is used by qt internals.
Try to integrate the slider function first make it work in the cpp an h file.
Pass some value's with the existing buttonpress function.
After that create the connection to the qml.
Just leave the opencascade.h untouched.
I want to connect slider to 3d model, but this string crash all compile
Ah. This make sence.
For example how to connect a button, the .cpp file :
Code:
void Robot::onClicked(const QString& in1, const QString& in2, const QString& in3)
Code:
public slots:
void onClicked(const QString& in1,const QString& in2,const QString& in3);
t
Code:
Button {
robot.onClicked(input1.text,input2.text,input3.text)
}
Personally i never pass argument's in button's themself. Qt has no interface for this. But if above example works it's ok for me.
For a slider you have information like a float value for the slider value. It is no string value !
You just use a float value. Hal has no double value's present.
For info : It's not always a good idea to use onClicked. the "on" is used by qt internals.
Try to integrate the slider function first make it work in the cpp an h file.
Pass some value's with the existing buttonpress function.
After that create the connection to the qml.
Please Log in to join the conversation.
- TheRoslyak
- Offline
- Elite Member
-
Less
More
- Posts: 238
- Thank you received: 0
5 years 4 months ago #211621
by TheRoslyak
Replied by TheRoslyak on topic How would you design a real time application for cnc control in c / c++ ???
Ok
I connect slider to interface. It counts in both directions. But if I use opencascade function - project is crash.
dropmefiles.com/Cammf
I connect slider to interface. It counts in both directions. But if I use opencascade function - project is crash.
dropmefiles.com/Cammf
Please Log in to join the conversation.
5 years 4 months ago #211639
by Grotius
Replied by Grotius on topic How would you design a real time application for cnc control in c / c++ ???
Hi,
In the main.cpp the opencascade is named occ.
In main.qml you create the robot scene by calling :
So for passing the slider values to occ it would be something like :
(calling that from your qml code)
What you did is calling a c++ opencascade function directly. An sich this is no problem. This methode can be used, but not alway's.
Why not then?
Opencascade has to be initialized, started etc before it can be used.
Normally this is done once in a program loop. For c++ :
Then in your program you call a function like :
Then it will show no error.
I hope this give you an idea how to handle this. In the beginning it can be quite confusing. But when you have practiced
a little more, you will begin to understand how things work in c++.
P.s.
Very nice to see, you are using qt design studio.
Can you tell us your experience with this program? Is it nice to use? Is it difficult?
In the main.cpp the opencascade is named occ.
Code:
engine.rootContext()->setContextProperty("occ", new Opencascade);
In main.qml you create the robot scene by calling :
Code:
occ.createrobotscene();
So for passing the slider values to occ it would be something like :
Code:
occ.setslidervalue(10);
What you did is calling a c++ opencascade function directly. An sich this is no problem. This methode can be used, but not alway's.
Why not then?
Opencascade has to be initialized, started etc before it can be used.
Normally this is done once in a program loop. For c++ :
Code:
Opencascadewidget *occ = new Opencascadewidget;
Then in your program you call a function like :
Code:
occ->setslidervalue(10);
Then it will show no error.
I hope this give you an idea how to handle this. In the beginning it can be quite confusing. But when you have practiced
a little more, you will begin to understand how things work in c++.
P.s.
Very nice to see, you are using qt design studio.
Can you tell us your experience with this program? Is it nice to use? Is it difficult?
Please Log in to join the conversation.
- TheRoslyak
- Offline
- Elite Member
-
Less
More
- Posts: 238
- Thank you received: 0
5 years 4 months ago #211678
by TheRoslyak
Replied by TheRoslyak on topic How would you design a real time application for cnc control in c / c++ ???
I thought of doing this, but as soon as I start writing in Robot.h:
include <opencascade.h>
project not compile
include <opencascade.h>
project not compile
Please Log in to join the conversation.
5 years 4 months ago #211687
by Grotius
Replied by Grotius on topic How would you design a real time application for cnc control in c / c++ ???
Hi,
You can add the code to your project.
Mention creating the slot signal in opencascade.h and then call it from qml with : occ.yourslotsignal()
Now you can happely go on with coding !
In the main.qml:
Opencascade.h:
Opencascade.cpp:
And your robot is moving !
You have to check your model rotation-translation yourself.
You can look at this function to rotate your model. It's based on a quaternion. But first try to get it correct using the
existing example.
You can add the code to your project.
Mention creating the slot signal in opencascade.h and then call it from qml with : occ.yourslotsignal()
Now you can happely go on with coding !
In the main.qml:
Warning: Spoiler!
Code:
Slider {
id: slider
x: 228
y: 241
from: 0
value: 0
to:100
onMoved:{
occ.slider_joint_moved(0,slider.value)
}
}
Slider {
id: slider1
x: 228
y: 283
from: 0
value: 0
to:100
onMoved:{
occ.slider_joint_moved(1,slider.value)
}
}
Slider {
id: slider2
x: 228
y: 325
from: 0
value: 0
to:100
onMoved:{
occ.slider_joint_moved(2,slider.value)
}
}
Opencascade.h:
Warning: Spoiler!
Code:
public slots:
void slider_joint_moved(unsigned int joint, float value);
Opencascade.cpp:
Warning: Spoiler!
Code:
void Opencascade::slider_joint_moved(unsigned int joint, float value){
std::cout<<"joint:"<<joint<<" value:"<<value<<std::endl;
update_joint(joint,value);
}
And your robot is moving !
You have to check your model rotation-translation yourself.
You can look at this function to rotate your model. It's based on a quaternion. But first try to get it correct using the
existing example.
Warning: Spoiler!
Code:
Handle(AIS_Shape) draw_primitives::rotate_translate_3d_quaternion(Handle(AIS_Shape) shape, gp_Pnt translation, double euler_z, double euler_y, double euler_x){
// ** For euler angles you have to follow the euler sequence of rotation. First around z, then around y, then around x.
// Otherwise you will get wrong solutions.
gp_Trsf trsf;
gp_Quaternion aQuat;
aQuat.SetEulerAngles (gp_YawPitchRoll, euler_z, euler_y, euler_x);
trsf.SetRotation(aQuat);
gp_Trsf trsf1;
trsf1.SetTranslation({0,0,0},translation);
trsf1.Multiply(trsf);
shape->SetLocalTransformation(trsf1);
return shape;
}
Attachment not found
Please Log in to join the conversation.
- TheRoslyak
- Offline
- Elite Member
-
Less
More
- Posts: 238
- Thank you received: 0
5 years 4 months ago #211688
by TheRoslyak
Replied by TheRoslyak on topic How would you design a real time application for cnc control in c / c++ ???
Thank you so much.
I know about rotation problem. I think I can do it
How you can hide yellow cross?
PS Can you check "LinuxCNC S-Curve Accelerations" topic
I know about rotation problem. I think I can do it
How you can hide yellow cross?
PS Can you check "LinuxCNC S-Curve Accelerations" topic
Please Log in to join the conversation.
5 years 4 months ago #211868
by Grotius
Replied by Grotius on topic How would you design a real time application for cnc control in c / c++ ???
Hi,
For reading a stepfile, there are different options. Try this example :
PS Can you check "LinuxCNC S-Curve Accelerations" topic
If you have problem's with a nice motion output. Try to integrate a stepgen component between your motion command and
motor drives. The stepgen component can finetune the acceleration-deacceleartion very nice.
For reading a stepfile, there are different options. Try this example :
Warning: Spoiler!
Code:
bool Opencascade::Readstepfile(const std::string& theStepName)
{
SegmentVec.push_back(Segment);
STEPCAFControl_Controller::Init();
Handle(TDocStd_Document) aDoc;
Handle(XCAFApp_Application) anApp = XCAFApp_Application::GetApplication();
anApp->NewDocument("MDTV-XCAF", aDoc);
STEPCAFControl_Reader aStepReader;
aStepReader.SetColorMode(true);
aStepReader.SetNameMode(true);
aStepReader.SetLayerMode(true);
aStepReader.SetPropsMode(true);
aStepReader.ReadFile (theStepName.c_str());
aStepReader.Transfer (aDoc);
TDF_Label aRootLabel = aDoc->Main();
aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aRootLabel);
aColorTool = XCAFDoc_DocumentTool::ColorTool(aRootLabel);
Visit(aRootLabel);
m_view->FitAll();
return 1;
}
void Opencascade::Visit(const TDF_Label& theLabel)
{
//theLabel.EntryDump(std::cout);
Quantity_Color aColor;
TopoDS_Shape aShape;
Handle(TDataStd_Name) aName;
if (theLabel.FindAttribute(TDataStd_Name::GetID(), aName))
{
//std::cout << " Name: " << aName->Get() << std::endl;
}
bool skip=0;
if (aShapeTool->IsShape(theLabel))
{
//TopoDS_Shape aShape;
//if a shape can be made from the current label, look for the color of that label:
if(aShapeTool->GetShape(theLabel, aShape)){
//std::cout<<"made a shape"<<std::endl;
if(aColorTool->GetColor(aShape,XCAFDoc_ColorSurf,aColor)){
skip=0;
} else { skip=1;}
}
if(skip==0){
SegmentVec.back().Ais_ShapeVec.push_back(new AIS_Shape(aShape));
//if(aColor.Name()!=Quantity_NOC_YELLOW && aColor.Name()!=Quantity_NOC_RED){
SegmentVec.back().Ais_ShapeVec.back()->SetColor(aColor);
//}
SegmentVec.back().Ais_ShapeVec.back()->SetDisplayMode(AIS_Shaded);
SegmentVec.back().Ais_ShapeVec.back()->Attributes()->SetFaceBoundaryDraw(true);
SegmentVec.back().Ais_ShapeVec.back()->Attributes()->SetFaceBoundaryAspect(
new Prs3d_LineAspect(Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.));
SegmentVec.back().Ais_ShapeVec.back()->Attributes()->SetIsoOnTriangulation(true);
m_context->Display(SegmentVec.back().Ais_ShapeVec.back(),Standard_False);
}
}
/*! Repeat the visit function for each childmember. */
for (TDF_ChildIterator c(theLabel); c.More(); c.Next())
{
Visit(c.Value());
}
}
PS Can you check "LinuxCNC S-Curve Accelerations" topic
If you have problem's with a nice motion output. Try to integrate a stepgen component between your motion command and
motor drives. The stepgen component can finetune the acceleration-deacceleartion very nice.
Please Log in to join the conversation.
5 years 2 months ago #218142
by udoS
Replied by udoS on topic How would you design a real time application for cnc control in c / c++ ???
Hi Grotius... remember me ?
In reference to your "Qt_C-_Lcnc_Gui"
there is a section ...toolpos.x=emcStatus->motion.traj.position.tran.x; in get_position.h
Where do I find things like distance_to_go.x and/or other related values or maybe a relevant documentation.
Oh... and how to index if I have a gantry like I realy do.
Best regards
udo
In reference to your "Qt_C-_Lcnc_Gui"
there is a section ...toolpos.x=emcStatus->motion.traj.position.tran.x; in get_position.h
Where do I find things like distance_to_go.x and/or other related values or maybe a relevant documentation.
Oh... and how to index if I have a gantry like I realy do.
Best regards
udo
Please Log in to join the conversation.
5 years 2 months ago #218239
by Grotius
Replied by Grotius on topic How would you design a real time application for cnc control in c / c++ ???
Hi, i "duckducked".
Motion distance-to-go is inside the motion controller.
linuxcnc.org/docs/2.7/html/man/man9/motion.9.html
motion.distance−to−go OUT FLOAT
Distance remaining in the current move
You can retrieve this value by reading the halpin of the motion ..
In c++ you can setup a gui component with a hal-in pin of type float.
In the current repository their seems not to be a gui-component. The
level of coding was quite low at that time.
Then connect in the .hal file the motion-halpin type::hal_out to your gui input pin.
Examples how to setup this, see the attachements. rename .txt to .cpp
Oh... and how to index if I have a gantry like I realy do.
You mean activate the home sequence?
Motion distance-to-go is inside the motion controller.
linuxcnc.org/docs/2.7/html/man/man9/motion.9.html
motion.distance−to−go OUT FLOAT
Distance remaining in the current move
You can retrieve this value by reading the halpin of the motion ..
In c++ you can setup a gui component with a hal-in pin of type float.
In the current repository their seems not to be a gui-component. The
level of coding was quite low at that time.
Then connect in the .hal file the motion-halpin type::hal_out to your gui input pin.
Examples how to setup this, see the attachements. rename .txt to .cpp
Oh... and how to index if I have a gantry like I realy do.
You mean activate the home sequence?
Please Log in to join the conversation.
5 years 2 months ago #218332
by udoS
Replied by udoS on topic How would you design a real time application for cnc control in c / c++ ???
Hi, thanks.
That’s not it.
The distance-to-go is ok but that is the total move.
I‘m looking for .dtg that comes as a tuple from the nml emcSatus.
So it should be available somewhere at:
std:get<0>(emcSatus-> ........ .dtg);
Using Qtcreator 4.8
Best regards
That’s not it.
The distance-to-go is ok but that is the total move.
I‘m looking for .dtg that comes as a tuple from the nml emcSatus.
So it should be available somewhere at:
std:get<0>(emcSatus-> ........ .dtg);
Using Qtcreator 4.8
Best regards
Please Log in to join the conversation.
Time to create page: 0.240 seconds
