Skip to content

Commit dc70d73

Browse files
Merge pull request #22 from pollen-robotics/21-range-of-neck-angles-different-from-real-robot
Set angles in range -180,180
2 parents 9392497 + bd0eefc commit dc70d73

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Packages/ReachySimulator/Scripts/JointServiceServer.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,20 +383,21 @@ public override Task<FullBodyCartesianCommandAck> SendFullBodyCartesianCommands(
383383
(float)fullBodyCartesianCommand.Neck.Q.W);
384384

385385
Vector3 neck_commands = Mathf.Deg2Rad * headRotation.eulerAngles;
386+
386387
jointCommandList.Add(new JointCommand
387388
{
388389
Id = new JointId { Name = "neck_roll" },
389-
GoalPosition = (float?)neck_commands[2],
390+
GoalPosition = (float?)ChangeAngleRange(neck_commands[2]),
390391
});
391392
jointCommandList.Add(new JointCommand
392393
{
393394
Id = new JointId { Name = "neck_pitch" },
394-
GoalPosition = (float?)neck_commands[0],
395+
GoalPosition = (float?)ChangeAngleRange(neck_commands[0]),
395396
});
396397
jointCommandList.Add(new JointCommand
397398
{
398399
Id = new JointId { Name = "neck_yaw" },
399-
GoalPosition = (float?)neck_commands[1],
400+
GoalPosition = -(float?)ChangeAngleRange(neck_commands[1]),
400401
});
401402
}
402403

@@ -447,6 +448,13 @@ public override async Task<FullBodyCartesianCommandAck> StreamFullBodyCartesianC
447448
NeckCommandSuccess = true
448449
});
449450
}
451+
452+
private float ChangeAngleRange(float orbita_angle)
453+
{
454+
float modified_angle = orbita_angle % (2.0f * (float)Math.PI);
455+
modified_angle = modified_angle > (float)Math.PI ? modified_angle - (2.0f * (float)Math.PI) : modified_angle;
456+
return modified_angle;
457+
}
450458
}
451459

452460
public class ArmKinematicsImpl : ArmKinematics.ArmKinematicsBase

Packages/ReachySimulator/Scripts/ReachyController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public void HandleCommand(Dictionary<JointId, float> commands)
269269
if (motorName == "neck_yaw")
270270
{
271271
containNeckCommand = true;
272-
headOrientation[2] = kvp.Value;
272+
headOrientation[2] = -kvp.Value;
273273
}
274274
}
275275

0 commit comments

Comments
 (0)