Commit 37bea394 authored by Jake Read's avatar Jake Read

robot program ready for forward transform and lsqr

parent 85ffd44b
......@@ -316,6 +316,7 @@ View.assignProgram(program)
- module deletion seems unclean
- input / output objects should be able to unhook themselves:
- keep references of what-is-attached ?
- would like to be able to default prevent state variables from being changed by users, i.e. in 'collector' the 'count' variable
## WRT Representations
......
......@@ -510,6 +510,8 @@ document.onkeydown = function(evt) {
case 'd':
console.log(program)
break
case 'k':
socketSend('save program', 'temp')
default:
break
}
......
......@@ -49,12 +49,12 @@ function UIArray() {
// here's our input callback, specified in the input constructor
function onThruInput(input){
if(typeof input == 'number'){
state.number = input
if(Array.isArray(input)){
state.array = input
onArrayDesire()
} else {
state.number = parseFloat(input)
console.log("ERR input to array module is non-array")
}
onArrayDesire()
}
function onArrayDesire(){
......
// boilerplate rndmc header
const JSUnit = require('../../src/jsunit.js')
let Input = JSUnit.Input
let Output = JSUnit.Output
let State = JSUnit.State
// interface elements
const JSUI = require('../../src/jsui.js')
let UI = JSUI.UI
/*
collector
takes samples from what-ever output, stores in an array until a 'dump' input,
outputs that array, clears internals
*/
// a constructor, a fn, a javascript mess
function Collector() {
// this is the tiny program-as-and-object that we'll load into rundmc
// description / name is required to load successfully
var collector = {
description: {
name: 'collector',
alt: 'collect and dump'
}
}
// the State() object is what the system scrapes for ui variables / updates from the UI
// this includes things like Button('title', callback), which are unique state variables
// they can also be found in jsunit.js
collector.state = State()
// alias !
var state = collector.state
state.count = 0
var collection = new Array()
collector.ui = UI()
var ui = collector.ui
ui.addElement('onDumpButton', './ui/uiButton.js', onDumpDesire)
ui.onDumpButton.onload = function() {
ui.onDumpButton.setText('array out ->')
}
// inputs are required, and must be Input('type', callback)
collector.inputs = {
collect: Input('any', onNewItem), // makes anything into num event
dump: Input('evt', onDumpDesire)
}
// outputs: Output('type')
collector.outputs = {
pass: Output('any')
}
// here's our input callback, specified in the input constructor
function onNewItem(input){
collection.push(input)
state.count = collection.length
}
function onDumpDesire(){
collector.outputs.pass.emit(collection)
collection = new Array()
state.count = collection.length
}
// gotta give the program this thing we made
return collector
}
// this for node.js's require() function
module.exports = Collector
\ No newline at end of file
......@@ -29,7 +29,7 @@ function Gate() {
var ui = gate.ui
ui.addElement('openButton', './ui/uiButton.js', onButtonPress)
ui.openButton.onload = function() {
ui.openButton.setText('toggle gate')
ui.openButton.setText('click to open gate')
}
// yikes
......@@ -44,14 +44,14 @@ function Gate() {
}
function onButtonPress(evt) {
console.log("GATE BUTTON")
if (gate.isOpen) {
gate.isOpen = false
state.message = 'closed'
ui.openButton.setText('click to open gate')
} else {
gate.isOpen = true
state.message = 'open'
//gate.outputs.out.emit('go')
ui.openButton.setText('click to close gate')
}
}
......
// boilerplate header
const JSUnit = require('../../src/jsunit.js')
let Input = JSUnit.Input
let Output = JSUnit.Output
let State = JSUnit.State
// interface elements
const JSUI = require('../../src/jsui.js')
let UI = JSUI.UI
// a constructor, a fn, a javascript mess
function GateCounter() {
var gateCounter = {
// descriptions are used in UI
description: {
name: 'gateCounter',
alt: 'in ... out'
}
}
gateCounter.state = State()
// alias !
var state = gateCounter.state
state.addThis = 10
state.count = 0
gateCounter.ui = UI()
var ui = gateCounter.ui
ui.addElement('openButton', './ui/uiButton.js', onButtonPress)
ui.openButton.onload = function() {
ui.openButton.setText('click to add ' + state.addThis.toString() + ' to count')
}
state.onUiChange('addThis', function(){
ui.openButton.setText('click to add ' + state.addThis.toString() + ' to count')
})
// yikes
gateCounter.isOpen = false
gateCounter.inputs = {
thru: Input('any', gateCounterKeeper), // makes anything into '1' event
setCount: Input('number', onSetCount),
addEvent: Input('any', onAddEvent)
}
gateCounter.outputs = {
out: Output('any')
}
function onButtonPress(evt) {
console.log("gateCounter BUTTON")
state.count += state.addThis
}
function onSetCount(num){
state.addThis = num
state.count = num
}
function onAddEvent(evt){
state.count = state.addThis
}
function gateCounterKeeper(input) {
if (state.count > 0) {
var outVar = JSON.parse(JSON.stringify(input))
gateCounter.outputs.out.emit(outVar)
state.count --
}
}
return gateCounter
}
// exports
module.exports = GateCounter
\ No newline at end of file
// boilerplate rndmc header
const JSUnit = require('../../src/jsunit.js')
let Input = JSUnit.Input
let Output = JSUnit.Output
let State = JSUnit.State
// interface elements
const JSUI = require('../../src/jsui.js')
let UI = JSUI.UI
// a constructor, a fn, a *hot* javascript mess
function ParallelContencator() {
// this is the tiny program-as-and-object that we'll load into rundmc
// description / name is required to load successfully
var parallelContencator = {
description: {
name: 'parallelContencator',
alt: 'inputs -> arrays'
}
}
// the State() object is what the system scrapes for ui variables / updates from the UI
// this includes things like Button('title', callback), which are unique state variables
// they can also be found in jsunit.js
parallelContencator.state = State()
// alias !
var state = parallelContencator.state
state.gateKeep = true
parallelContencator.ui = UI()
var ui = parallelContencator.ui
ui.addElement('onOutputButton', './ui/uiButton.js', doThroughput)
ui.onOutputButton.onload = function() {
ui.onOutputButton.setText('array out ->')
}
// inputs are required, and must be Input('type', callback)
parallelContencator.inputs = {
in0: Input('any', onIn0),
in1: Input('any', onIn1),
push: Input('evt', doThroughput) // makes anything into num event
}
// outputs: Output('type')
parallelContencator.outputs = {
out: Output('array')
}
var contencated = [0, 0]
var recent = [false, false]
function onIn0(inp) {
contencated[0] = inp
recent[0] = true
doGateCheck()
}
function onIn1(inp) {
contencated[1] = inp
recent[1] = true
doGateCheck()
}
function doGateCheck() {
if (state.gateKeep) {
var count = 0
recent.forEach(function(element) {
if (element) {
count++
}
})
if (count == recent.length) {
doThroughput()
}
} else {
doThroughput()
}
}
function doThroughput() {
// here's how we fire an output.
parallelContencator.outputs.out.emit(contencated)
recent.fill(false)
}
// gotta give the program this thing we made
return parallelContencator
}
// this for node.js's require() function
module.exports = ParallelContencator
\ No newline at end of file
This diff is collapsed.
......@@ -16,11 +16,6 @@ var program = Programs.new('new program')
- robot does forward transform with live [t1, t2]
- robot displays forward transform with [t1, t2]
- modules needed
- object collector (i.e. collects inputs into a list, has 'output' and 'reset' input triggers / buttons as well)
- two-up contencator (i.e. takes two inputs, puts them into arrays)
- gate opens, lets a count thru, shuts
*/
var link = Programs.loadModuleFromSource(program, './modules/hardware/atkseriallink.js')
......@@ -55,6 +50,12 @@ mrbotone.outputs.pos.attach(log.inputs.thru)
var canvas = Programs.loadModuleFromSource(program, './modules/ui/threeCanvas.js')
Programs.setUI(canvas, 1500, 650)
var collector = Programs.loadModuleFromSource(program, './modules/util/collector.js')
Programs.setUI(collector, 1050, 800)
var gateCounter = Programs.loadModuleFromSource(program, './modules/util/gateCounter.js')
Programs.setUI(gateCounter, 600, 850)
/*
var stest = Programs.loadModuleFromSource(program, './modules/ui/stest.js')
......
......@@ -29,7 +29,9 @@ const Reps = require('./reps.js')
const Programs = require('./programs.js')
// the program object: real simple, just has a description, and a 'modules'
var program = Programs.new('new program')
// var program = Programs.new('new program')
var program = Programs.open('./programs/temp.json')
/*
var stest = Programs.loadModuleFromSource(program, './modules/ui/stest.js')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment