From d552972f51596710a656a428badb38f965af7eaa Mon Sep 17 00:00:00 2001 From: Noah Zemlin Date: Tue, 11 Feb 2020 19:28:42 -0600 Subject: [PATCH] Remove nrc DriveCommand for nrc Motors --- .../DriveCommandSubscriber.cs | 32 ----------------- ...sSubscriber.cs => IGVCMotorsSubscriber.cs} | 2 +- ...r.cs.meta => IGVCMotorsSubscriber.cs.meta} | 0 .../ROSSharp Modules/NRCMotorsSubscriber.cs | 24 +++++++++++++ ...er.cs.meta => NRCMotorsSubscriber.cs.meta} | 2 +- Assets/Robots/NRC_Robot.asset | 4 +-- Assets/Robots/NRC_Robot.prefab | 3 +- Assets/RosSharpMessages/Nrc/msg/Motors.cs | 34 +++++++++++++++++++ .../RosSharpMessages/Nrc/msg/Motors.cs.meta | 11 ++++++ Assets/Scripts/IGVCConfigLoader.cs | 4 +-- Assets/Scripts/NRCConfigLoader.cs | 6 ++-- Assets/Scripts/SimpleCarController.cs | 5 --- Assets/StreamingAssets/build_info | 2 +- 13 files changed, 80 insertions(+), 49 deletions(-) delete mode 100644 Assets/ROSSharp Modules/DriveCommandSubscriber.cs rename Assets/ROSSharp Modules/{MotorsSubscriber.cs => IGVCMotorsSubscriber.cs} (88%) rename Assets/ROSSharp Modules/{MotorsSubscriber.cs.meta => IGVCMotorsSubscriber.cs.meta} (100%) create mode 100644 Assets/ROSSharp Modules/NRCMotorsSubscriber.cs rename Assets/ROSSharp Modules/{DriveCommandSubscriber.cs.meta => NRCMotorsSubscriber.cs.meta} (83%) create mode 100644 Assets/RosSharpMessages/Nrc/msg/Motors.cs create mode 100644 Assets/RosSharpMessages/Nrc/msg/Motors.cs.meta diff --git a/Assets/ROSSharp Modules/DriveCommandSubscriber.cs b/Assets/ROSSharp Modules/DriveCommandSubscriber.cs deleted file mode 100644 index 52b9714..0000000 --- a/Assets/ROSSharp Modules/DriveCommandSubscriber.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace RosSharp.RosBridgeClient.MessageTypes.Nrc -{ - public class DriveCommandSubscriber : UnitySubscriber - { - private SimpleCarController car; - - private DriveStatusPublisher pubby; - - protected override void Start() - { - base.Start(); - car = GetComponent(); - pubby = GetComponent(); - } - - protected override void ReceiveMessage(DriveCommand motors) - { - float curHeading = pubby.message.yaw; - - float delta = motors.heading - curHeading; - delta = (delta + 180) % 360 - 180; - - car.leftControl = motors.speed + (delta / 180); - car.rightControl = motors.speed - (delta / 180); - - } - } -} diff --git a/Assets/ROSSharp Modules/MotorsSubscriber.cs b/Assets/ROSSharp Modules/IGVCMotorsSubscriber.cs similarity index 88% rename from Assets/ROSSharp Modules/MotorsSubscriber.cs rename to Assets/ROSSharp Modules/IGVCMotorsSubscriber.cs index 20bedd1..14066fa 100644 --- a/Assets/ROSSharp Modules/MotorsSubscriber.cs +++ b/Assets/ROSSharp Modules/IGVCMotorsSubscriber.cs @@ -4,7 +4,7 @@ namespace RosSharp.RosBridgeClient.MessageTypes.Igvc { - public class MotorsSubscriber : UnitySubscriber + public class IGVCMotorsSubscriber : UnitySubscriber { private SimpleCarController car; diff --git a/Assets/ROSSharp Modules/MotorsSubscriber.cs.meta b/Assets/ROSSharp Modules/IGVCMotorsSubscriber.cs.meta similarity index 100% rename from Assets/ROSSharp Modules/MotorsSubscriber.cs.meta rename to Assets/ROSSharp Modules/IGVCMotorsSubscriber.cs.meta diff --git a/Assets/ROSSharp Modules/NRCMotorsSubscriber.cs b/Assets/ROSSharp Modules/NRCMotorsSubscriber.cs new file mode 100644 index 0000000..bfcce72 --- /dev/null +++ b/Assets/ROSSharp Modules/NRCMotorsSubscriber.cs @@ -0,0 +1,24 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace RosSharp.RosBridgeClient.MessageTypes.Nrc +{ + public class NRCMotorsSubscriber : UnitySubscriber + { + private SimpleCarController car; + + protected override void Start() + { + base.Start(); + car = GetComponent(); + } + + protected override void ReceiveMessage(Motors motors) + { + car.leftControl = motors.left; + car.rightControl = motors.right; + } + } +} + diff --git a/Assets/ROSSharp Modules/DriveCommandSubscriber.cs.meta b/Assets/ROSSharp Modules/NRCMotorsSubscriber.cs.meta similarity index 83% rename from Assets/ROSSharp Modules/DriveCommandSubscriber.cs.meta rename to Assets/ROSSharp Modules/NRCMotorsSubscriber.cs.meta index 8a9cb64..71bd0e0 100644 --- a/Assets/ROSSharp Modules/DriveCommandSubscriber.cs.meta +++ b/Assets/ROSSharp Modules/NRCMotorsSubscriber.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d2b35ee3f3eea854085dc8ffc433382a +guid: c4e82c4c4431d734caf9c4489410979e MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Robots/NRC_Robot.asset b/Assets/Robots/NRC_Robot.asset index da0979c..94ad8ca 100644 --- a/Assets/Robots/NRC_Robot.asset +++ b/Assets/Robots/NRC_Robot.asset @@ -20,8 +20,8 @@ MonoBehaviour: defaultValue: /nrc/camera/compressed - name: Drive Status Topic defaultValue: /nrc/sensor_data - - name: Drive Command Topic - defaultValue: /nrc/cmd + - name: Motors Topic + defaultValue: /nrc/motors - name: ROS Bridge IP defaultValue: localhost:9090 - name: Autonomous diff --git a/Assets/Robots/NRC_Robot.prefab b/Assets/Robots/NRC_Robot.prefab index 3b18a05..8f799e9 100644 --- a/Assets/Robots/NRC_Robot.prefab +++ b/Assets/Robots/NRC_Robot.prefab @@ -519,12 +519,11 @@ MonoBehaviour: m_GameObject: {fileID: 3740033819105132858} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: d2b35ee3f3eea854085dc8ffc433382a, type: 3} + m_Script: {fileID: 11500000, guid: c4e82c4c4431d734caf9c4489410979e, type: 3} m_Name: m_EditorClassIdentifier: Topic: TimeStep: 0 - tf: {fileID: 3740033819105132855} --- !u!1 &3740033819154644750 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/RosSharpMessages/Nrc/msg/Motors.cs b/Assets/RosSharpMessages/Nrc/msg/Motors.cs new file mode 100644 index 0000000..272cf04 --- /dev/null +++ b/Assets/RosSharpMessages/Nrc/msg/Motors.cs @@ -0,0 +1,34 @@ +/* + * This message is auto generated by ROS#. Please DO NOT modify. + * Note: + * - Comments from the original code will be written in their own line + * - Variable sized arrays will be initialized to array of size 0 + * Please report any issues at + * + */ + +using Newtonsoft.Json; + +namespace RosSharp.RosBridgeClient.MessageTypes.Nrc +{ + public class Motors : Message + { + [JsonIgnore] + public const string RosMessageName = "nrc_msgs/motors"; + + public float left; + public float right; + + public Motors() + { + this.left = 0.0f; + this.right = 0.0f; + } + + public Motors(float left, float right) + { + this.left = left; + this.right = right; + } + } +} diff --git a/Assets/RosSharpMessages/Nrc/msg/Motors.cs.meta b/Assets/RosSharpMessages/Nrc/msg/Motors.cs.meta new file mode 100644 index 0000000..bc8d1e9 --- /dev/null +++ b/Assets/RosSharpMessages/Nrc/msg/Motors.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f4655de4fb8f5ca43a833f94881fd5e8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/IGVCConfigLoader.cs b/Assets/Scripts/IGVCConfigLoader.cs index 1a13230..9395155 100644 --- a/Assets/Scripts/IGVCConfigLoader.cs +++ b/Assets/Scripts/IGVCConfigLoader.cs @@ -17,7 +17,7 @@ public class IGVCConfigLoader : MonoBehaviour private IMUPublisher iMUPublisher; private VelocityPublisher velocityPublisher; private GPSPublisher gPSPublisher; - private MotorsSubscriber motorsSubscriber; + private IGVCMotorsSubscriber motorsSubscriber; void Awake() { @@ -28,7 +28,7 @@ void Awake() iMUPublisher = this.GetComponent(); velocityPublisher = this.GetComponent(); gPSPublisher = this.GetComponent(); - motorsSubscriber = this.GetComponent(); + motorsSubscriber = this.GetComponent(); simpleCarController.useController = !RobotOptions.GetValue(robotName + "Autonomous").Equals("True"); rosConnector.RosBridgeServerUrl = "ws://" + RobotOptions.GetValue(robotName + "ROS Bridge IP"); diff --git a/Assets/Scripts/NRCConfigLoader.cs b/Assets/Scripts/NRCConfigLoader.cs index 67579ef..122467a 100644 --- a/Assets/Scripts/NRCConfigLoader.cs +++ b/Assets/Scripts/NRCConfigLoader.cs @@ -14,7 +14,7 @@ public class NRCConfigLoader : MonoBehaviour private RosConnector rosConnector; private ImagePublisher imagePublisher; private DriveStatusPublisher driveStatusPublisher; - private DriveCommandSubscriber driveCommandSubscriber; + private NRCMotorsSubscriber motorsSubscriber; void Awake() { @@ -22,13 +22,13 @@ void Awake() rosConnector = this.GetComponent(); imagePublisher = this.GetComponent(); driveStatusPublisher = this.GetComponent(); - driveCommandSubscriber = this.GetComponent(); + motorsSubscriber = this.GetComponent(); simpleCarController.useController = !RobotOptions.GetValue(robotName + "Autonomous").Equals("True"); rosConnector.RosBridgeServerUrl = "ws://" + RobotOptions.GetValue(robotName + "ROS Bridge IP"); imagePublisher.Topic = RobotOptions.GetValue(robotName + "Camera Topic"); driveStatusPublisher.Topic = RobotOptions.GetValue(robotName + "Drive Status Topic"); - driveCommandSubscriber.Topic = RobotOptions.GetValue(robotName + "Drive Command Topic"); + motorsSubscriber.Topic = RobotOptions.GetValue(robotName + "Motors Topic"); } } } \ No newline at end of file diff --git a/Assets/Scripts/SimpleCarController.cs b/Assets/Scripts/SimpleCarController.cs index 140132d..b871206 100644 --- a/Assets/Scripts/SimpleCarController.cs +++ b/Assets/Scripts/SimpleCarController.cs @@ -22,13 +22,8 @@ public class SimpleCarController : MonoBehaviour public bool useController = false; - private Rigidbody rb; - private MotorsSubscriber ms; - public void Start() { - this.rb = this.GetComponent(); - this.ms = this.GetComponent(); } public void FixedUpdate() diff --git a/Assets/StreamingAssets/build_info b/Assets/StreamingAssets/build_info index b40c4ce..59a7e07 100644 --- a/Assets/StreamingAssets/build_info +++ b/Assets/StreamingAssets/build_info @@ -1 +1 @@ -Build from DESKTOP-QVE6E0N at 2/3/2020 8:52:14 PM \ No newline at end of file +Build from DESKTOP-D8RUH2C at 2/11/2020 7:25:10 PM \ No newline at end of file