forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulateMotionData.js
More file actions
64 lines (56 loc) · 2.25 KB
/
populateMotionData.js
File metadata and controls
64 lines (56 loc) · 2.25 KB
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
var fs = require('fs');
var parseString = require('xml2js').parseString;
var pageData = {};
var flowData = {};
var MILLIS_PER_FRAME = 8; // This is a guess based on reading docs such as http://support.robotis.com/en/software/roboplus/roboplus_motion/motionedit/stepedit/roboplus_motion_pausetime.htm
var UNIT_PADDING_TIME = 100; // Another guess of how long to wait before motion is truly done
var RECOVERY_TIME = 300; // Another guess of how long to wait before motion is truly done
function elapsedTime(flow)
{
var millis = 0;
if (flow.$.return == '-1') // This flow has a finite time and returns
{
var units = flow.units[0].unit;
units.forEach(function (unit)
{
var pageName = unit.$.main;
var steps = pageData[pageName].steps[0].step;
var lastFrame = Number(steps[steps.length - 1].$.frame);
millis += (lastFrame * MILLIS_PER_FRAME + UNIT_PADDING_TIME) * unit.$.exitSpeed * unit.$.loop;
millis += RECOVERY_TIME;
});
}
return millis;
}
module.exports = function populateMotionData(motionData, normalizeCommandName)
{
motionData.flowsByNumber = {};
motionData.flowsByName = {};
parseString(fs.readFileSync(__dirname + '/assets/assumedMotionFile.mtnx', { encoding: 'utf8' }), function (err, parsed)
{
motionData.raw = parsed;
// Create a reference map of pages, to use in calculating the elapsed time for each command
parsed.Root.PageRoot[0].Page.forEach(function (page)
{
pageData[page.$.name] = page;
});
// Create a reference map of flows
parsed.Root.FlowRoot[0].Flow.forEach(function (flow)
{
flowData[flow.$.name] = flow;
});
var callFlows = parsed.Root.BucketRoot[0].Bucket[0].callFlows[0].callFlow;
callFlows.forEach(function (callFlow)
{
var flowNumber = callFlow.$.callIndex;
var flowName = callFlow.$.flow;
var flow = flowData[flowName];
motionData.flowsByNumber[flowNumber] =
{
name: flowName,
time: elapsedTime(flow)
};
motionData.flowsByName[normalizeCommandName(flowName)] = flowNumber;
});
});
};