Skip to content

Commit

Permalink
Bug fix in Micom Device
Browse files Browse the repository at this point in the history
- fix rotation direction for ROS2 message
  there was bug for conversion between Left-handed and right-handed
  • Loading branch information
hyunseok-yang committed Sep 18, 2020
1 parent 70eaf26 commit 6018e42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 8 additions & 5 deletions Assets/Scripts/Devices/MicomSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,10 @@ public bool UpdateOdom()
var odom = micomSensorData.Odom;
if ((odom != null) && (motorLeft != null && motorRight != null))
{
var angularVelocityLeft = motorLeft.GetCurrentVelocity();
var angularVelocityRight = motorRight.GetCurrentVelocity();
// Set revsered value due to differnt direction
// Left-handed -> Right-handed direction of rotation
var angularVelocityLeft = -motorLeft.GetCurrentVelocity();
var angularVelocityRight = -motorRight.GetCurrentVelocity();

odom.AngularVelocityLeft = angularVelocityLeft * Mathf.Deg2Rad;
odom.AngularVelocityRight = angularVelocityRight * Mathf.Deg2Rad;
Expand Down Expand Up @@ -387,12 +389,13 @@ private void SetMotorVelocity(in float angularVelocityLeft, in float angularVelo
{
if (motorLeft != null && motorRight != null)
{
motorLeft.SetVelocityTarget(angularVelocityLeft);
motorRight.SetVelocityTarget(angularVelocityRight);
// Set revsered value due to differnt direction
// Right-handed -> Left-handed direction of rotation
motorLeft.SetVelocityTarget(-angularVelocityLeft);
motorRight.SetVelocityTarget(-angularVelocityRight);
}
}


public Pose GetPartsPose(in string targetPartsName)
{
if (partsPoseMapTable.TryGetValue(targetPartsName, out var targetPartsPose))
Expand Down
3 changes: 1 addition & 2 deletions Assets/Scripts/Devices/Modules/Motor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ public void SetVelocityTarget(in float targetAngularVelocity)
// name, currentVelocity, targetAngularVelocity, cmdForce, rigidBody.maxAngularVelocity);

// JointMotor.targetVelocity angular velocity in degrees per second.
// Set revsered value due to differnt direction between ROS2/SDF(Right-handed)
var motor = joint.motor;
motor.targetVelocity = -targetAngularVelocity;
motor.targetVelocity = targetAngularVelocity;
motor.force = Mathf.Round(cmdForce);

if (targetAngularVelocity == 0)
Expand Down

0 comments on commit 6018e42

Please sign in to comment.