Robots: Use std::numeric_limits and std::numbers instead of defines

This commit is contained in:
Benjamin Nauck
2025-03-27 19:02:17 +01:00
parent 61684e86c1
commit 883d02756d
5 changed files with 31 additions and 36 deletions

View File

@@ -173,6 +173,8 @@ void ViewProviderRobotObject::onChanged(const App::Property* prop)
void ViewProviderRobotObject::updateData(const App::Property* prop)
{
using std::numbers::pi;
Robot::RobotObject* robObj = static_cast<Robot::RobotObject*>(pcObject);
if (prop == &robObj->RobotVrmlFile) {
// read also from file
@@ -269,33 +271,33 @@ void ViewProviderRobotObject::updateData(const App::Property* prop)
}
if (Axis1Node) {
Axis1Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0),
robObj->Axis1.getValue() * (M_PI / 180));
robObj->Axis1.getValue() * (pi / 180));
}
if (Axis2Node) {
Axis2Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0),
robObj->Axis2.getValue() * (M_PI / 180));
robObj->Axis2.getValue() * (pi / 180));
}
if (Axis3Node) {
Axis3Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0),
robObj->Axis3.getValue() * (M_PI / 180));
robObj->Axis3.getValue() * (pi / 180));
}
if (Axis4Node) {
Axis4Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0),
robObj->Axis4.getValue() * (M_PI / 180));
robObj->Axis4.getValue() * (pi / 180));
}
if (Axis5Node) {
Axis5Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0),
robObj->Axis5.getValue() * (M_PI / 180));
robObj->Axis5.getValue() * (pi / 180));
}
if (Axis6Node) {
Axis6Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0),
robObj->Axis6.getValue() * (M_PI / 180));
robObj->Axis6.getValue() * (pi / 180));
}
}
else if (prop == &robObj->Axis1) {
if (Axis1Node) {
Axis1Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0),
robObj->Axis1.getValue() * (M_PI / 180));
robObj->Axis1.getValue() * (pi / 180));
if (toolShape) {
toolShape->setTransformation(
(robObj->Tcp.getValue() * (robObj->ToolBase.getValue().inverse())).toMatrix());
@@ -305,7 +307,7 @@ void ViewProviderRobotObject::updateData(const App::Property* prop)
else if (prop == &robObj->Axis2) {
if (Axis2Node) {
Axis2Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0),
robObj->Axis2.getValue() * (M_PI / 180));
robObj->Axis2.getValue() * (pi / 180));
if (toolShape) {
toolShape->setTransformation(
(robObj->Tcp.getValue() * (robObj->ToolBase.getValue().inverse())).toMatrix());
@@ -315,7 +317,7 @@ void ViewProviderRobotObject::updateData(const App::Property* prop)
else if (prop == &robObj->Axis3) {
if (Axis3Node) {
Axis3Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0),
robObj->Axis3.getValue() * (M_PI / 180));
robObj->Axis3.getValue() * (pi / 180));
if (toolShape) {
toolShape->setTransformation(
(robObj->Tcp.getValue() * (robObj->ToolBase.getValue().inverse())).toMatrix());
@@ -325,7 +327,7 @@ void ViewProviderRobotObject::updateData(const App::Property* prop)
else if (prop == &robObj->Axis4) {
if (Axis4Node) {
Axis4Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0),
robObj->Axis4.getValue() * (M_PI / 180));
robObj->Axis4.getValue() * (pi / 180));
if (toolShape) {
toolShape->setTransformation(
(robObj->Tcp.getValue() * (robObj->ToolBase.getValue().inverse())).toMatrix());
@@ -335,7 +337,7 @@ void ViewProviderRobotObject::updateData(const App::Property* prop)
else if (prop == &robObj->Axis5) {
if (Axis5Node) {
Axis5Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0),
robObj->Axis5.getValue() * (M_PI / 180));
robObj->Axis5.getValue() * (pi / 180));
if (toolShape) {
toolShape->setTransformation(
(robObj->Tcp.getValue() * (robObj->ToolBase.getValue().inverse())).toMatrix());
@@ -345,7 +347,7 @@ void ViewProviderRobotObject::updateData(const App::Property* prop)
else if (prop == &robObj->Axis6) {
if (Axis6Node) {
Axis6Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0),
robObj->Axis6.getValue() * (M_PI / 180));
robObj->Axis6.getValue() * (pi / 180));
if (toolShape) {
toolShape->setTransformation(
(robObj->Tcp.getValue() * (robObj->ToolBase.getValue().inverse())).toMatrix());
@@ -395,27 +397,29 @@ void ViewProviderRobotObject::setAxisTo(float A1,
float A6,
const Base::Placement& Tcp)
{
using std::numbers::pi;
Robot::RobotObject* robObj = static_cast<Robot::RobotObject*>(pcObject);
if (Axis1Node) {
// FIXME Ugly hack for the wrong transformation of the Kuka 500 robot VRML the minus sign on
// Axis 1
Axis1Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A1 * (M_PI / 180));
Axis1Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A1 * (pi / 180));
}
if (Axis2Node) {
Axis2Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A2 * (M_PI / 180));
Axis2Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A2 * (pi / 180));
}
if (Axis3Node) {
Axis3Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A3 * (M_PI / 180));
Axis3Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A3 * (pi / 180));
}
if (Axis4Node) {
Axis4Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A4 * (M_PI / 180));
Axis4Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A4 * (pi / 180));
}
if (Axis5Node) {
Axis5Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A5 * (M_PI / 180));
Axis5Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A5 * (pi / 180));
}
if (Axis6Node) {
Axis6Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A6 * (M_PI / 180));
Axis6Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A6 * (pi / 180));
}
// update tool position
if (toolShape) {