Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a ZO 4wd Differential Drive Controller #24

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions Editor/CustomEditors/ZO4wdDifferentialDriveControllerEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using ZO.ROS.Controllers;
using ZO.Physics;


namespace ZO.Editor {

[CustomEditor(typeof(ZO4wdDifferentialDriveController))]
public class ZO4wdDifferentialDriveControllerEditor : UnityEditor.Editor {

// int _hingeChoiceIndex = 0;
string[] _motorChoiceNames;
SerializedObject _diffDriveSerializedObject;
SerializedProperty _frontRightMotorProp;
SerializedProperty _rearRightMotorProp;
SerializedProperty _frontLeftMotorProp;
SerializedProperty _rearLeftMotorProp;

private void OnEnable() {
_diffDriveSerializedObject = new SerializedObject(target);
_frontRightMotorProp = _diffDriveSerializedObject.FindProperty("_frontRightWheelMotor");
_rearRightMotorProp = _diffDriveSerializedObject.FindProperty("_rearRightWheelMotor");
_frontLeftMotorProp = _diffDriveSerializedObject.FindProperty("_frontLeftWheelMotor");
_rearLeftMotorProp = _diffDriveSerializedObject.FindProperty("_rearLeftWheelMotor");
}
public override void OnInspectorGUI() {
_diffDriveSerializedObject.Update();

DrawDefaultInspector();

ZO4wdDifferentialDriveController diffDrive = (ZO4wdDifferentialDriveController)target;

// get the hinge joints on this object
ZOHingeJoint[] hingeJoints = diffDrive.GetComponentsInChildren<ZOHingeJoint>();
_motorChoiceNames = new string[hingeJoints.Length];

// check if we already have set the hinge joints
int frontRightWheelIndex = -1;
int rearRightWheelIndex = -1;
int frontLeftWheelIndex = -1;
int rearLeftWheelIndex = -1;
for (int i = 0; i < hingeJoints.Length; i++) {
_motorChoiceNames[i] = hingeJoints[i].Name;
if (hingeJoints[i] == diffDrive.FrontRightWheelMotor) {
frontRightWheelIndex = i;
}
if (hingeJoints[i] == diffDrive.RearRightWheelMotor) {
rearRightWheelIndex = i;
}
if (hingeJoints[i] == diffDrive.FrontLeftWheelMotor) {
frontLeftWheelIndex = i;
}
if (hingeJoints[i] == diffDrive.RearLeftWheelMotor) {
rearLeftWheelIndex = i;
}

}

int frontLeftMotorChosenIndex = UnityEditor.EditorGUILayout.Popup("Front Left Wheel Motor Name", frontLeftWheelIndex, _motorChoiceNames);
int frontRightMotorChosenIndex = UnityEditor.EditorGUILayout.Popup("Front Right Wheel Motor Name", frontRightWheelIndex, _motorChoiceNames);

int rearLeftMotorChosenIndex = UnityEditor.EditorGUILayout.Popup("Rear Left Wheel Motor Name", rearLeftWheelIndex, _motorChoiceNames);
int rearRightMotorChosenIndex = UnityEditor.EditorGUILayout.Popup("Rear Right Wheel Motor Name", rearRightWheelIndex, _motorChoiceNames);

// if we chose something different then what is already selected then set it
if (frontRightMotorChosenIndex != frontRightWheelIndex) {
_frontRightMotorProp.objectReferenceValue = hingeJoints[frontRightMotorChosenIndex];
}
if (rearRightMotorChosenIndex != rearRightWheelIndex) {
_rearRightMotorProp.objectReferenceValue = hingeJoints[rearRightMotorChosenIndex];
}

if (frontLeftMotorChosenIndex != frontLeftWheelIndex) {
_frontLeftMotorProp.objectReferenceValue = hingeJoints[frontLeftMotorChosenIndex];
}
if (rearLeftMotorChosenIndex != rearLeftWheelIndex) {
_rearLeftMotorProp.objectReferenceValue = hingeJoints[rearLeftMotorChosenIndex];
}


// apply the properties
_diffDriveSerializedObject.ApplyModifiedProperties();

}
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [Export URDF](#export-urdf)
- [Import URDF](#import-urdf)
- [LEO Robot Example](#leo-robot-example)
- [Modifying package source](#modifying-package-source)

ZeroSim is a robotics simulation engine built on the easy to use [Unity 3D](https://unity.com/) development platform and the power of the [Robotics Operating System (ROS)](https://www.ros.org/). ZeroSim is designed for ease of use and rapid development of all sorts of robotics and simulation -- from warehouses and industrial settings, to farming and outdoors -- from robotic arms to ground and drone based mobile robots.

Expand Down Expand Up @@ -298,3 +299,8 @@ sed -i 's#package://#./#g' my_leo_robot/leo_sim.urdf
```

10. In Unity import URDF by: Right click and select `ZeroSim --> Import URDF...`

### Modifying package source
You can download and install this package in your Unity project and modify the package source code. You can do that by one of the following methods:
1. Clone this repository in any folder on your computer. Install it with `Package Manager --> Add package from disk...`.
2. Clone this repository inside the `Packages` folder in your Unity project.
Loading