@@ -13,6 +13,7 @@ import com.aldebaran.qi.sdk.builder.LookAtBuilder
13
13
import com.aldebaran.qi.sdk.builder.TransformBuilder
14
14
import kotlin.math.atan2
15
15
import kotlin.math.cos
16
+ import kotlin.math.roundToInt
16
17
import kotlin.math.sin
17
18
18
19
class RemoteRobotController (context : QiContext ) {
@@ -59,12 +60,20 @@ class RemoteRobotController(context: QiContext) {
59
60
" newRightJoystickY=$newRightJoystickY " )
60
61
61
62
// Round values
62
- val leftJoystickTheta = atan2(newLeftJoystickY, newLeftJoystickX)
63
- val roundedNewLeftJoystickX = if (leftJoystickTheta != 0f ) (cos(leftJoystickTheta) * 10 ).toInt() else 0
64
- val roundedNewLeftJoystickY = if (leftJoystickTheta != 0f ) (sin(leftJoystickTheta) * 10 ).toInt() else 0
65
- val rightJoystickTheta = atan2(newRightJoystickY, newRightJoystickX)
66
- val roundedNewRightJoystickX = if (rightJoystickTheta != 0f ) (cos(rightJoystickTheta) * 10 ).toInt() else 0
67
- val roundedNewRightJoystickY = if (rightJoystickTheta != 0f ) (sin(rightJoystickTheta) * 10 ).toInt() else 0
63
+ var roundedNewLeftJoystickX = 0
64
+ var roundedNewLeftJoystickY = 0
65
+ if (! (newLeftJoystickX == 0f && newLeftJoystickY == 0f )) {
66
+ val leftJoystickTheta = atan2(newLeftJoystickY, newLeftJoystickX)
67
+ roundedNewLeftJoystickX = (cos(leftJoystickTheta) * 10 ).roundToInt()
68
+ roundedNewLeftJoystickY = (sin(leftJoystickTheta) * 10 ).roundToInt()
69
+ }
70
+ var roundedNewRightJoystickX = 0
71
+ var roundedNewRightJoystickY = 0
72
+ if (! (newRightJoystickX == 0f && newRightJoystickY == 0f )) {
73
+ val rightJoystickTheta = atan2(newRightJoystickY, newRightJoystickX)
74
+ roundedNewRightJoystickX = (cos(rightJoystickTheta) * 10 ).roundToInt()
75
+ roundedNewRightJoystickY = (sin(rightJoystickTheta) * 10 ).roundToInt()
76
+ }
68
77
69
78
// Avoid repeating commands
70
79
if (! (roundedNewLeftJoystickX == currentLeftJoystickX && roundedNewLeftJoystickY == currentLeftJoystickY)) {
0 commit comments