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

Commit a72701c

Browse files
committed
add new sample
1 parent 41c2e0a commit a72701c

File tree

8 files changed

+130
-19
lines changed

8 files changed

+130
-19
lines changed

Assets/Scripts/Hakoniwa/Assets/EV3/IEV3Parts.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public interface IEV3Parts
1111
string GetMotorC();
1212
string GetColorSensor();
1313
string getUltraSonicSensor();
14-
string getTouchSensor();
14+
string getTouchSensor0();
15+
string getTouchSensor1();
1516
string getGyroSensor();
1617
}
1718
}

Assets/Scripts/Hakoniwa/Assets/EV3/RobotController.cs

+32-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public class RobotController : MonoBehaviour, IAssetController
2525
private Hakoniwa.Assets.IRobotMotorSensor motor_arm_sensor;
2626
private Hakoniwa.Assets.IRobotColorSensor colorSensor;
2727
private Hakoniwa.Assets.IRobotUltraSonicSensor ultrasonicSensor;
28-
private Hakoniwa.Assets.IRobotTouchSensor touchSensor;
28+
private Hakoniwa.Assets.IRobotTouchSensor touchSensor0;
29+
private Hakoniwa.Assets.IRobotTouchSensor touchSensor1;
2930
private Hakoniwa.Assets.IRobotGyroSensor gyroSensor;
3031
private bool isConnected;
3132
private ulong micon_simtime;
@@ -111,12 +112,19 @@ private void InitSensor()
111112
ultrasonicSensor = obj.GetComponentInChildren<Hakoniwa.Assets.IRobotUltraSonicSensor>();
112113
ultrasonicSensor.Initialize(obj);
113114

114-
string parts = this.parts.getTouchSensor();
115+
string parts = this.parts.getTouchSensor0();
115116
if (parts != null)
116117
{
117-
obj = root.transform.Find(this.transform.name + "/" + this.parts.getTouchSensor()).gameObject;
118-
touchSensor = obj.GetComponentInChildren<Hakoniwa.Assets.IRobotTouchSensor>();
119-
touchSensor.Initialize(obj);
118+
obj = root.transform.Find(this.transform.name + "/" + this.parts.getTouchSensor0()).gameObject;
119+
touchSensor0 = obj.GetComponentInChildren<Hakoniwa.Assets.IRobotTouchSensor>();
120+
touchSensor0.Initialize(obj);
121+
}
122+
parts = this.parts.getTouchSensor1();
123+
if (parts != null)
124+
{
125+
obj = root.transform.Find(this.transform.name + "/" + this.parts.getTouchSensor1()).gameObject;
126+
touchSensor1 = obj.GetComponentInChildren<Hakoniwa.Assets.IRobotTouchSensor>();
127+
touchSensor1.Initialize(obj);
120128
}
121129
parts = this.parts.getGyroSensor();
122130
if (parts != null)
@@ -144,17 +152,30 @@ private void UpdateSensor()
144152

145153
colorSensor.UpdateSensorValues();
146154
ultrasonicSensor.UpdateSensorValues();
147-
if (touchSensor != null)
155+
if (touchSensor0 != null)
156+
{
157+
touchSensor0.UpdateSensorValues();
158+
if (this.touchSensor0.IsPressed())
159+
{
160+
//Debug.Log("Touched0:");
161+
this.writer.Set("touch_sensor0", 4095);
162+
}
163+
else
164+
{
165+
this.writer.Set("touch_sensor0", 0);
166+
}
167+
}
168+
if (touchSensor1 != null)
148169
{
149-
touchSensor.UpdateSensorValues();
150-
if (this.touchSensor.IsPressed())
170+
touchSensor1.UpdateSensorValues();
171+
if (this.touchSensor1.IsPressed())
151172
{
152-
//Debug.Log("Touched:");
153-
this.writer.Set("touch_sensor", 4095);
173+
//Debug.Log("Touched1:");
174+
this.writer.Set("touch_sensor1", 4095);
154175
}
155176
else
156177
{
157-
this.writer.Set("touch_sensor", 0);
178+
this.writer.Set("touch_sensor1", 0);
158179
}
159180
}
160181
if (gyroSensor != null)

Assets/Scripts/Hakoniwa/Assets/EduRobot.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
using Hakoniwa.Assets.EV3;
6+
7+
namespace Hakoniwa.Assets.EduRobot
8+
{
9+
public class EduRobotParts : MonoBehaviour, IEV3Parts
10+
{
11+
private string motor_a = "RoboModel_Axis/EV3_LeftMotor/HackEV_L8_Wheel2/L8_Tire_Bk";
12+
private string motor_b = "RoboModel_Axis/EV3_RightMotor/HackEV_L8_Wheel/L8_Tire_Bk 1";
13+
private string color_sensor = "RoboModel_Axis/EV3_ColorSensor/EV3_ColorSensor_Wh06/ColorSensor";
14+
private string ultra_sonic_sensor = "RoboModel_Axis/EV3_Sidewinder_Head/EV3_UltrasonicSensor/EV3_UltrasonicSensor_Bk10";
15+
private string touch_sensor0 = "RoboModel_Axis/EV3_TouchSensor/TouchSensor";
16+
private string touch_sensor1 = "RoboModel_Axis/EV3_Bumper/Bumper_Front";
17+
18+
public string GetColorSensor()
19+
{
20+
return color_sensor;
21+
}
22+
23+
public string GetMotorA()
24+
{
25+
return motor_a;
26+
}
27+
28+
public string GetMotorB()
29+
{
30+
return motor_b;
31+
}
32+
33+
public string getUltraSonicSensor()
34+
{
35+
return ultra_sonic_sensor;
36+
}
37+
public string getTouchSensor0()
38+
{
39+
return touch_sensor0;
40+
}
41+
42+
public string getGyroSensor()
43+
{
44+
return null;
45+
}
46+
47+
public string GetMotorC()
48+
{
49+
return null;
50+
}
51+
52+
string IEV3Parts.getTouchSensor1()
53+
{
54+
return touch_sensor1;
55+
}
56+
}
57+
}

Assets/Scripts/Hakoniwa/Assets/EduRobot/EduRobotParts.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Hakoniwa/Assets/HackEV/HackEVParts.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class HackEVParts : MonoBehaviour, IEV3Parts
1414
private string ultra_sonic_sensor = "RoboModel_Axis/HackEV_L8_Sidewinder_Head/EV3_UltrasonicSensor/EV3_UltrasonicSensor_Bk10";
1515
private string gyro_sensor = "RoboModel_Axis/HackEV_L8_Sidewinder_Head/EV3_GyroSensor/EV3_GyroSensor_Ash01";
1616
private string motor_arm = "RoboModel_Axis/HackEV_L8_MiddleMotor/EV3_InteractiveServoMotor_L/EV3_InteractiveServoMotor_L_MotorRoot";
17-
private string touch_sensor = "RoboModel_Axis/HackEV_L9_Sidewinder_ShoulderSensor/HackEV_L8_TouchSensor2/L8_DoubleBevelGear20_Bk 1";
17+
private string touch_sensor0 = "RoboModel_Axis/HackEV_L9_Sidewinder_ShoulderSensor/HackEV_L8_TouchSensor2/L8_DoubleBevelGear20_Bk 1";
1818

1919
public string GetColorSensor()
2020
{
@@ -35,9 +35,9 @@ public string getUltraSonicSensor()
3535
{
3636
return ultra_sonic_sensor;
3737
}
38-
public string getTouchSensor()
38+
public string getTouchSensor0()
3939
{
40-
return touch_sensor;
40+
return touch_sensor0;
4141
}
4242

4343
public string getGyroSensor()
@@ -49,5 +49,10 @@ public string GetMotorC()
4949
{
5050
return motor_arm;
5151
}
52+
53+
string IEV3Parts.getTouchSensor1()
54+
{
55+
return null;
56+
}
5257
}
5358
}

Assets/Scripts/Hakoniwa/Assets/Jeep/JeepParts.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ public string getUltraSonicSensor()
3333
{
3434
return ultra_sonic_sensor;
3535
}
36-
public string getTouchSensor()
36+
public string getTouchSensor0()
37+
{
38+
return null;
39+
}
40+
public string getTouchSensor1()
3741
{
3842
return null;
3943
}

Assets/Scripts/Hakoniwa/Assets/SimpleRobot/SimpleRobotParts.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class SimpleRobotParts : MonoBehaviour, IEV3Parts
1313
private string motor_b = "Tire2";
1414
private string color_sensor = "Axle/SensorHolder/SensorBox/ColorSensor";
1515
private string ultra_sonic_sensor = "Axle/SensorHolder/SensorBox/UltrasonicSensor";
16-
private string touch_sensor = "Axle/TouchSensor";
16+
private string touch_sensor0 = "Axle/TouchSensor";
1717
private string gyro_sensor = "Axle/GyroSensor";
1818
private string motor_arm = "Axle/Arm/ArmMotor";
1919

@@ -36,9 +36,13 @@ public string getUltraSonicSensor()
3636
{
3737
return ultra_sonic_sensor;
3838
}
39-
public string getTouchSensor()
39+
public string getTouchSensor0()
4040
{
41-
return touch_sensor;
41+
return touch_sensor0;
42+
}
43+
public string getTouchSensor1()
44+
{
45+
return null;
4246
}
4347
public string getGyroSensor()
4448
{

0 commit comments

Comments
 (0)