Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit

Permalink
fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
esm-tmori committed Jul 12, 2020
1 parent 6cac0ad commit 86a5079
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
27 changes: 18 additions & 9 deletions Assets/Scripts/Hakoniwa/Assets/EV3/RobotController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ private void InitActuator()
motor_b.Initialize(obj);
this.motor_b_sensor = obj.GetComponentInChildren<Hakoniwa.Assets.IRobotMotorSensor>();

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<Hakoniwa.Assets.IRobotMotor>();
motor_arm.Initialize(obj);
this.motor_arm_sensor = obj.GetComponentInChildren<Hakoniwa.Assets.IRobotMotorSensor>();
Expand All @@ -106,15 +107,17 @@ private void InitSensor()
ultrasonicSensor = obj.GetComponentInChildren<Hakoniwa.Assets.IRobotUltraSonicSensor>();
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<Hakoniwa.Assets.IRobotTouchSensor>();
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<Hakoniwa.Assets.IRobotGyroSensor>();
gyroSensor.Initialize(obj);
}
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions Assets/Scripts/Hakoniwa/Assets/HackEV/HackEVParts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -39,12 +41,12 @@ public string getTouchSensor()

public string getGyroSensor()
{
return null;
return gyro_sensor;
}

public string GetMotorC()
{
return null;
return motor_arm;
}
}
}

0 comments on commit 86a5079

Please sign in to comment.