Skip to content

Commit 961b0a1

Browse files
authored
EV3: Fix atan2 RBF generation (#1998)
* Use radians instead of degrees * Fix clazy warnings * Fix EV3 code generation to convert radians to degrees * Fix Vera and Codefactor issues * Fix clazy warnings * Remove line break from templates * Fix clazy warnings * Fix ev3 generation for atan2 * Fix ev3 generation * Use atan2 as a subroutine * Delete the terrible code
1 parent 0906e0c commit 961b0a1

File tree

9 files changed

+30
-31
lines changed

9 files changed

+30
-31
lines changed

plugins/robots/generators/ev3/ev3RbfGenerator/lua/ev3LuaPrinter.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,11 @@ void Ev3LuaPrinter::visit(const QSharedPointer<qrtext::lua::ast::FunctionCall> &
674674
arguments << castTo(Ev3RbfType::dataF, qrtext::as<qrtext::lua::ast::Node>(argument));
675675
}
676676

677-
if (mReservedFunctionsConverter.needChangeArg(nodeName)) {
677+
if (mReservedFunctionsConverter.isCosOrSin(nodeName)) {
678678
for (auto it = arguments.begin(); it != arguments.end(); it++) {
679679
const auto &oldValue = *it;
680680
const auto &argChanged = newRegister(Ev3RbfType::dataF);
681-
additionalResults << mReservedFunctionsConverter.translateArg(nodeName, oldValue, argChanged);
681+
additionalResults << QString("MULF(%1, %2, %3)").arg(oldValue, "57.29577951308232F", argChanged);
682682
*it = argChanged;
683683
}
684684
}
@@ -698,9 +698,6 @@ void Ev3LuaPrinter::visit(const QSharedPointer<qrtext::lua::ast::FunctionCall> &
698698
} else {
699699
additionalResults << reservedFunctionCall.replace("@@RESULT@@", functionResult);
700700
pushResult(node, result, additionalResults.join("\n"));
701-
if (mReservedFunctionsConverter.needChangeResult(nodeName)) {
702-
mAdditionalCode[node.data()] << mReservedFunctionsConverter.translateResult(nodeName, result);
703-
}
704701
if (shouldCastToIntAfter) {
705702
mAdditionalCode[node.data()] << QString("MOVEF_32(%1, %2)").arg(functionResult, result);
706703
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
MATH(ACOS, @@ARGUMENT@@, @@RESULT@@)
1+
MATH(ACOS, @@ARGUMENT@@, @@RESULT@@)
2+
DIVF(@@RESULT@@, 57.29577951308232F, @@RESULT@@)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
MATH(ASIN, @@ARGUMENT@@, @@RESULT@@)
1+
MATH(ASIN, @@ARGUMENT@@, @@RESULT@@)
2+
DIVF(@@RESULT@@, 57.29577951308232F, @@RESULT@@)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
MATH(ATAN, @@ARGUMENT@@, @@RESULT@@)
1+
MATH(ATAN, @@ARGUMENT@@, @@RESULT@@)
2+
DIVF(@@RESULT@@, 57.29577951308232F, @@RESULT@@)
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
DIVF(@@ARGUMENT1@@, @@ARGUMENT2@@, _temp_sensor_value_f)
2-
MATH(ATAN, _temp_sensor_value_f, @@RESULT@@)
1+
CALL(atan2wrap_EV3_KERNEL_util, @@ARGUMENT1@@, @@ARGUMENT2@@, @@RESULT@@)

plugins/robots/generators/ev3/ev3RbfGenerator/templates/main.t

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@ __programEnd:
3636

3737
@@THREADS@@
3838

39+
subcall atan2wrap_EV3_KERNEL_util
40+
{
41+
IN_F y
42+
IN_F x
43+
OUT_F z
44+
45+
DATAF yDividedByX
46+
DIVF(y, x, yDividedByX)
47+
MATH(ATAN, yDividedByX, z)
48+
DIVF(z, 57.29577951308232F, z)
49+
JR_GTF(x, 0.0F, endLabel)
50+
JR_GTEQF(y, 0.0F, yGreatEqualZero)
51+
SUBF(z, pi, z)
52+
JR(endLabel)
53+
yGreatEqualZero:
54+
ADDF(z, pi, z)
55+
endLabel:
56+
}
57+
3958
// utils functions block start
4059
subcall motors_overflow_check_EV3_KERNEL_util
4160
{

plugins/robots/generators/generatorBase/include/generatorBase/lua/reservedFunctionsConverter.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,9 @@ class ROBOTS_GENERATOR_EXPORT ReservedFunctionsConverter : public TemplateParame
2727

2828
QString convert(const QString &name, const QStringList &args) const;
2929

30-
inline bool needChangeArg(const QString &name) const {
30+
inline bool isCosOrSin(const QString &name) const {
3131
return name == "cos" || name == "sin";
3232
}
33-
34-
inline bool needChangeResult(const QString &name) const {
35-
return name == "atan2" || name == "acos" || name == "asin" || name == "atan";
36-
}
37-
38-
inline QString translateArg(const QString &functionName, const QString &argName, const QString &newArgName) const {
39-
return needChangeArg(functionName) ? QString("MULF(%1, %2, %3)")
40-
.arg(argName, s180dividedByPi, newArgName) : QString();
41-
}
42-
43-
44-
inline QString translateResult(const QString &functionName, const QString &argName) const {
45-
return needChangeResult(functionName) ? QString("DIVF(%1, %2, %1)")
46-
.arg(argName, s180dividedByPi) : QString();
47-
}
48-
private:
49-
static constexpr const char* s180dividedByPi = "57.29577951308232F";
5033
};
5134

5235
}

plugins/robots/generators/generatorBase/src/lua/reservedFunctionsConverter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
using namespace generatorBase::lua;
2020

21-
constexpr const char* ReservedFunctionsConverter::s180dividedByPi;
22-
2321
ReservedFunctionsConverter::ReservedFunctionsConverter(const QStringList &pathsToTemplates)
2422
: TemplateParametrizedEntity(pathsToTemplates)
2523
{

qrtranslations/ru/plugins/robots/ev3RbfGenerator_ru.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<translation type="vanished">/* Внимание: преобразование типа из строки в целое число пока не поддерживается. Пожалуйста, обратитесь к разработчикам с запросом. */ 0</translation>
1414
</message>
1515
<message>
16-
<location filename="../../../../plugins/robots/generators/ev3/ev3RbfGenerator/lua/ev3LuaPrinter.cpp" line="+811"/>
16+
<location filename="../../../../plugins/robots/generators/ev3/ev3RbfGenerator/lua/ev3LuaPrinter.cpp" line="+808"/>
1717
<source>/* Warning: cast from string to numeric type is not supported */ 0</source>
1818
<translation>/* Внимание: преобразование типа из строки в числовой тип пока не поддерживается. Пожалуйста, обратитесь к разработчикам с запросом. */ 0</translation>
1919
</message>

0 commit comments

Comments
 (0)