Node.js script not setting BeagleBone Black mux - node.js
On my BeagleBone Black, when I run this script:
#!/usr/bin/node
var b = require('bonescript');
b.getPlatform(printData);
function printData(x) {
console.log('name = ' + x.name);
console.log('version = ' + x.version);
console.log('serialNumber = ' + x.serialNumber);
console.log('bonescript = ' + x.bonescript);
console.log();
}
b.pinMode("P9_11", b.OUTPUT, 7, 'pullup', 'slow');
b.pinMode("P9_13", b.OUTPUT, 7, 'pullup', 'slow');
b.pinMode("P9_15", b.OUTPUT, 7, 'pullup', 'slow');
b.pinMode("P9_17", b.OUTPUT, 7, 'pullup', 'slow');
b.getPinMode("P9_11", printPinMux);
b.getPinMode("P9_13", printPinMux);
b.getPinMode("P9_15", printPinMux);
b.getPinMode("P9_17", printPinMux);
function printPinMux(x) {
console.log('mux = ' + x.mux);
console.log('pullup = ' + x.pullup);
console.log('slew = ' + x.slew);
if(x.options) {
console.log('options = ' + x.options.join(','));
}
console.log('pin = ' + x.pin);
console.log('name = ' + x.name);
console.log('err = ' + x.err);
console.log();
}
I get this output:
name = BeagleBone Black
version = 0A5A
serialNumber = 1813BBBK7710
bonescript = 0.2
mux = 7
pullup = pullup
slew = fast
options = gpmc_wait0,mii2_crs,NA,rmii2_crs_dv,mmc1_sdcd,NA,NA,gpio0_30
pin = P9_11
name = UART4_RXD
err = undefined
mux = 7
pullup = pullup
slew = fast
options = gpmc_wpn,mii2_rxerr,NA,rmii2_rxerr,mmc2_sdcd,NA,NA,gpio0_31
pin = P9_13
name = UART4_TXD
err = undefined
mux = 2
pullup = pulldown
slew = slow
options = spi0_cs0,mmc2_sdwp,i2c1_scl,NA,NA,NA,NA,gpio0_5
pin = P9_17
name = I2C1_SCL
err = undefined
mux = 0
pullup = pulldown
slew = fast
options = mii1_rxd3,NA,rgmii1_rd3,mmc0_dat5,mmc1_dat2,NA,mcasp0_axr0,gpio2_18
pin = P9_15
name = GPIO1_16
err = undefined
It looks like b.pinMode() isn't setting the pins' modes. Why?
Related
Nodejs indexOf with array of arrays
I'd be grateful if someone can explain what I'm doing wrong here. I compare two arrays of geographic coordinates, successfully find the common elements and then try to get the indexes for the first hit. Only arrB works as expected. Although the key is quite clearly at arrA[1], no match is found. I've included loads of logging because I don't quite believe what I'm seeing. function arrayIntersect(a, b) { /* credit https://stackoverflow.com/questions/1885557/simplest-code-for-array-intersection-in-javascript */ var aa = {}; a.forEach(function(v) { aa[v]=1; }); return b.filter(function(v) { return v in aa; }); } const arrA = [[53.88,-2.96],[53.7,-2.45],[53.79,-2.52],[53.66,-2.61],[53.98,-2.34],[53.92,-2.36],[53.89,-2.95],[53.9,-2.94],[53.88,-2.4],[53.89,-2.81],[53.93,-2.77],[53.87,-2.13],[53.9,-2.54],[53.6,-2.91],[54.01,-2.83],[53.83,-2.44],[53.6,-2.88],[54.02,-2.76],[53.99,-2.8],[54.15,-2.79],[53.85,-2.13],[53.62,-2.96],[54,-2.84],[53.66,-2.75],[53.91,-2.27],[53.86,-2.62],[53.51,-2.13],[53.82,-2.3]] const arrB = [[53.82,-2.9],[53.95,-2.73],[53.62,-2.73],[54.11,-2.81],[54.18,-2.84],[53.53,-2.09],[53.83,-2.98],[53.87,-2.42],[53.82,-2.66],[53.87,-2.41],[53.88,-2.98],[53.96,-2.75],[53.53,-2.02],[53.7,-2.45],[54.06,-2.87],[53.94,-2.34],[53.7,-2.87],[53.61,-2.89],[54.18,-2.84],[54.12,-2.8],[53.86,-2.82],[53.9,-2.53],[53.91,-2.86],[53.81,-2.26],[53.8,-2.51],[53.79,-2.98],[53.79,-3],[53.74,-2.92],[54.11,-2.8],[53.96,-2.49],[53.89,-2.44],[53.87,-2.12],[53.93,-2.77],[53.93,-2.78],[53.86,-2.86],[54.14,-2.46],[54.08,-2.78],[54.07,-2.75],[53.94,-2.86],[53.78,-3],[54.02,-2.89],[53.86,-2.26],[53.68,-2.79],[53.66,-2.75],[53.66,-2.88],[53.78,-2.79],[53.66,-2.31],[53.67,-2.3],[53.6,-2.08],[53.63,-2.09],[54.16,-2.83],[53.62,-2.96],[53.84,-2.15]] console.log(arrA.length + ' ' + Array.isArray(arrA)) console.log(arrB.length + ' ' + Array.isArray(arrB)) console.log(arrA[0].length + ' ' + Array.isArray(arrA[0])) // sample entries console.log(arrB[0].length + ' ' + Array.isArray(arrB[0])) res = arrayIntersect(arrA, arrB) ; console.log('res ' + res + ' ' + Array.isArray(res)) let key = res[0] ; console.log('key ' + key + ' ' + Array.isArray(key)) let idxA = arrA.indexOf(key) ; console.log('idxA ' + idxA) let idxB = arrB.indexOf(key) ; console.log('idxB ' + idxB) Results Server started at http://localhost:8080 28 true 53 true 2 true 2 true res 53.7,-2.45,53.93,-2.77,53.66,-2.75,53.62,-2.96 true key 53.7,-2.45 true idxA -1 idxB 13
When you use arrays with objects in it the indexOf function compares then the object reference and not the object itself to get the index value. And remember, in your case you have arrays in arrays but in javascript also arrays are objects so this aplies as well in your case. Then your arrayIntersect function filters arrB, therefor the originale objects from arrB are stored then in the res array which then only can be used to get back the index in the arrB. One approach could be to just use find for arrA to get the index and just stringify the objects while comparing: function arrayIntersect(a, b) { /* credit https://stackoverflow.com/questions/1885557/simplest-code-for-array-intersection-in-javascript */ var aa = {}; a.forEach(function(v) { aa[v]=1; }); return b.filter(function(v) { return v in aa; }); } const arrA = [[53.88,-2.96],[53.7,-2.45],[53.79,-2.52],[53.66,-2.61],[53.98,-2.34],[53.92,-2.36],[53.89,-2.95],[53.9,-2.94],[53.88,-2.4],[53.89,-2.81],[53.93,-2.77],[53.87,-2.13],[53.9,-2.54],[53.6,-2.91],[54.01,-2.83],[53.83,-2.44],[53.6,-2.88],[54.02,-2.76],[53.99,-2.8],[54.15,-2.79],[53.85,-2.13],[53.62,-2.96],[54,-2.84],[53.66,-2.75],[53.91,-2.27],[53.86,-2.62],[53.51,-2.13],[53.82,-2.3]] const arrB = [[53.82,-2.9],[53.95,-2.73],[53.62,-2.73],[54.11,-2.81],[54.18,-2.84],[53.53,-2.09],[53.83,-2.98],[53.87,-2.42],[53.82,-2.66],[53.87,-2.41],[53.88,-2.98],[53.96,-2.75],[53.53,-2.02],[53.7,-2.45],[54.06,-2.87],[53.94,-2.34],[53.7,-2.87],[53.61,-2.89],[54.18,-2.84],[54.12,-2.8],[53.86,-2.82],[53.9,-2.53],[53.91,-2.86],[53.81,-2.26],[53.8,-2.51],[53.79,-2.98],[53.79,-3],[53.74,-2.92],[54.11,-2.8],[53.96,-2.49],[53.89,-2.44],[53.87,-2.12],[53.93,-2.77],[53.93,-2.78],[53.86,-2.86],[54.14,-2.46],[54.08,-2.78],[54.07,-2.75],[53.94,-2.86],[53.78,-3],[54.02,-2.89],[53.86,-2.26],[53.68,-2.79],[53.66,-2.75],[53.66,-2.88],[53.78,-2.79],[53.66,-2.31],[53.67,-2.3],[53.6,-2.08],[53.63,-2.09],[54.16,-2.83],[53.62,-2.96],[53.84,-2.15]] console.log(arrA.length + ' ' + Array.isArray(arrA)) console.log(arrB.length + ' ' + Array.isArray(arrB)) console.log(arrA[0].length + ' ' + Array.isArray(arrA[0])) // sample entries console.log(arrB[0].length + ' ' + Array.isArray(arrB[0])) res = arrayIntersect(arrA, arrB) ; console.log('res ' + res + ' ' + Array.isArray(res)) let key = res[0] ; console.log('key ' + key + ' ' + Array.isArray(key)) let idxA = arrA.indexOf(arrA.find(el=>JSON.stringify(el)===JSON.stringify(key))) ; console.log('idxA ' + idxA) let idxB = arrB.indexOf(key) ; console.log('idxB ' + idxB)
export generated excel variable to real excel file
this is how I generated Excel variable: Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook excelworkBook; Microsoft.Office.Interop.Excel.Worksheet excelSheet; Microsoft.Office.Interop.Excel.Range excelCellrange; excelworkBook = excel.Application.Workbooks.Add(Type.Missing); excelSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelworkBook.ActiveSheet; //proper data from xml data field to store in excel // ************************ //generate a data table and fill excell cell excelCellrange = excelSheet.Range[excelSheet.Cells[1, 1], excelSheet.Cells[theDataSet.Tables[0].Rows.Count+1, theDataSet.Tables[0].Columns.Count]]; excelCellrange.Font.ThemeColor = Microsoft.Office.Interop.Excel.XlThemeColor.xlThemeColorAccent1; excelCellrange.EntireColumn.AutoFit(); Microsoft.Office.Interop.Excel.Borders border = excelCellrange.Borders; border.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; border.Weight = 3d; excel.Columns.AutoFit(); excel.DisplayAlerts = false; excel.Visible = true; now the question is how save this excel variable to real excel file to specific destination ? best regards.
this is how I figure out this problem that maybe help someone else: Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook excelworkBook; Microsoft.Office.Interop.Excel.Worksheet excelSheet; Microsoft.Office.Interop.Excel.Range excelCellrange; excelworkBook = excel.Application.Workbooks.Add(Type.Missing); excelSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelworkBook.ActiveSheet; XmlDocument xml = new XmlDocument(); xml.LoadXml(dtAll.Rows[gridEX1.CurrentRow.RowIndex]["Data"].ToString()); StringReader theReader = new StringReader(xml.InnerXml); DataSet theDataSet = new DataSet(); theDataSet.ReadXml(theReader); excel.Caption = dtAll.Rows[gridEX1.CurrentRow.RowIndex]["docID"].ToString() + "_" + dtAll.Rows[gridEX1.CurrentRow.RowIndex]["DocTitle"].ToString() + "_" + dtAll.Rows[gridEX1.CurrentRow.RowIndex]["DocDetails"].ToString(); excel.StandardFont = "B Nazanin"; excel.StatusBar = "col count: " + theDataSet.Tables[0].Rows.Count; for (int i = 0; i < theDataSet.Tables[0].Columns.Count; i++) { excel.Cells[1, i + 1] = theDataSet.Tables[0].Columns[i].ColumnName; excel.Cells[1, i + 1].Font.Color = System.Drawing.Color.Blue; for (int j = 0; j < theDataSet.Tables[0].Rows.Count; j++) { excel.Cells[j + 2, i + 1].Font.Color = System.Drawing.Color.Black; excel.Cells[j + 2, i + 1] = theDataSet.Tables[0].Rows[j][i].ToString(); } } excelCellrange = excelSheet.Range[excelSheet.Cells[1, 1], excelSheet.Cells[theDataSet.Tables[0].Rows.Count + 1, theDataSet.Tables[0].Columns.Count]]; excelCellrange.Font.ThemeColor = Microsoft.Office.Interop.Excel.XlThemeColor.xlThemeColorAccent1; excelCellrange.EntireColumn.AutoFit(); Microsoft.Office.Interop.Excel.Borders border = excelCellrange.Borders; border.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; border.Weight = 3d; byte[] output = Encoding.UTF8.GetBytes(xml.InnerXml); string strfn = GroupTitle + ".xlsx"; if (File.Exists(strfn)) { File.Delete(strfn); } FileStream fs = new FileStream(strfn, FileMode.CreateNew, FileAccess.Write); fs.Write(output, 0, output.Length); fs.Flush(); fs.Close(); string dest = Global.DocOutputPath.Substring(0, Global.DocOutputPath.Length - 1) + GroupTitle + ".xlsx"; if (File.Exists(dest)) { DialogResult dialogResult = MessageBox.Show("are you sure about rewrite on file?", "warnning", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { File.Copy(strfn, dest); File.Delete(dest); } else if (dialogResult == DialogResult.No) { return; } } else { File.Copy(strfn, dest); }
How can I modify a M/M/1 queuing system to G/G/1?
I wrote a Monte Carlo simulation for M/M/1 queuing system since it's deterministic. Now I tried modifying the same code for a G/G/1 queueing system with interarrival times and service times having a triangular distribution. Instead of drawing samples from Poisson and exponential distribution, I am drawing samples from the triangular distribution (for G/G/1). However, I am getting results that are hard to make sense of. The analytical approximation results say that the mean waiting time in the queue is 0.9708 which is kinda off from the result (~0.75) I am getting with the simulation. clc clear tic Nc = 1008; Tsys = zeros(1,Nc); Tia = zeros(1,Nc); Ta = zeros(1,Nc); Tsrv = zeros(1,Nc); Tnsrv = zeros(1,Nc); Txsys = zeros(1,Nc); WTqmc = zeros(1,Nc); MTqmc = zeros(1,Nc); MTsys = zeros(1,Nc); Tri1_min = 2; Tri1_mid = 3; Tri1_max = 5; Tri2_min = 1.8; Tri2_mid = 2.8; Tri2_max = 4.5; pdat = makedist('Triangular','a',Tri1_min,'b',Tri1_mid,'c',Tri1_max); pdser = makedist('Triangular','a',Tri2_min,'b',Tri2_mid,'c',Tri2_max); Tia(1) = random(pdat); Ta(1) = Tia(1); Tsys(1) = Tsrv(1); Tnsrv(1) = Ta(1); Tsrv(1) = random(pdser); Txsys(1) = Ta(1) + Tsrv(1); WTqmc(1) = 0; MTqmc(1) = WTqmc(1); for i = 2:1:Nc Tia(i) = random(pdat); Ta(i) = Ta(i-1) + Tia(i); Tsys(i) = Ta(i); if Ta(i) < Txsys(i-1) Tnsrv(i) = Tnsrv(i-1) + Tsrv(i-1); else Tnsrv(i) = Ta(i); end Tsrv(i) = random(pdser); Txsys(i) = Tnsrv(i) + Tsrv(i); WTqmc(i) = Tnsrv(i)-Ta(i); Tsys(i) = Txsys(i) - Ta(i); MTqmc(i) = ((i-1)* MTqmc(i-1) + WTqmc(i))/i; % MTsys(i) = ((i-1)* MTsys(i-1) + Tsys(i))/i; end Tend = Txsys(Nc); Nts = floor(Tend); dt = 1; Time = zeros(1,Nts); Lq = zeros(1,Nts); Time(1) = 0; Lq(1) = 0; for j = 2:1:Nts Time(j) = Time(j-1)+dt; Lq(j) = 0; for i = 1:1:Nc if (Ta(i) < Time(j) && Txsys(i) > Time(j) && Tnsrv(i) > Time(j)) Lq(j) = Lq(j)+1; end end end MLqmc = mean(Lq) MTqmc1 = MTqmc(Nc) MTqmc_mean = mean(WTqmc) SDmtamc = std(WTqmc) SEmtamc = SDmtamc/sqrt(Nc) toc mean1= (2+3+5)/3; mean2=(1.8+2.8+4.5)/3; var1=(4+9+25-2*3-2*5-3*5)/18; var2=(1.8*1.8+2.8*2.8+4.5*4.5-1.8*2.8-1.8*4.5-2.8*4.5)/18; rho= (1/mean1)/(1/mean2); ca2= var1/mean1^2; cs2=var2/mean2^2; Lq=((rho^2)*(1+cs2)*(ca2+(rho^2)*cs2))/(2*(1-rho)*(1+(rho^2)*cs2)); wq=Lq/(1/mean1) %Plot Outcomes figure(1) plot(Ta,MTqmc) xlabel('Arrivals') ylabel('Mean Time in Queue') title('Queue Length vs Time')
pretty printing from any format to a desired format
I am wondering if there is a way by which I can convert a format, let's say a tree to a format I want. Take the following example: a -> b, d f - > c f-> v I want to have this as an output: a implies (b and d) f implies (c or v)
This is practically the algorithm that you are looking for, but please take note that this algorithm doesn't support the deep conditions. function mathLogic(inputs) { var rows = inputs.split("\n"); for (var i in rows) rows[i] = rows[i].replace(/\s/g, ""); console.log("Rows: ", rows) var logics = {}; for (var i in rows) { var row = rows[i]; var rowSplit = row.split("->"); var from = rowSplit[0]; var to = rowSplit[1]; var ands = to.split(","); if (!logics[from]) logics[from] = []; logic = logics[from]; logic.push(ands); } for (var i in logics) { var implyString = i + " implies "; var orLogic = logics[i]; var ors = []; for (var j in orLogic) { var or = orLogic[j] if (or.length > 1) ors.push("(" + or.join(" and ") + ")"); else ors.push(or.join(" and ")); } if (ors.length > 1) implyString += "(" + ors.join(" or ") + ")"; else implyString += ors.join(" or "); console.log(implyString); } } mathLogic(`a -> b, d f - > c f-> v`);
gryo scope and accelerometer output
I am currently working on project using and arduino, a gyro, an accelerometer, and a Bluetooth chip to try to model some data. I am currently trying to gather data, package it up and send it to a phone via Bluetooth. The issue is the Bluetooth chip I am using is a low energy one and so it can only send messages of 20 bytes at a time. I am trying to get past this issue by storing the data collected for a certain amount of time then send it all in 20 byte bursts. I am currently testing this method without sending the data and just printing the data to the serial monitor. This is where my issue is arising, when printing the data in real time everything works but when I try to store it in an array I get this: 593,575,567,0,0,0 592,575,567,0,0,0 592,575,567,0,0,0 592,575,567,0,0,0 592,575,567,0,0,0 593,575,567,0,0,0 586,576,568,0,0,0 0,0,0 0,0 0,0 ,0,0,0 0,0,0 As you can see it seems to just break. If anyone could help me out it would be great! Here is the relevant code chunk for(int i = 0; i < loopVal; i++) { yawGyroValDouble = 0; pitchGyroValDouble = 0; rollGyroValDouble = 0; totalClicksY = 0; angleY = 0; totalClicksP = 0; angleP = 0; totalClicksR = 0; angleR = 0; xRe = 0; yRe = 0; zRe = 0; s = ""; int starttime = millis(); // get start time int endtime = starttime; // init end time while ((endtime - starttime) < time) { getGyroValues(); // This will update rollGyroVal, pitchGyroVal, and yawGyroVal with new values yawGyroValDouble =yawGyroVal; if(abs(yawGyroValDouble) > abs(gyroNoiseThresh)){ // ignore noise totalClicksY+=yawGyroValDouble; // update runsum } pitchGyroValDouble =pitchGyroVal; if(abs(yawGyroValDouble) > abs(gyroNoiseThresh)){ // ignore noise totalClicksP+=pitchGyroValDouble; // update runsum } rollGyroValDouble =rollGyroVal; if(abs(yawGyroValDouble) > abs(gyroNoiseThresh)){ // ignore noise totalClicksR+=rollGyroValDouble; // update runsum } xRe = analogRead(pinX); yRe = analogRead(pinY); zRe = analogRead(pinZ); delay (gyroDelayTime); endtime = millis(); } angleY = totalClicksY / clicksPerDegCCW; angleP = totalClicksP / clicksPerDegCCW; angleR = totalClicksR / clicksPerDegCCW; String yawSend = String(angleY); String pitchSend = String(angleP); String rollSend = String(angleR); String xSend = String(xRe); String ySend = String(yRe); String zSend = String(zRe); //s = "Accel - X: " + xSend + " Y: " + ySend + " Z: " + zSend + "\n" + "Gyro - Yaw: " + yawSend + " Pitch: " + pitchSend + " Roll: " + rollSend; s = "" + xSend + "," + ySend + "," + zSend + "," + yawSend + "," + pitchSend + "," + rollSend; Serial.println(s); res[i] = s; }
You didn't show where totalClicksY, totalClicksP, totalClicksR, and clicksPerDegCCW are declared, but I'm betting they are declared as integer types (int or long). If so, the result of your maths: angleY = totalClicksY / clicksPerDegCCW; angleP = totalClicksP / clicksPerDegCCW; angleR = totalClicksR / clicksPerDegCCW; will be integers. And if the results of those divisions are less than 1, they will be truncated to 0. Try declaring totalClicksY, totalClicksP, totalClicksR and clicksPerDegCCW as double. That, or cast them when you do the math, like this: angleY = (double)totalClicksY / (double)clicksPerDegCCW; angleP = (double)totalClicksP / (double)clicksPerDegCCW; angleR = (double)totalClicksR / (double)clicksPerDegCCW; (I'm also assuming that angleY, angleP, and angleR are also declared as doubles - if not they definitely should be).