Skip to content

Commit 9cda4f1

Browse files
committed
fixed Unity to ROS Quaternion!
1 parent df37a2c commit 9cda4f1

File tree

3 files changed

+13
-62
lines changed

3 files changed

+13
-62
lines changed

Runtime/Scripts/ROS/MessageTypes/Geometry/ZOROSGeometryMessages.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,11 @@ public UnityEngine.Quaternion ToUnityQuaternion() {
123123
/// </summary>
124124
/// <param name="q"></param>
125125
public void FromUnityQuaternionToROS(UnityEngine.Quaternion q) {
126-
this.x = (double)-q.x;
127-
this.y = (double)-q.z;
126+
this.x = (double)-q.z;
127+
this.y = (double)q.x;
128128
this.z = (double)-q.y;
129129
this.w = (double)q.w;
130+
130131
}
131132

132133
[Newtonsoft.Json.JsonIgnore]
@@ -245,8 +246,8 @@ public void FromLocalUnityTransform(UnityEngine.Transform transform) {
245246
/// </summary>
246247
/// <param name="transform"></param>
247248
public void FromGlobalUnityTransformToROS(UnityEngine.Transform transform) {
248-
translation.UnityVector3 = transform.position;
249-
rotation.UnityQuaternion = transform.rotation;
249+
translation.FromUnityVector3ToROS(transform.position);
250+
rotation.FromUnityQuaternionToROS(transform.rotation);
250251
}
251252

252253
[Newtonsoft.Json.JsonIgnore]

Runtime/Scripts/ROS/Unity/Publishers/ZOROSTransformPublisher.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ public string FrameID {
3434
protected override void ZOStart() {
3535
base.ZOStart();
3636
// if the child frame id is not set then set it to be the name of this game object.
37-
if (ChildFrameID.Length == 0) {
37+
if (string.IsNullOrEmpty(ChildFrameID) == true) {
3838
ChildFrameID = this.gameObject.name;
3939
}
4040

41-
// TODO: autoset frameId by looking up the hierarch for a parent ZOROSTransformPublisher
42-
// if no parent found then set to "map"
4341
}
4442
protected override void ZOUpdateHzSynchronized() {
4543
_transformMessage.header.Update();
@@ -53,12 +51,14 @@ protected override void ZOUpdateHzSynchronized() {
5351

5452
protected override void ZOOnValidate() {
5553
base.ZOOnValidate();
56-
if (ChildFrameID == "") {
54+
if (string.IsNullOrEmpty(ChildFrameID) == true) {
5755
ChildFrameID = Name;
5856
}
59-
if (FrameID == "") {
57+
if (string.IsNullOrEmpty(FrameID) == true) {
6058
if (transform.parent) {
6159
FrameID = transform.parent.name;
60+
} else {
61+
FrameID = ZOROSUnityManager.Instance.WorldFrameId;
6262
}
6363
}
6464
if (UpdateRateHz == 0) {

Samples~/ZeroSimSamples/Robots/Spot/spot_rigged.prefab

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -196,40 +196,6 @@ HingeJoint:
196196
m_EnablePreprocessing: 1
197197
m_MassScale: 1
198198
m_ConnectedMassScale: 1
199-
--- !u!138 &662680477
200-
FixedJoint:
201-
m_ObjectHideFlags: 0
202-
m_CorrespondingSourceObject: {fileID: 0}
203-
m_PrefabInstance: {fileID: 0}
204-
m_PrefabAsset: {fileID: 0}
205-
m_GameObject: {fileID: 705516937584561444}
206-
m_ConnectedBody: {fileID: 1690162257}
207-
m_ConnectedArticulationBody: {fileID: 0}
208-
m_BreakForce: Infinity
209-
m_BreakTorque: Infinity
210-
m_EnableCollision: 0
211-
m_EnablePreprocessing: 1
212-
m_MassScale: 1
213-
m_ConnectedMassScale: 1
214-
--- !u!114 &662680478
215-
MonoBehaviour:
216-
m_ObjectHideFlags: 0
217-
m_CorrespondingSourceObject: {fileID: 0}
218-
m_PrefabInstance: {fileID: 0}
219-
m_PrefabAsset: {fileID: 0}
220-
m_GameObject: {fileID: 705516937584561444}
221-
m_Enabled: 1
222-
m_EditorHideFlags: 0
223-
m_Script: {fileID: 11500000, guid: d54edc081e20dfbb3b27d3f855559c74, type: 3}
224-
m_Name:
225-
m_EditorClassIdentifier:
226-
_updateRateHz: 0
227-
_debug: 0
228-
_currentUpdateHz: 0
229-
_currentFixedUpdateHz: 0
230-
_fixedJoint: {fileID: 662680477}
231-
_connectedBody: {fileID: 1690162257}
232-
_name: joint.fixed_from_body_to_base_llnk
233199
--- !u!114 &662680489
234200
MonoBehaviour:
235201
m_ObjectHideFlags: 0
@@ -250,29 +216,13 @@ MonoBehaviour:
250216
_name: ros.publisher.transform_body
251217
_frameId: map
252218
_childFrameId: body
253-
--- !u!54 &1690162257
254-
Rigidbody:
255-
m_ObjectHideFlags: 0
256-
m_CorrespondingSourceObject: {fileID: 0}
257-
m_PrefabInstance: {fileID: 0}
258-
m_PrefabAsset: {fileID: 0}
259-
m_GameObject: {fileID: 1730632979493296597}
260-
serializedVersion: 2
261-
m_Mass: 1
262-
m_Drag: 0
263-
m_AngularDrag: 0.05
264-
m_UseGravity: 1
265-
m_IsKinematic: 0
266-
m_Interpolate: 0
267-
m_Constraints: 0
268-
m_CollisionDetection: 0
269-
--- !u!114 &1690162256
219+
--- !u!114 &662680477
270220
MonoBehaviour:
271221
m_ObjectHideFlags: 0
272222
m_CorrespondingSourceObject: {fileID: 0}
273223
m_PrefabInstance: {fileID: 0}
274224
m_PrefabAsset: {fileID: 0}
275-
m_GameObject: {fileID: 1730632979493296597}
225+
m_GameObject: {fileID: 705516937584561444}
276226
m_Enabled: 1
277227
m_EditorHideFlags: 0
278228
m_Script: {fileID: 11500000, guid: b28630d63f8f5fb68a139c2eebaae78f, type: 3}
@@ -283,7 +233,7 @@ MonoBehaviour:
283233
_currentUpdateHz: 0
284234
_currentFixedUpdateHz: 0
285235
_ROSTopic: /odometry
286-
_name: publisher.odometry_base_link
236+
_name: publisher.odometry_body
287237
_applyNoise: 0
288238
_a1: 0.05
289239
_a2: 15

0 commit comments

Comments
 (0)