ekms 9.6.3-beta.13 → 9.6.3-beta.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,6 +41,7 @@
41
41
  "([lower] (@<= arm || @<=claw))",
42
42
  "([open] (claw))",
43
43
  "([close] (claw))",
44
+ "([startPath|start] (path))",
44
45
  "([pathComponent])",
45
46
  "(<another> (point))",
46
47
  "([stop] ([drone|])?)",
@@ -49,6 +50,14 @@
49
50
  "((context.unit.dimension == 'time') [timeAtPoint|] (atPoint))"
50
51
  ],
51
52
  "bridges": [
53
+ {
54
+ "id": "startPath",
55
+ "isA": [
56
+ "verb"
57
+ ],
58
+ "bridge": "{ ...next(operator), path: after[0], operator: operator, interpolate: [{ property: 'operator' }, { property: 'path' }] }",
59
+ "semantic": "async ({context, remember, recall}) => {\n const point = await recall({ context: { marker: 'point' } })\n remember(context) \n remember(point) // put the last point before the startPath so when the new path is generated this is the start point\n }"
60
+ },
52
61
  {
53
62
  "id": "timeAtPoint",
54
63
  "before": [
@@ -101,7 +110,7 @@
101
110
  "repeatable"
102
111
  ],
103
112
  "bridge": "{\n ...next(operator), operator: operator, path: after[0], interpolate: append(default(operator.interpolate, [{ property: 'operator'}]), [{ property: 'path' }])\n }",
104
- "semantic": "async ({context, e, toArray, fragments, toEValue, toFinalValue, recall, objects}) => {\n const evaluated = await(e(context.path))\n const path = toEValue(evaluated)\n \n // TODO put this in a common place for use by do+patrol \n\n // ordinal to pause time in seconds \n let pauseTimeInSeconds = {}\n if (context.pause) {\n const timeAtPoints = toArray(context.pause.timeAtPoint)\n for (const timeAtPoint of timeAtPoints) {\n const instantiation = await fragments(\"quantity in seconds\", { quantity: timeAtPoint.time })\n const result = await e(instantiation)\n const seconds = toFinalValue(toFinalValue(result).amount)\n\n const points = await recall({ context: timeAtPoint.point.point, frameOfReference: path })\n for (const point of toArray(points)) {\n pauseTimeInSeconds[point.ordinal] = seconds\n }\n }\n }\n\n // get to the start of the patrol \n objects.current.path.push(path.points[0])\n objects.current.path.push({ aimOnly: true, ...path.points[1] })\n objects.current.path.push({ repeatStart: true })\n for (const point of path.points) {\n objects.current.path.push(point)\n if (pauseTimeInSeconds[point.ordinal]) {\n objects.current.path.push({ marker: 'pause', pauseSeconds: pauseTimeInSeconds[point.ordinal] })\n }\n }\n if (context.repeats) {\n objects.current.timeRepeats = toFinalValue(context.repeats.repeats)\n }\n // if the patrol does not start and end at the same spot then \n // go back to the start along the same path\n\n\n // if the start is not the end of the patrol then go backwards along the patrol\n if (JSON.stringify(path.points[0].point) !== JSON.stringify(path.points[path.points.length-1].point)) {\n for (const point of [...path.points].reverse().slice(1)) {\n objects.current.path.push(point)\n if (pauseTimeInSeconds[point.ordinal]) {\n objects.current.path.push({ marker: 'pause', pauseSeconds: pauseTimeInSeconds[point.ordinal] })\n }\n }\n\n const secondPoint = path.points[1]\n objects.current.path.push({ ...secondPoint, aimOnly: true })\n\n }\n objects.runCommand = true\n }"
113
+ "semantic": "async ({context, e, toArray, fragments, toEValue, toFinalValue, recall, objects}) => {\n const evaluated = await(e(context.path))\n const path = toEValue(evaluated)\n \n // TODO put this in a common place for use by do+patrol \n\n // ordinal to pause time in seconds \n const pauseTimeInSeconds = {}\n if (context.pause) {\n const timeAtPoints = toArray(context.pause.timeAtPoint)\n for (const timeAtPoint of timeAtPoints) {\n const instantiation = await fragments(\"quantity in seconds\", { quantity: timeAtPoint.time })\n const result = await e(instantiation)\n const seconds = toFinalValue(toFinalValue(result).amount)\n\n const points = await recall({ context: timeAtPoint.point.point, frameOfReference: path })\n for (const point of toArray(points)) {\n pauseTimeInSeconds[point.ordinal] = seconds\n }\n }\n }\n\n // get to the start of the patrol \n objects.current.path.push(path.points[0])\n objects.current.path.push({ aimOnly: true, ...path.points[1] })\n objects.current.path.push({ repeatStart: true })\n for (const point of path.points) {\n objects.current.path.push(point)\n if (pauseTimeInSeconds[point.ordinal]) {\n objects.current.path.push({ marker: 'pause', pauseSeconds: pauseTimeInSeconds[point.ordinal] })\n }\n }\n if (context.repeats) {\n objects.current.timeRepeats = toFinalValue(context.repeats.repeats)\n }\n // if the patrol does not start and end at the same spot then \n // go back to the start along the same path\n\n\n // if the start is not the end of the patrol then go backwards along the patrol\n if (JSON.stringify(path.points[0].point) !== JSON.stringify(path.points[path.points.length-1].point)) {\n for (const point of [...path.points].reverse().slice(1)) {\n objects.current.path.push(point)\n if (pauseTimeInSeconds[point.ordinal]) {\n objects.current.path.push({ marker: 'pause', pauseSeconds: pauseTimeInSeconds[point.ordinal] })\n }\n }\n\n const secondPoint = path.points[1]\n objects.current.path.push({ ...secondPoint, aimOnly: true })\n }\n objects.runCommand = true\n }"
105
114
  },
106
115
  {
107
116
  "id": "lift",
@@ -543,11 +552,11 @@
543
552
  "semantics": [
544
553
  {
545
554
  "match": "({context}) => context.marker == 'doAction'",
546
- "apply": "async ({context, fragments, e, s, toEValue, toFinalValue, objects}) => {\n // await s({ ...context, marker: 'patrol', path: context.action})\n if (true) {\n const evaluated = await(e(context.action))\n const path = toEValue(evaluated)\n let pauseTimeInSeconds = 0\n if (context.pause) {\n debugger\n const instantiation = await fragments(\"quantity in seconds\", { quantity: context.pause.timeAtPoint.time })\n const result = await e(instantiation)\n const seconds = toFinalValue(toFinalValue(result).amount)\n pauseTimeInSeconds = seconds\n }\n for (const point of path.points) {\n objects.current.path.push(point)\n if (pauseTimeInSeconds) {\n objects.current.path.push({ marker: 'pause', pauseSeconds: pauseTimeInSeconds })\n }\n }\n objects.runCommand = true\n }\n }"
555
+ "apply": "async ({context, fragments, e, s, toEValue, toFinalValue, objects}) => {\n await s({ ...context, marker: 'patrol', path: context.action})\n }"
547
556
  },
548
557
  {
549
558
  "match": "({context, contextHierarchy}) => {\n if (!context.pullFromContext || !context.evaluate || contextHierarchy.under(['doAction', 'evaluate', 'patrol']) || context.instance) {\n return false\n }\n \n if (context.marker == 'path' || context.marker == 'this' || context.marker == 'that') {\n return true\n }\n }",
550
- "apply": "async ({context, frameOfReference, toArray, fragments, stm, objects, remember, recall, resolveEvaluate, _continue, contextHierarchy}) => {\n const pathComponents = toArray(await recall({ context: { marker: 'pathComponent' }, all: true }))\n const path = (await fragments('path')).contexts()[0]\n delete path.value\n path.instance = true\n path.points = pathComponents.reverse()\n frameOfReference(path, { mentioned: 'points', reversed: true })\n await remember(path)\n\n _continue() // let the call pick the object out from the stm\n }"
559
+ "apply": "async ({context, frameOfReference, toArray, fragments, objects, remember, recall, resolveEvaluate, _continue, contextHierarchy}) => {\n const pathComponents = toArray(await recall({ \n context: { marker: 'pathComponent' }, \n all: true,\n stopCondition: (context) => context.marker == 'startPath',\n }))\n const path = (await fragments('path')).contexts()[0]\n delete path.value\n path.instance = true\n path.points = pathComponents.reverse()\n frameOfReference(path, { mentioned: 'points', reversed: true })\n await remember(path)\n\n _continue() // let the call pick the object out from the stm\n }"
551
560
  },
552
561
  {
553
562
  "match": "({context, contextHierarchy}) => {\n if (!context.pullFromContext || !context.evaluate || !contextHierarchy.under('call') || context.notUnderCall) {\n return false\n }\n \n if (context.marker == 'point' || context.marker == 'ordinal') {\n return true\n }\n }",
@@ -561,6 +570,10 @@
561
570
  "match": "({context}) => context.evaluate && ['start', 'end'].includes(context.marker) && context.objects && context.objects[1].marker == 'path'",
562
571
  "apply": "async ({gp, s, context, objects, fragments, resolveEvaluate, api, recall}) => {\n const path = await recall({ context: context.objects[1] })\n if (!path?.points) {\n return\n }\n if (context.marker == 'start') {\n resolveEvaluate(context, path?.points[0])\n } else if (context.marker == 'end') {\n resolveEvaluate(context, path?.points[path?.points.length-1])\n }\n }"
563
572
  },
573
+ {
574
+ "match": "({context, contextHierarchy}) => \n context.evaluate && \n ['start', 'end', 'point'].includes(context.marker) && \n !context.propertyOf && \n contextHierarchy.under('go') &&\n !contextHierarchy.under('call')",
575
+ "apply": "async ({gp, s, toArray, context, objects, fragments, resolveEvaluate, api, recall}) => {\n const path = await recall({ context: { marker: 'path' } })\n if (!path?.points) {\n return\n }\n \n if (context.marker == 'start') {\n resolveEvaluate(context, path?.points[0])\n } else if (context.marker == 'end') {\n resolveEvaluate(context, path?.points[path?.points.length-1])\n } else {\n const points = await recall({ context, frameOfReference: path })\n resolveEvaluate(context, toArray(points)[0])\n }\n }"
576
+ },
564
577
  {
565
578
  "match": "({context}) => context.marker == 'speed' && context.evaluate",
566
579
  "apply": "async ({gp, s, context, objects, fragments, resolveEvaluate, api}) => {\n let value = objects.current.speed\n if (context.condition) {\n if (['highest', 'maximum'].includes(context.condition.marker)) {\n value = api.maximumSpeedDrone()\n } else if (['lowest', 'minimum'].includes(context.condition.marker)) {\n value = api.minimumSpeedDrone()\n }\n }\n const speed = await fragments(\"number meters per second\", { number: { marker: 'integer', value } })\n const preferred = await s({ marker: 'preferredUnits', quantity: speed }) \n resolveEvaluate(context, preferred.response || speed)\n }"
@@ -55711,6 +55724,7 @@
55711
55724
  "([lower] (@<= arm || @<=claw))",
55712
55725
  "([open] (claw))",
55713
55726
  "([close] (claw))",
55727
+ "([startPath|start] (path))",
55714
55728
  "([pathComponent])",
55715
55729
  "(<another> (point))",
55716
55730
  "([stop] ([drone|])?)",
@@ -55719,6 +55733,13 @@
55719
55733
  "((context.unit.dimension == 'time') [timeAtPoint|] (atPoint))"
55720
55734
  ],
55721
55735
  "bridges": [
55736
+ {
55737
+ "id": "startPath",
55738
+ "isA": [
55739
+ "verb"
55740
+ ],
55741
+ "bridge": "{ ...next(operator), path: after[0], operator: operator, interpolate: [{ property: 'operator' }, { property: 'path' }] }"
55742
+ },
55722
55743
  {
55723
55744
  "id": "timeAtPoint",
55724
55745
  "before": [
@@ -56202,6 +56223,7 @@
56202
56223
  {},
56203
56224
  {},
56204
56225
  {},
56226
+ {},
56205
56227
  {}
56206
56228
  ]
56207
56229
  }
@@ -59874,6 +59896,11 @@
59874
59896
  "thisAble",
59875
59897
  false
59876
59898
  ],
59899
+ [
59900
+ "startPath",
59901
+ "verb",
59902
+ false
59903
+ ],
59877
59904
  [
59878
59905
  "stm_before",
59879
59906
  "adjective",
@@ -64304,6 +64331,11 @@
64304
64331
  "thisAble",
64305
64332
  false
64306
64333
  ],
64334
+ [
64335
+ "startPath",
64336
+ "verb",
64337
+ false
64338
+ ],
64307
64339
  [
64308
64340
  "stm_before",
64309
64341
  "adjective",
@@ -68734,6 +68766,11 @@
68734
68766
  "thisAble",
68735
68767
  false
68736
68768
  ],
68769
+ [
68770
+ "startPath",
68771
+ "verb",
68772
+ false
68773
+ ],
68737
68774
  [
68738
68775
  "stm_before",
68739
68776
  "adjective",
@@ -73399,6 +73436,11 @@
73399
73436
  "thisAble",
73400
73437
  false
73401
73438
  ],
73439
+ [
73440
+ "startPath",
73441
+ "verb",
73442
+ false
73443
+ ],
73402
73444
  [
73403
73445
  "stm_before",
73404
73446
  "adjective",
@@ -78085,6 +78127,11 @@
78085
78127
  "thisAble",
78086
78128
  false
78087
78129
  ],
78130
+ [
78131
+ "startPath",
78132
+ "verb",
78133
+ false
78134
+ ],
78088
78135
  [
78089
78136
  "stm_before",
78090
78137
  "adjective",
@@ -82514,6 +82561,11 @@
82514
82561
  "thisAble",
82515
82562
  false
82516
82563
  ],
82564
+ [
82565
+ "startPath",
82566
+ "verb",
82567
+ false
82568
+ ],
82517
82569
  [
82518
82570
  "stm_before",
82519
82571
  "adjective",
@@ -86965,6 +87017,11 @@
86965
87017
  "thisAble",
86966
87018
  false
86967
87019
  ],
87020
+ [
87021
+ "startPath",
87022
+ "verb",
87023
+ false
87024
+ ],
86968
87025
  [
86969
87026
  "stm_before",
86970
87027
  "adjective",
@@ -91663,6 +91720,11 @@
91663
91720
  "thisAble",
91664
91721
  false
91665
91722
  ],
91723
+ [
91724
+ "startPath",
91725
+ "verb",
91726
+ false
91727
+ ],
91666
91728
  [
91667
91729
  "stm_before",
91668
91730
  "adjective",
@@ -95974,6 +96036,11 @@
95974
96036
  "thisAble",
95975
96037
  false
95976
96038
  ],
96039
+ [
96040
+ "startPath",
96041
+ "verb",
96042
+ false
96043
+ ],
95977
96044
  [
95978
96045
  "stm_before",
95979
96046
  "adjective",
package/common/drone.js CHANGED
@@ -1,4 +1,4 @@
1
- const { knowledgeModule, where } = require('./runtime').theprogrammablemind
1
+ const { knowledgeModule, where, debug } = require('./runtime').theprogrammablemind
2
2
  const { conjugateVerb } = require('./english_helpers')
3
3
  const { OverrideCheck, defaultContextCheckProperties, defaultContextCheck, getValue, setValue } = require('./helpers')
4
4
  const drone_tests = require('./drone.test.json')
@@ -16,6 +16,10 @@ const { rotateDelta, degreesToRadians, radiansToDegrees, cartesianToPolar, small
16
16
  /*
17
17
  NEED TO CHECK ON ACTUAL DRONE
18
18
 
19
+ DONE fix DO so it can do all the stuff partol can do <<<<<<<<<<<<<<<<<<<
20
+ start again. start a new path
21
+ the last 3 points are called path 1
22
+
19
23
  stopping 2 seconds at each point
20
24
  patrols x do that again
21
25
  DONE go to the end of the patrol
@@ -25,6 +29,9 @@ NEED TO CHECK ON ACTUAL DRONE
25
29
  go to the start
26
30
  DONE node drone -q 'north 1 meter\neast 1 meter\ncall that route 2\nwhat is the second point of route 2' -g -
27
31
 
32
+ go to the start along the path / following the path
33
+ pausing 1 second at the first point and 5 at the last
34
+
28
35
  DONE go to the second point of route 1
29
36
  DONE do route 1 pausing 10 seconds at each point
30
37
 
@@ -885,6 +892,7 @@ const template = {
885
892
  "([lower] (@<= arm || @<=claw))",
886
893
  "([open] (claw))",
887
894
  "([close] (claw))",
895
+ "([startPath|start] (path))",
888
896
  "([pathComponent])",
889
897
  "(<another> (point))",
890
898
  // "([turn] (direction))",
@@ -897,20 +905,16 @@ const template = {
897
905
  // "((context.unit.dimension == 'time') [timeForRest|] (forRest))",
898
906
  ],
899
907
  bridges: [
900
- /*
901
- {
902
- id: 'forRest',
903
- isA: ['preposition'],
904
- bridge: "{ ...next(operator), rest: after[0], operator: operator, interpolate: [{ property: 'operator' }, { property: 'rest' }] }"
905
- },
906
908
  {
907
- id: 'timeForRest',
908
- before: ['verb'],
909
- after: ['preposition'],
910
- convolution: true,
911
- bridge: "{ ...next(operator), time: before[0], point: after[0], operator: operator, interpolate: [{ property: 'time' }, { property: 'point' }] }"
909
+ id: 'startPath',
910
+ isA: ['verb'],
911
+ bridge: "{ ...next(operator), path: after[0], operator: operator, interpolate: [{ property: 'operator' }, { property: 'path' }] }",
912
+ semantic: async ({context, remember, recall}) => {
913
+ const point = await recall({ context: { marker: 'point' } })
914
+ remember(context)
915
+ remember(point) // put the last point before the startPath so when the new path is generated this is the start point
916
+ },
912
917
  },
913
- */
914
918
  {
915
919
  id: 'timeAtPoint',
916
920
  before: ['verb'],
@@ -993,7 +997,6 @@ const template = {
993
997
 
994
998
  const secondPoint = path.points[1]
995
999
  objects.current.path.push({ ...secondPoint, aimOnly: true })
996
-
997
1000
  }
998
1001
  objects.runCommand = true
999
1002
  }
@@ -1251,26 +1254,7 @@ const template = {
1251
1254
  {
1252
1255
  match: ({context}) => context.marker == 'doAction',
1253
1256
  apply: async ({context, fragments, e, s, toEValue, toFinalValue, objects}) => {
1254
- // await s({ ...context, marker: 'patrol', path: context.action})
1255
- if (true) {
1256
- const evaluated = await(e(context.action))
1257
- const path = toEValue(evaluated)
1258
- let pauseTimeInSeconds = 0
1259
- if (context.pause) {
1260
- debugger
1261
- const instantiation = await fragments("quantity in seconds", { quantity: context.pause.timeAtPoint.time })
1262
- const result = await e(instantiation)
1263
- const seconds = toFinalValue(toFinalValue(result).amount)
1264
- pauseTimeInSeconds = seconds
1265
- }
1266
- for (const point of path.points) {
1267
- objects.current.path.push(point)
1268
- if (pauseTimeInSeconds) {
1269
- objects.current.path.push({ marker: 'pause', pauseSeconds: pauseTimeInSeconds })
1270
- }
1271
- }
1272
- objects.runCommand = true
1273
- }
1257
+ await s({ ...context, marker: 'patrol', path: context.action})
1274
1258
  }
1275
1259
  },
1276
1260
  {
@@ -1283,8 +1267,12 @@ const template = {
1283
1267
  return true
1284
1268
  }
1285
1269
  },
1286
- apply: async ({context, frameOfReference, toArray, fragments, stm, objects, remember, recall, resolveEvaluate, _continue, contextHierarchy}) => {
1287
- const pathComponents = toArray(await recall({ context: { marker: 'pathComponent' }, all: true }))
1270
+ apply: async ({context, frameOfReference, toArray, fragments, objects, remember, recall, resolveEvaluate, _continue, contextHierarchy}) => {
1271
+ const pathComponents = toArray(await recall({
1272
+ context: { marker: 'pathComponent' },
1273
+ all: true,
1274
+ stopCondition: (context) => context.marker == 'startPath',
1275
+ }))
1288
1276
  const path = (await fragments('path')).contexts()[0]
1289
1277
  delete path.value
1290
1278
  path.instance = true
@@ -1341,6 +1329,29 @@ const template = {
1341
1329
  }
1342
1330
  }
1343
1331
  },
1332
+ {
1333
+ match: ({context, contextHierarchy}) =>
1334
+ context.evaluate &&
1335
+ ['start', 'end', 'point'].includes(context.marker) &&
1336
+ !context.propertyOf &&
1337
+ contextHierarchy.under('go') &&
1338
+ !contextHierarchy.under('call'),
1339
+ apply: async ({gp, s, toArray, context, objects, fragments, resolveEvaluate, api, recall}) => {
1340
+ const path = await recall({ context: { marker: 'path' } })
1341
+ if (!path?.points) {
1342
+ return
1343
+ }
1344
+
1345
+ if (context.marker == 'start') {
1346
+ resolveEvaluate(context, path?.points[0])
1347
+ } else if (context.marker == 'end') {
1348
+ resolveEvaluate(context, path?.points[path?.points.length-1])
1349
+ } else {
1350
+ const points = await recall({ context, frameOfReference: path })
1351
+ resolveEvaluate(context, toArray(points)[0])
1352
+ }
1353
+ }
1354
+ },
1344
1355
  {
1345
1356
  match: ({context}) => context.marker == 'speed' && context.evaluate,
1346
1357
  apply: async ({gp, s, context, objects, fragments, resolveEvaluate, api}) => {