ekms 9.6.0-beta.10 → 9.6.0-beta.12

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.
@@ -1,4 +1,4 @@
1
- const { knowledgeModule, where, process:clientProcess } = require('./runtime').theprogrammablemind
1
+ const { debug, knowledgeModule, where, process:clientProcess } = require('./runtime').theprogrammablemind
2
2
  const { defaultContextCheck } = require('./helpers')
3
3
  const gdefaults = require('./gdefaults.js')
4
4
  const createCurrencyKM = require('./currency.js')
@@ -173,22 +173,20 @@ function initializeApi(config, api) {
173
173
  }
174
174
 
175
175
 
176
- async function initializer({isModule, km}) {
177
- if (!isModule) {
178
- const timeKM = await createTimeKM()
179
- const currencyKM = await createCurrencyKM()
180
- const config = km('characters')
181
- const api = new Sally(timeKM)
182
- const api2 = new Bob(currencyKM)
183
- await config.setApi(() => api2)
184
- await config.setApi(() => api)
185
- }
176
+ async function demoInitializer(config) {
177
+ const timeKM = await createTimeKM()
178
+ const currencyKM = await createCurrencyKM()
179
+ const api = new Sally(timeKM)
180
+ const api2 = new Bob(currencyKM)
181
+ await config.setApi(() => api2)
182
+ await config.setApi(() => api)
186
183
  }
184
+
187
185
  // mode this to non-module init only
188
186
  knowledgeModule({
189
187
  config,
190
188
  includes: [gdefaults],
191
- initializer,
189
+ demoInitializer,
192
190
  multiApiInitializer: initializeApi,
193
191
 
194
192
  module,
@@ -11,6 +11,7 @@
11
11
  {
12
12
  "operators": [
13
13
  "([back])",
14
+ "([forth])",
14
15
  "([turn] (direction))",
15
16
  "([pause] ([number]))",
16
17
  "([stop] ([drone|])?)",
@@ -23,7 +24,13 @@
23
24
  "isA": [
24
25
  "noun"
25
26
  ],
26
- "semantic": "async ({objects, mentions, api, e, context}) => {\n objects.runCommand = true\n const ordinal = api.currentOrdinal() - 1\n const lastPoint = mentions({ context: { marker: 'point' }, condition: (context) => context.ordinal == ordinal })\n objects.current.destination = lastPoint\n }"
27
+ "semantic": "async ({objects, mentions, api, e, context}) => {\n objects.runCommand = true\n const ordinal = api.currentOrdinal() - 1\n const lastPoint = mentions({ context: { marker: 'point' }, condition: (context) => context.ordinal == ordinal })\n objects.current.path.push(lastPoint)\n }"
28
+ },
29
+ {
30
+ "id": "forth",
31
+ "isA": [
32
+ "noun"
33
+ ]
27
34
  },
28
35
  {
29
36
  "id": "toPoint",
@@ -31,7 +38,7 @@
31
38
  "preposition"
32
39
  ],
33
40
  "bridge": "{ ...next(operator), operator: operator, point: after[0], interpolate: [{ property: 'operator' }, { property: 'point' }] }",
34
- "semantic": "async ({objects, api, e, context}) => {\n objects.runCommand = true\n const point = await e(context.point)\n objects.current.destination = point.evalue\n }"
41
+ "semantic": "async ({objects, api, e, context}) => {\n objects.runCommand = true\n const point = await e(context.point)\n objects.current.path.push(point.evalue)\n }"
35
42
  },
36
43
  {
37
44
  "id": "go"
@@ -70,7 +77,12 @@
70
77
  "apply": "() => ''"
71
78
  }
72
79
  ],
73
- "semantics": []
80
+ "semantics": [
81
+ {
82
+ "match": "({context, toArray}) => {\n if (context.marker !== 'list') {\n return false\n }\n\n const array = toArray(context)\n if (array[0].marker == 'back' && array[1].marker == 'forth') {\n return true\n }\n }",
83
+ "apply": "({context, objects, api, mentions}) => {\n objects.runCommand = true\n objects.current.backAndForth = true\n const ordinal = api.currentOrdinal()\n const currentPoint = mentions({ context: { marker: 'point' }, condition: (context) => context.ordinal == ordinal })\n const lastPoint = mentions({ context: { marker: 'point' }, condition: (context) => context.ordinal == ordinal-1 })\n objects.current.path.push(lastPoint)\n objects.current.path.push(currentPoint)\n }"
84
+ }
85
+ ]
74
86
  }
75
87
  ],
76
88
  "resultss": [
@@ -15677,6 +15689,7 @@
15677
15689
  "extraConfig": true,
15678
15690
  "operators": [
15679
15691
  "([back])",
15692
+ "([forth])",
15680
15693
  "([turn] (direction))",
15681
15694
  "([pause] ([number]))",
15682
15695
  "([stop] ([drone|])?)",
@@ -15690,6 +15703,12 @@
15690
15703
  "noun"
15691
15704
  ]
15692
15705
  },
15706
+ {
15707
+ "id": "forth",
15708
+ "isA": [
15709
+ "noun"
15710
+ ]
15711
+ },
15693
15712
  {
15694
15713
  "id": "toPoint",
15695
15714
  "isA": [
@@ -15728,7 +15747,9 @@
15728
15747
  "generators": [
15729
15748
  {}
15730
15749
  ],
15731
- "semantics": []
15750
+ "semantics": [
15751
+ {}
15752
+ ]
15732
15753
  }
15733
15754
  ],
15734
15755
  "fragments": [
@@ -16304,6 +16325,11 @@
16304
16325
  "queryable",
16305
16326
  false
16306
16327
  ],
16328
+ [
16329
+ "forth",
16330
+ "noun",
16331
+ false
16332
+ ],
16307
16333
  [
16308
16334
  "forward",
16309
16335
  "direction",
@@ -19090,6 +19116,11 @@
19090
19116
  "queryable",
19091
19117
  false
19092
19118
  ],
19119
+ [
19120
+ "forth",
19121
+ "noun",
19122
+ false
19123
+ ],
19093
19124
  [
19094
19125
  "forward",
19095
19126
  "direction",
@@ -22147,6 +22178,11 @@
22147
22178
  "queryable",
22148
22179
  false
22149
22180
  ],
22181
+ [
22182
+ "forth",
22183
+ "noun",
22184
+ false
22185
+ ],
22150
22186
  [
22151
22187
  "forward",
22152
22188
  "direction",
@@ -25124,6 +25160,11 @@
25124
25160
  "queryable",
25125
25161
  false
25126
25162
  ],
25163
+ [
25164
+ "forth",
25165
+ "noun",
25166
+ false
25167
+ ],
25127
25168
  [
25128
25169
  "forward",
25129
25170
  "direction",
package/common/drone.js CHANGED
@@ -110,6 +110,10 @@ https://www.amazon.ca/Freenove-Raspberry-Tracking-Avoidance-Ultrasonic/dp/B0BNDQ
110
110
  go forward for 1 second\nbackward 2 meters (implicit stop)
111
111
 
112
112
  go back
113
+
114
+ go back and forth 3 times
115
+ go back and forth 2 meters
116
+ go back and forth 1 second
113
117
  */
114
118
 
115
119
  function expectDirection(args) {
@@ -190,6 +194,7 @@ class API {
190
194
 
191
195
  objects.current = {
192
196
  angleInRadians: 0,
197
+ path: [],
193
198
  speed: this.minimumSpeedDrone(),
194
199
  ordinal: 0, // ordinal of the current point or the current point that the recent movement started at
195
200
  }
@@ -269,31 +274,41 @@ class API {
269
274
  }
270
275
 
271
276
  const stopAtDistance = async (direction, distanceMeters) => {
272
- const speed_meters_per_second = this._objects.current.speed
277
+ const speed_meters_per_second = objects.current.speed
273
278
  const duration_seconds = distanceMeters / speed_meters_per_second
274
279
  await this.pause(duration_seconds, { batched: true })
275
- await this.stop()
280
+ await this.stop({ batched: true })
276
281
  this.markCurrentPoint()
277
282
  }
278
283
 
279
- if (this._objects.current.destination) {
280
- const currentPoint = this.args.mentions({ context: { marker: 'point' } }).point
281
- const destinationPoint = this._objects.current.destination.point
282
- if (currentPoint.x == destinationPoint.x && currentPoint.y == destinationPoint.y) {
283
- // already there
284
- } else {
285
- const polar = cartesianToPolar(currentPoint, destinationPoint)
286
- const destinationAngleInRadians = polar.angle
287
- const angleDelta = (destinationAngleInRadians - this._objects.current.angleInRadians)
288
- await this.rotate(angleDelta)
289
- await this.forward(this._objects.current.speed)
290
- await stopAtDistance("forward", polar.radius)
291
- this._objects.current.destination = undefined
284
+ if (objects.current.path.length > 0) {
285
+ if (objects.current.timeRepeats) {
286
+ this.startRepeats(objects.current.timeRepeats)
287
+ }
288
+ for (const destination of objects.current.path) {
289
+ const destinationPoint = destination.point
290
+ const currentPoint = this.args.mentions({ context: { marker: 'point' } }).point
291
+ if (currentPoint.x == destinationPoint.x && currentPoint.y == destinationPoint.y) {
292
+ // already there
293
+ } else {
294
+ const polar = cartesianToPolar(currentPoint, destinationPoint)
295
+ const destinationAngleInRadians = polar.angle
296
+ const angleDelta = (destinationAngleInRadians - objects.current.angleInRadians)
297
+ await this.rotate(angleDelta)
298
+ await this.forward(objects.current.speed)
299
+ await stopAtDistance("forward", polar.radius)
300
+ }
292
301
  }
302
+ if (objects.current.timeRepeats) {
303
+ this.endRepeats()
304
+ }
305
+ await this.sendBatch()
306
+ objects.current.path = []
307
+ objects.current.timeRepeats = 0
293
308
  return
294
309
  }
295
310
 
296
- const command = { speed: this._objects.current.speed, ...this._objects.current }
311
+ const command = { speed: objects.current.speed, ...objects.current }
297
312
  switch (command.direction) {
298
313
  case 'forward':
299
314
  await this.forward(command.speed, { batched: command.distance })
@@ -315,9 +330,22 @@ class API {
315
330
  if (command.distance) {
316
331
  const distanceMeters = command.distance
317
332
  await stopAtDistance(command.direction, distanceMeters)
333
+ await this.sendBatch()
318
334
  }
319
335
  }
320
336
 
337
+ async startRepeats(n) {
338
+ await this.startRepeatsDrone()
339
+ }
340
+
341
+ async endRepeats(n) {
342
+ await this.endRepeatsDrone()
343
+ }
344
+
345
+ async sendBatch() {
346
+ await this.sendBatchDrone()
347
+ }
348
+
321
349
  async forward(speed, options) {
322
350
  await this.forwardDrone(speed, options)
323
351
  const time = this.now()
@@ -367,6 +395,18 @@ class API {
367
395
 
368
396
  // subclass and override the remaining to call the drone
369
397
 
398
+ async startRepeats(n) {
399
+ this._objects.history.push({ marker: 'startRepeats', n })
400
+ }
401
+
402
+ async endRepeats(n) {
403
+ this._objects.history.push({ marker: 'endRepeats', })
404
+ }
405
+
406
+ async sendBatchDrone(durationInSeconds, options) {
407
+ this._objects.history.push({ marker: 'sendBatch', pause: durationInSeconds, ...options })
408
+ }
409
+
370
410
  async pauseDrone(durationInSeconds, options) {
371
411
  this._objects.history.push({ marker: 'history', pause: durationInSeconds, ...options })
372
412
  this.testDate = new Date(this.testDate.getTime() + (durationInSeconds-1)*1000)
@@ -537,6 +577,7 @@ const template = {
537
577
  {
538
578
  operators: [
539
579
  "([back])",
580
+ "([forth])",
540
581
  "([turn] (direction))",
541
582
  "([pause] ([number]))",
542
583
  "([stop] ([drone|])?)",
@@ -551,9 +592,13 @@ const template = {
551
592
  objects.runCommand = true
552
593
  const ordinal = api.currentOrdinal() - 1
553
594
  const lastPoint = mentions({ context: { marker: 'point' }, condition: (context) => context.ordinal == ordinal })
554
- objects.current.destination = lastPoint
595
+ objects.current.path.push(lastPoint)
555
596
  }
556
597
  },
598
+ {
599
+ id: "forth",
600
+ isA: ['noun'],
601
+ },
557
602
  {
558
603
  id: "toPoint",
559
604
  isA: ['preposition'],
@@ -561,7 +606,7 @@ const template = {
561
606
  semantic: async ({objects, api, e, context}) => {
562
607
  objects.runCommand = true
563
608
  const point = await e(context.point)
564
- objects.current.destination = point.evalue
609
+ objects.current.path.push(point.evalue)
565
610
  }
566
611
  },
567
612
  { id: "go" },
@@ -605,7 +650,34 @@ const template = {
605
650
  },
606
651
  ],
607
652
  semantics: [
608
-
653
+ {
654
+ match: ({context}) => context.marker == 'timeRepeats',
655
+ apply: ({context, objects, toFinalValue}) => {
656
+ objects.runCommand = true
657
+ objects.current.timeRepeats = toFinalValue(context.repeats)
658
+ }
659
+ },
660
+ {
661
+ match: ({context, toArray}) => {
662
+ if (context.marker !== 'list') {
663
+ return false
664
+ }
665
+
666
+ const array = toArray(context)
667
+ if (array[0].marker == 'back' && array[1].marker == 'forth') {
668
+ return true
669
+ }
670
+ },
671
+ apply: ({context, objects, api, mentions}) => {
672
+ objects.runCommand = true
673
+ objects.current.backAndForth = true
674
+ const ordinal = api.currentOrdinal()
675
+ const currentPoint = mentions({ context: { marker: 'point' }, condition: (context) => context.ordinal == ordinal })
676
+ const lastPoint = mentions({ context: { marker: 'point' }, condition: (context) => context.ordinal == ordinal-1 })
677
+ objects.current.path.push(lastPoint)
678
+ objects.current.path.push(currentPoint)
679
+ }
680
+ }
609
681
  ],
610
682
  },
611
683
  ],