@@ -7,8 +7,13 @@ namespace BlackBoxModeling.Samples
7
7
public class RoboticArm : BlackBox
8
8
{
9
9
//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 ;
12
17
13
18
//Constructors
14
19
public RoboticArm ( )
@@ -19,10 +24,14 @@ public RoboticArm()
19
24
//Define inputs
20
25
AddInput ( "Motor1" ) ;
21
26
AddInput ( "Motor2" ) ;
27
+ AddInput ( "Motor3" ) ;
22
28
23
29
//Define outputs
24
30
AddOutput ( "Theta1" ) ;
25
- AddOutput ( "Theta2" ) ;
31
+ AddOutput ( "Length2" ) ;
32
+ AddOutput ( "Theta3" ) ;
33
+ AddOutput ( "x" ) ;
34
+ AddOutput ( "y" ) ;
26
35
27
36
//Specify responsiveness
28
37
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()
34
43
35
44
double voltageMotor1 = Convert . ToDouble ( i [ "Motor1" ] ) ;
36
45
double voltageMotor2 = Convert . ToDouble ( i [ "Motor2" ] ) ;
46
+ double voltageMotor3 = Convert . ToDouble ( i [ "Motor3" ] ) ;
37
47
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 ;
40
54
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 ;
47
78
48
79
//Update outputs
49
80
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 ;
51
91
}
52
92
}
53
93
}
0 commit comments