Skip to content

Commit c6e40ad

Browse files
Christopher BlakeChristopher Blake
authored andcommitted
2 parents 959e6a6 + 7b80e23 commit c6e40ad

File tree

1 file changed

+52
-12
lines changed

1 file changed

+52
-12
lines changed

BlackBox/BlackBox/Samples/RoboticArm.cs

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ namespace BlackBoxModeling.Samples
77
public class RoboticArm : BlackBox
88
{
99
//Fields
10-
double theta1 = 0;
11-
double theta2 = 0;
10+
const double LENGTH1 = 300; //mm
11+
double theta1 = 225; //degrees (180 to 315)
12+
double length2 = 150; //mm (100 to 300)
13+
double theta3 = 225; //degrees (90 to 180)
14+
const double LENGTH3 = 50; //mm
15+
double x = 0;
16+
double y = 0;
1217

1318
//Constructors
1419
public RoboticArm()
@@ -19,10 +24,14 @@ public RoboticArm()
1924
//Define inputs
2025
AddInput("Motor1");
2126
AddInput("Motor2");
27+
AddInput("Motor3");
2228

2329
//Define outputs
2430
AddOutput("Theta1");
25-
AddOutput("Theta2");
31+
AddOutput("Length2");
32+
AddOutput("Theta3");
33+
AddOutput("x");
34+
AddOutput("y");
2635

2736
//Specify responsiveness
2837
this.TimeInterval_ms = 250; //i.e. The model needs 0.250 seconds to convert the input into a new output.
@@ -34,20 +43,51 @@ public override void Run()
3443

3544
double voltageMotor1 = Convert.ToDouble(i["Motor1"]);
3645
double voltageMotor2 = Convert.ToDouble(i["Motor2"]);
46+
double voltageMotor3 = Convert.ToDouble(i["Motor3"]);
3747

38-
//Update theta1 (0 to 360deg)
39-
theta1 = (theta1 + (0.1 * voltageMotor1)) % 360;
48+
//Update theta1
49+
theta1 = theta1 + (0.1 * voltageMotor1);
50+
if (theta1 <= 180)
51+
theta1 = 180;
52+
else if (theta1 >= 315)
53+
theta1 = 315;
4054

41-
//Update theta2 (-80 to 90 deg)
42-
theta2 = theta2 + (0.1 * voltageMotor2);
43-
if (theta2 <= -80)
44-
theta2 = -80;
45-
else if (theta2 >= 90)
46-
theta2 = 90;
55+
//Update theta2
56+
length2 = length2 + (0.1 * voltageMotor2);
57+
if (length2 <= 100)
58+
length2 = 100;
59+
else if (length2 >= 300)
60+
length2 = 300;
61+
62+
//Update theta3
63+
theta3 = theta3 + (0.1 * voltageMotor1);
64+
if (theta3 <= 180)
65+
theta3 = 180;
66+
else if (theta3 >= 315)
67+
theta3 = 315;
68+
69+
//Update x and y coordinates of end factor
70+
double theta1abs = 180 + theta1;
71+
double theta3abs = theta1abs - 180 + theta3;
72+
x = LENGTH1
73+
+ Math.Cos(Radians(theta1abs)) * length2
74+
+ Math.Cos(Radians(theta3abs)) * LENGTH3;
75+
y = 0
76+
+ Math.Sin(Radians(theta1abs)) * length2
77+
+ Math.Sin(Radians(theta3abs)) * LENGTH3;
4778

4879
//Update outputs
4980
o["Theta1"] = theta1;
50-
o["Theta2"] = theta2;
81+
o["Length2"] = length2;
82+
o["Theta3"] = theta3;
83+
o["x"] = x;
84+
o["y"] = y;
85+
}
86+
87+
//Methods
88+
double Radians(double degrees)
89+
{
90+
return degrees * Math.PI / 180.0;
5191
}
5292
}
5393
}

0 commit comments

Comments
 (0)