Skip to content

Commit 99c4877

Browse files
Fix on values rounding (#2)
1 parent 8c0b2ad commit 99c4877

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

pepper-gamepad-root/pepper-gamepad/src/main/java/com/softbankrobotics/peppergamepad/RemoteRobotController.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.aldebaran.qi.sdk.builder.LookAtBuilder
1313
import com.aldebaran.qi.sdk.builder.TransformBuilder
1414
import kotlin.math.atan2
1515
import kotlin.math.cos
16+
import kotlin.math.roundToInt
1617
import kotlin.math.sin
1718

1819
class RemoteRobotController(context: QiContext) {
@@ -59,12 +60,20 @@ class RemoteRobotController(context: QiContext) {
5960
"newRightJoystickY=$newRightJoystickY")
6061

6162
// 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+
}
6877

6978
// Avoid repeating commands
7079
if (!(roundedNewLeftJoystickX == currentLeftJoystickX && roundedNewLeftJoystickY == currentLeftJoystickY)) {

0 commit comments

Comments
 (0)