From 86a5079d57466009398705b2e5cf07e67ae3b97c Mon Sep 17 00:00:00 2001 From: tmori Date: Sun, 12 Jul 2020 11:47:02 +0900 Subject: [PATCH] fix #6 --- .../Hakoniwa/Assets/EV3/RobotController.cs | 27 ++++++++++++------- .../Hakoniwa/Assets/HackEV/HackEVParts.cs | 6 +++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Assets/Scripts/Hakoniwa/Assets/EV3/RobotController.cs b/Assets/Scripts/Hakoniwa/Assets/EV3/RobotController.cs index 1ef69e5..10d4a84 100644 --- a/Assets/Scripts/Hakoniwa/Assets/EV3/RobotController.cs +++ b/Assets/Scripts/Hakoniwa/Assets/EV3/RobotController.cs @@ -82,9 +82,10 @@ private void InitActuator() motor_b.Initialize(obj); this.motor_b_sensor = obj.GetComponentInChildren(); - obj = root.transform.Find(this.transform.name + "/" + this.parts.GetMotorC()).gameObject; - if (obj != null) + string parts = this.parts.GetMotorC(); + if (parts != null) { + obj = root.transform.Find(this.transform.name + "/" + this.parts.GetMotorC()).gameObject; this.motor_arm = obj.GetComponentInChildren(); motor_arm.Initialize(obj); this.motor_arm_sensor = obj.GetComponentInChildren(); @@ -106,15 +107,17 @@ private void InitSensor() ultrasonicSensor = obj.GetComponentInChildren(); ultrasonicSensor.Initialize(obj); - obj = root.transform.Find(this.transform.name + "/" + this.parts.getTouchSensor()).gameObject; - if (obj != null) + string parts = this.parts.getTouchSensor(); + if (parts != null) { + obj = root.transform.Find(this.transform.name + "/" + this.parts.getTouchSensor()).gameObject; touchSensor = obj.GetComponentInChildren(); touchSensor.Initialize(obj); } - obj = root.transform.Find(this.transform.name + "/" + this.parts.getGyroSensor()).gameObject; - if (obj != null) + parts = this.parts.getGyroSensor(); + if (parts != null) { + obj = root.transform.Find(this.transform.name + "/" + this.parts.getGyroSensor()).gameObject; gyroSensor = obj.GetComponentInChildren(); gyroSensor.Initialize(obj); } @@ -123,11 +126,14 @@ private void UpdateSensor() { motor_a_sensor.UpdateSensorValues(); motor_b_sensor.UpdateSensorValues(); - motor_arm_sensor.UpdateSensorValues(); + if (this.motor_arm_sensor != null) + { + motor_arm_sensor.UpdateSensorValues(); + this.writer.Set("motor_angle_c", (int)motor_arm_sensor.GetDegree()); + } this.writer.Set("motor_angle_a", (int)motor_a_sensor.GetDegree()); this.writer.Set("motor_angle_b", (int)motor_b_sensor.GetDegree()); - this.writer.Set("motor_angle_c", (int)motor_arm_sensor.GetDegree()); colorSensor.UpdateSensorValues(); ultrasonicSensor.UpdateSensorValues(); @@ -219,7 +225,10 @@ private void UpdateActuator() this.motor_a.SetTargetVelicty(power_a * powerConst); this.motor_b.SetTargetVelicty(power_b * powerConst); - this.motor_arm.SetTargetVelicty(power_c * this.armMotorConst); + if (this.motor_arm != null) + { + this.motor_arm.SetTargetVelicty(power_c * this.armMotorConst); + } } } diff --git a/Assets/Scripts/Hakoniwa/Assets/HackEV/HackEVParts.cs b/Assets/Scripts/Hakoniwa/Assets/HackEV/HackEVParts.cs index 31521e3..33b179e 100644 --- a/Assets/Scripts/Hakoniwa/Assets/HackEV/HackEVParts.cs +++ b/Assets/Scripts/Hakoniwa/Assets/HackEV/HackEVParts.cs @@ -12,6 +12,8 @@ public class HackEVParts : MonoBehaviour, IEV3Parts private string motor_b = "RoboModel_Axis/HackEV_L8_RightMotor/HackEV_L8_Wheel/L8_Tire_Bk 1"; private string color_sensor = "RoboModel_Axis/HackEV_L6_RC1_LightSensor/EV3_ColorSensor/EV3_ColorSensor_Wh06/ColorSensor"; private string ultra_sonic_sensor = "RoboModel_Axis/HackEV_L8_Sidewinder_Head/EV3_UltrasonicSensor/EV3_UltrasonicSensor_Bk10"; + private string gyro_sensor = "RoboModel_Axis/HackEV_L8_Sidewinder_Head/EV3_GyroSensor/EV3_GyroSensor_Ash01"; + private string motor_arm = "RoboModel_Axis/HackEV_L8_MiddleMotor/EV3_InteractiveServoMotor_L/EV3_InteractiveServoMotor_L_MotorRoot"; public string GetColorSensor() { @@ -39,12 +41,12 @@ public string getTouchSensor() public string getGyroSensor() { - return null; + return gyro_sensor; } public string GetMotorC() { - return null; + return motor_arm; } } }