Commit e8d0418d authored by Jake Read's avatar Jake Read

continues for robot

parent b73465fd
......@@ -316,8 +316,8 @@ function redrawLinks() {
svg.removeChild(svg.firstChild)
}
// draw origin
var og1 = newLine(20, 30, 40, 30, 3, false)
var og2 = newLine(30, 20, 30, 40, 3, false)
var og1 = newLine(-20, 0, 20, 0, 3, false)
var og2 = newLine(0, -20, 0, 20, 3, false)
// find that link
var lnkPt
var nLnk = 0
......
......@@ -10,7 +10,8 @@
<script type="text/javascript" src="divtools.js"></script>
<script type="text/javascript" src="client.js"></script>
<div id = "nav">
<p>'l' for load program, 's' for save program, right-click or 'm' for add module menu</p>
<a href = "https://gitlab.cba.mit.edu/jakeread/rndmc">RuNDMC</a> |
'l' for load program, 's' for save program, right-click or 'm' for add module menu
</div>
</body>
......
......@@ -97,6 +97,20 @@ textarea {
clear: both;
}
#nav {
padding: 5px;
padding-right: 15px;
background-color: #303030;
color: #eee;
font-size: 15px;
position:absolute;
z-index: 1000;
}
#nav a{
color: #eee;
}
ul {
list-style-type: none;
font-size: 15px;
......@@ -142,8 +156,4 @@ li:active{
width: 80px;
padding: 3px;
background-color: #303030;
}
#nav {
font-size: 15px;
}
\ No newline at end of file
......@@ -8,9 +8,20 @@ let Button = JSUnit.Button
const Hardware = require('../../src/atkunit.js')
const PCKT = require('../../src/packets.js')
// interface elements
const JSUI = require('../../src/jsui.js')
let UI = JSUI.UI
// a constructor, a fn, a javascript mess
function ATKMathRobot() {
// TODO:
// add small filter to PID / D-term
// add deadband option?
// do chart-tune
// tune ... and take video
// do three.js
// we make the module, starting from this base
// '0,1' is the route to our piece of hardware
// 'onPacket' is the function that will be called
......@@ -22,6 +33,7 @@ function ATKMathRobot() {
// inputs and outputs as usual
atkmr.inputs = {
tick: Input('event', onPositionTickTock),
pc_t: Input('number', onPositionTargetInput)
}
atkmr.outputs = {
......@@ -29,19 +41,43 @@ function ATKMathRobot() {
}
// and state as well
var state = atkmr.state
var state = atkmr.state
state.message = 'no packet yet'
state.pc_t = 2048
state.onUiChange('pc_t', onPositionTargetUserChange)
state.walk = 1024
state.tickButton = Button('Walk Value', onPositionTickTock)
state.pKp = 4.5
state.onUiChange('pKp', onKValsUpdate)
state.pKi = 0.0
state.onUiChange('pKi', onKValsUpdate)
state.pKd = 0.0
state.onUiChange('pKd', onKValsUpdate)
state.cKp = 4.0
state.onUiChange('cKp', onKValsUpdate)
state.cKi = 0.0
state.onUiChange('cKi', onKValsUpdate)
atkmr.ui = UI()
var ui = atkmr.ui
ui.addElement('walkValButton', './ui/uiButton.js', onPositionTickTock)
ui.walkValButton.onload = function() {
ui.walkValButton.setText('walk value')
}
// to send things down the well, we can use
// atkmr.route.send(packet)
// where packet is a byte array
function onPositionTargetInput(evt){
function onKValsUpdate() {
var pckt = [144]
pckt = pckt.concat(PCKT.packFloatTo32(state.pKp, true), PCKT.packFloatTo32(state.pKi), PCKT.packFloatTo32(state.pKd), PCKT.packFloatTo32(state.cKp), PCKT.packFloatTo32(state.cKi))
console.log('pckt like', pckt)
atkmr.route.send(pckt)
}
function onPositionTargetInput(evt) {
console.log("INPUTS NOT YET BOUND", evt)
}
......@@ -60,11 +96,11 @@ function ATKMathRobot() {
atkmr.route.send(pc_tpack)
}
function onPositionTickTock(){
function onPositionTickTock() {
var pc_t = state.pc_t
pc_t += state.walk
pc_t %= 16384
state.pc_t = pc_t
state.pc_t = pc_t
onPositionTargetUserChange()
}
......@@ -72,10 +108,12 @@ function ATKMathRobot() {
// subscribe, where 141 (here) is the 'key'
// we're looking for on the network, and the
// msg is byte array we'll get back
atkmr.route.subscribe(143, function(msg){
atkmr.route.subscribe(143, function(msg) {
state.message = 'packet ok'
})
atkmr.go = onKValsUpdate
return atkmr
}
......
......@@ -242,6 +242,10 @@ function ATKSerialLink() {
// console.log('shifted', pckt)
}
// make program-available
atkSerialLink.startUp = findSerialPort
return atkSerialLink
}
......
......@@ -31,6 +31,24 @@ const Programs = require('./programs.js')
// the program object: real simple, just has a description, and a 'modules'
var program = Programs.new('new program')
var link = Programs.loadModuleFromSource(program, './modules/hardware/atkseriallink.js')
link.startUp()
link.description.position = {
left: 600,
top: 50
}
var mrbot = Programs.loadModuleFromSource(program, './modules/hardware/atkmrobot.js')
mrbot.description.position = {
left: 20,
top: 50
}
mrbot.go()
/*
var stest = Programs.loadModuleFromSource(program, './modules/ui/stest.js')
......
......@@ -88,7 +88,7 @@ function State() {
}
state.pushToUI = function(key) {
if (this.socket) {
if (this.socket.send != null) {
var data = {
id: this.parentId,
key: key,
......
......@@ -15,10 +15,34 @@ function unPack32(arr){
} else {
console.log("ERR: arr > 4 at unPack32", arr)
}
}
function packFloatTo32(val, debug){
// https://www.h-schmidt.net/FloatConverter/IEEE754.html
var f = new Float32Array(1)
f[0] = val
var view = new Uint8Array(f.buffer)
if(debug) printViewBytes(view)
var pack = new Array()
pack[0] = view[3]
pack[1] = view[2]
pack[2] = view[1]
pack[3] = view[0]
return pack
}
function printViewBytes(view){
for(i = view.length - 1; i >= 0; i --){
var bits = view[i].toString(2)
if(bits.length < 8){
bits = new Array(8 - bits.length).fill('0').join('') + bits
}
console.log(bits)
}
}
module.exports = {
pack32: pack32,
unPack32: unPack32
unPack32: unPack32,
packFloatTo32: packFloatTo32
}
\ No newline at end of file
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