-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrainKinematics_deprecated.groovy
205 lines (170 loc) · 5.66 KB
/
TrainKinematics_deprecated.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import com.neuronrobotics.bowlerkernel.Bezier3d.*;
import com.neuronrobotics.bowlerstudio.BowlerStudio
import com.neuronrobotics.bowlerstudio.BowlerStudioController
import com.neuronrobotics.bowlerstudio.creature.MobileBaseLoader
import com.neuronrobotics.bowlerstudio.physics.TransformFactory
import com.neuronrobotics.sdk.addons.kinematics.AbstractLink
import com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics
import com.neuronrobotics.sdk.addons.kinematics.ILinkListener
import com.neuronrobotics.sdk.addons.kinematics.MobileBase
import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR
import com.neuronrobotics.sdk.common.DeviceManager
import com.neuronrobotics.sdk.common.InvalidConnectionException
import com.neuronrobotics.sdk.pid.PIDLimitEvent
import eu.mihosoft.vrl.v3d.Transform
nameOfCOntroller="PathController"
class PathController{
def numBezierPieces = 20
boolean connected = false;
String name
ILinkListener ll=null;
AbstractLink motor;
BezierEditor editor
BezierEditor editor2
BezierEditor editor3
BezierEditor editor4
def unitTFs = []
def transforms
def tfLengths
double total=0;
public PathController(String n) {
name=n
}
public String getName() {
return name
}
public void setPath(ArrayList<TransformNR> tfs) {
transforms=tfs
for(int i=0;i<transforms.size()-1;i++) {
TransformNR start = transforms.get(i)
TransformNR end = transforms.get(i+1)
unitTFs.add(start.inverse().times(end))
}
tfLengths = unitTFs.collect{
return Math.sqrt(Math.pow(it.getX(), 2) + Math.pow(it.getY(), 2)+Math.pow(it.getZ(), 2))
}
println tfLengths
for(int i=0;i<tfLengths.size();i++) {
total+=tfLengths.get(i)
}
println "total length = "+total
}
public boolean connect(){
connected=true;
def URL="https://github.com/TechnocopiaPlant/TendyTheTankEngine.git"
editor = new BezierEditor(ScriptingEngine.fileFromGit(URL, "bez.json"),numBezierPieces)
editor2 = new BezierEditor(ScriptingEngine.fileFromGit(URL, "bez2.json"),numBezierPieces)
editor3 = new BezierEditor(ScriptingEngine.fileFromGit(URL, "bez3.json"),numBezierPieces)
editor4 = new BezierEditor(ScriptingEngine.fileFromGit(URL, "bez4.json"),numBezierPieces)
editor4.setCP2(editor4.cp2Manip.getX(),editor4.cp2Manip.getY(),50)
editor4.setEnd(0,0,0)
editor.addBezierToTheEnd(editor2)
editor2.addBezierToTheEnd(editor3)
editor3.addBezierToTheEnd(editor4)
//editor.setStart(-100, 0, 0)
def y=[]
y.addAll(editor.transforms())
y.addAll(editor2.transforms())
y.addAll(editor3.transforms())
y.addAll(editor4.transforms())
setPath(y.collect{ TransformFactory.csgToNR(it)})
MobileBase base=DeviceManager.getSpecificDevice( "TendyTheTankEngine",{
MobileBase m = MobileBaseLoader.fromGit(
"https://github.com/TechnocopiaPlant/TendyTheTankEngine.git",
"TendyTheTankEngine.xml"
)
return m
})
DHParameterKinematics drive=null
for(DHParameterKinematics k:base.getAllDHChains() ) {
if(k.getScriptingName().contentEquals("DriveCarrage")) {
drive=k;
}
}
drive.setMaxEngineeringUnits(0, total-1)
drive.setMinEngineeringUnits(0, 0)
motor = drive.getAbstractLink(0)
ll =new ILinkListener() {
/**
* On link position update.
*
* @param source the source
* @param engineeringUnitsValue the engineering units value
*/
public void onLinkPositionUpdate(AbstractLink source,double engineeringUnitsValue) {
//
TransformNR loc = poseAtLocation( engineeringUnitsValue)
drive.setRobotToFiducialTransform(loc)
}
/**
* On the event of a limit, this is called.
*
* @param source the source
* @param event the event
*/
public void onLinkLimit(AbstractLink source,PIDLimitEvent event) {
}
}
motor.addLinkListener(ll)
motor.fireLinkListener(motor.getCurrentEngineeringUnits())
if(drive==null)
throw new RuntimeException("Dive secion is missing, can not contine!");
return isAvailable();
}
public double getTotal() {
return total;
}
public Transform CADposeAtLocation(double engineeringUnitsValue) {
return TransformFactory.nrToCSG(poseAtLocation(engineeringUnitsValue) )
}
public TransformNR poseAtLocation(double engineeringUnitsValue) {
double distance=0;
int tfIndex=-1;
double unitDIstance=0;
for(int i=0;i<tfLengths.size();i++) {
double distStart = distance
distance+=tfLengths.get(i)
if(distance>engineeringUnitsValue && tfIndex<0) {
tfIndex=i;
unitDIstance = 1-(distance-engineeringUnitsValue)/tfLengths.get(i)
break;
}
}
//println "Path.groovy update "+engineeringUnitsValue+" tf index = "+tfIndex+" unit Distance = "+unitDIstance
TransformNR location = transforms.get(tfIndex)
TransformNR intermediate = unitTFs.get(tfIndex).scale(unitDIstance)
return location.times(intermediate)
}
/**
* Determines if the device is available.
*
* @return true if the device is avaiable, false if it is not
* @throws InvalidConnectionException the invalid connection exception
*/
public boolean isAvailable() throws InvalidConnectionException{
return connected;
}
/**
* This method tells the connection object to disconnect its pipes and close out the connection. Once this is called, it is safe to remove your device.
*/
public void disconnect(){
motor.removeLinkListener(ll)
get().collect{BowlerStudioController.removeObject(it)}
connected = false;
}
ArrayList<Object> get(){
def back=[]
back.addAll(editor.get())
back.addAll(editor2.get())
back.addAll(editor3.get())
back.addAll(editor4.get())
return back
}
}
def pc = DeviceManager.getSpecificDevice(nameOfCOntroller, {
def pc = new PathController(nameOfCOntroller)
pc.connect()
return pc
})
pc.get().collect{BowlerStudioController.addObject(it, null)}
return null