Skip to content

Commit

Permalink
start making GPSPublisher as per #23
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbrownmsm committed Dec 25, 2024
1 parent fbdcb1e commit af067da
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 39 deletions.
40 changes: 5 additions & 35 deletions Assets/Models/SwerveChassis.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 19703c438129631468fb69e0c459738b, type: 3}
m_Name:
m_EditorClassIdentifier:
drive_: 0
strafe_: 0
steer_: 0
drive: 0
strafe: 0
steer: 0
theta: 0
phi: 0
--- !u!114 &4044432513042082616
Expand All @@ -98,10 +92,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3724515de715a8f4e8ceba5c18255ac8, type: 3}
m_Name:
m_EditorClassIdentifier:
rigidBody: {fileID: 2094054056846038145}
CogX: 0
CogY: 0
CogZ: 0
chassisModel: {fileID: 9143162812384560785}
--- !u!1 &2110196124466543421
GameObject:
Expand Down Expand Up @@ -354,13 +344,13 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6038452864022524759}
serializedVersion: 2
m_LocalRotation: {x: 0.21263108, y: -0.67437977, z: 0.21263108, w: 0.67437977}
m_LocalRotation: {x: 0.18301274, y: -0.6830127, z: 0.18301274, w: 0.6830127}
m_LocalPosition: {x: -2, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8981353182278466628}
m_LocalEulerAnglesHint: {x: 35, y: -90, z: 0}
m_LocalEulerAnglesHint: {x: 30, y: -90, z: 0}
--- !u!20 &5533988587421443465
Camera:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -542,13 +532,13 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7850006732108450847}
serializedVersion: 2
m_LocalRotation: {x: 0.21263108, y: 0.67437977, z: -0.21263108, w: 0.67437977}
m_LocalRotation: {x: 0.18301274, y: 0.6830127, z: -0.18301274, w: 0.6830127}
m_LocalPosition: {x: 1.5, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 8981353182278466628}
m_LocalEulerAnglesHint: {x: 35, y: 90, z: 0}
m_LocalEulerAnglesHint: {x: 30, y: 90, z: 0}
--- !u!20 &4232470027967802732
Camera:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -833,7 +823,7 @@ Transform:
m_GameObject: {fileID: 8590054307612676665}
serializedVersion: 2
m_LocalRotation: {x: 0.2588199, y: -0, z: -0, w: 0.9659257}
m_LocalPosition: {x: 0, y: 0, z: 2}
m_LocalPosition: {x: 0, y: 0, z: 2.41}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
Expand Down Expand Up @@ -1183,11 +1173,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
wheelModel: {fileID: 7191232063989482968}
wheelCollider: {fileID: 2809360073453790076}
pos: 0
debugRotation: 0
debugSteerSetpoint: 0
debugDriveSetpoint: 0
debugVelocity: 0
--- !u!1001 &2224983793712491899
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1396,11 +1381,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
wheelModel: {fileID: 1831280071223446160}
wheelCollider: {fileID: 1406153199344676264}
pos: 2
debugRotation: 0
debugSteerSetpoint: 0
debugDriveSetpoint: 0
debugVelocity: 0
--- !u!4 &4601474858310787653 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: a3b86a2c4324a8942b6bfeb09cb57839, type: 3}
Expand Down Expand Up @@ -1614,11 +1594,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
wheelModel: {fileID: 4108097460041500886}
wheelCollider: {fileID: 3781738964313370011}
pos: 1
debugRotation: 0
debugSteerSetpoint: 0
debugDriveSetpoint: 0
debugVelocity: 0
--- !u!4 &5212277597321823952 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: a3b86a2c4324a8942b6bfeb09cb57839, type: 3}
Expand Down Expand Up @@ -1837,11 +1812,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
wheelModel: {fileID: 8803487471369810799}
wheelCollider: {fileID: 8012853228733047024}
pos: 3
debugRotation: 0
debugSteerSetpoint: 0
debugDriveSetpoint: 0
debugVelocity: 0
--- !u!1001 &9054201500550829188
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down
27 changes: 26 additions & 1 deletion Assets/Scenes/maps/2025.unity
Original file line number Diff line number Diff line change
Expand Up @@ -55708,7 +55708,10 @@ PrefabInstance:
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 2257797244222251143, guid: 8106eb0b21f001a4199fb16375ed97ef, type: 3}
insertIndex: -1
addedObject: {fileID: 1783415240}
m_SourcePrefab: {fileID: 100100000, guid: 8106eb0b21f001a4199fb16375ed97ef, type: 3}
--- !u!1001 &1289104148
PrefabInstance:
Expand Down Expand Up @@ -81109,6 +81112,28 @@ BoxCollider:
serializedVersion: 3
m_Size: {x: 10, y: 2.220446e-16, z: 10}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &1783415238 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 2257797244222251143, guid: 8106eb0b21f001a4199fb16375ed97ef, type: 3}
m_PrefabInstance: {fileID: 1288745284}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1783415240
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1783415238}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ee1ecb89704ca8440ae5adfd1ffae7a9, type: 3}
m_Name:
m_EditorClassIdentifier:
ros: {fileID: 0}
topicName: /autonav/gps/
latitude: 0
longitude: 0
robot: {fileID: 0}
--- !u!1 &1783447017 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 2836819319387312741, guid: 1f38c74b7998c4b4982791e87d9ca44e, type: 3}
Expand Down
52 changes: 52 additions & 0 deletions Assets/Scripts/RosInterface/GPSPublisher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using UnityEngine;
using Unity.Robotics.ROSTCPConnector;
using RosMessageTypes.Autonav;

public class GPSPublisher : MonoBehaviour {
public ROSConnection ros;
public string topicName = "/autonav/gps/";
private float publishRate = 1f / 5f; // internal GPS receiver on the VectorNav updates at like 5 Hz according to the ICD or whatever, TODO make this configurable
private float lastPublishTime = 0;

public float latitude = 0.0f;
public float longitude = 0.0f;

// public Transform robot;

void Start() {
// start the ROS connection
ros = ROSConnection.GetOrCreateInstance();
ros.RegisterPublisher<GPSFeedbackMsg>(topicName);
}

void FixedUpdate() {
// don't publish if we're paused
if (SettingsManager.paused) {
return;
}

// publish at the publish rate
if (Time.time - lastPublishTime < 1f / publishRate) {
return;
}

lastPublishTime = Time.time;

// don't kill the framerate trying to publish if we haven't established a connection yet
// if (!ros.HasConnectionError) {
latitude = (transform.position.z - 25.98906) / 1f; //FIXME (z - 25.98906)
longitude = (transform.position.x - 47.00509) / 1f; //FIXME (x - 47.00509)

// bottom right corner (first corner) is (lat, lon) => (31.42255, -17.09999)
// top right corner (second corner) is (lat, lon) => (-96.12039, -29.79432)

double altitude = 0.0f; // altitude doesn't matter for us
short gps_fix = 3; // see VN200-ICD page 55. Can be [0, 4] U [7, 8]. default of 3 is fine. can change later for testing TODO
bool is_locked = true; //TODO make this changable for testing
short satellites = 4; //TODO make this changeable for testing

GPSFeedbackMsg msg = new GPSFeedbackMsg(latitude, longitude, altitude, gps_fix, is_locked, satellites);
ros.Publish(topicName, msg);
// }
}
}
2 changes: 2 additions & 0 deletions Assets/Scripts/RosInterface/GPSPublisher.cs.meta

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

6 changes: 3 additions & 3 deletions Assets/Scripts/SwerveController/SwerveDrive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public void Drive(float drive_, float strafe_, float steer_) {
}

// scale the inputs (Unity stick/keyboard values should be in the range [-3, 3] or something I think)
drive *= 100;
strafe *= 100;
steer *= 100;
drive *= -50; //TODO what about the meters per second for the autonomous messages???
strafe *= -50;
steer *= -50;


float A = strafe - (steer * halfWheelbase);
Expand Down

0 comments on commit af067da

Please sign in to comment.