Skip to content

Commit

Permalink
numbers can have presets, voltage monitor can disable, and DS can loa…
Browse files Browse the repository at this point in the history
…d projects from github
  • Loading branch information
joshua-8 committed Nov 26, 2024
1 parent 79a162b commit 86bed36
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[
{
"type": "VoltageMonitorCalibrationVal",
"type": "float",
"name": "default",
"value": 310.0
"value": "310",
"mask": [
"adcUnitsPerVolt"
]
},
{
"type": "pin",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[
{
"type": "VoltageMonitorCalibrationVal",
"type": "float",
"name": "default",
"value": 310.0
"value": "310",
"mask": [
"adcUnitsPerVolt"
]
},
{
"type": "pin",
Expand Down
7 changes: 5 additions & 2 deletions RCMv3/boardData/QTPy/presets/parameter_presets/RCM_BYTE.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[
{
"type": "VoltageMonitorCalibrationVal",
"type": "float",
"name": "default",
"value": 310.0
"value": "310",
"mask": [
"adcUnitsPerVolt"
]
},
{
"type": "pin",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[
{
"type": "VoltageMonitorCalibrationVal",
"type": "float",
"name": "default",
"value": 310.0
"value": "310",
"mask": [
"adcUnitsPerVolt"
]
},
{
"type": "pin",
Expand Down
4 changes: 2 additions & 2 deletions RCMv3/rcmutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ void loop()
if (WSC::timedOut()) {
enabled = false;
}

Always();
if (disableEnabled) {
enabled = false;
}

Always();

if (enabled && !wasEnabled) {
Enable();
}
Expand Down
23 changes: 9 additions & 14 deletions RCMv3/rcmv3.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ enum RCMv3DataType {
RC_DATA_BSED,
RC_DATA_TMCChipAddress,
RC_DATA_WhichWire,
RC_DATA_VoltageMonitorCalibrationVal,
RC_DATA_ComponentIndex,
RC_DATA_ComponentInputIndex, /*which input of a component should be accessed*/
RC_DATA_ServoDriver,
Expand All @@ -51,12 +50,11 @@ const char* RCMv3DataTypeNames[] = {
"BSED",
"TMCChipAddress",
"WhichWire",
"VoltageMonitorCalibrationVal", // TODO: ADD METHOD FOR ADDING HELPERS THAT GIVE DEFAULT VALUES WITHOUT CREATING A NEW DATA TYPE?
"ComponentIndex",
"ComponentInputIndex",
"Servo Driver"
};

// TODO: ADD METHOD FOR ADDING HELPERS THAT GIVE DEFAULT VALUES WITHOUT CREATING A NEW DATA TYPE?
typedef struct {
const char* name;
RCMv3DataType type;
Expand Down Expand Up @@ -234,7 +232,7 @@ class RCMv3ParameterHelper {
case RC_TYPE_JVoltageCompMeasure:
return {
{ "measurePin", RC_DATA_Pin },
{ "adcUnitsPerVolt", RC_DATA_VoltageMonitorCalibrationVal },
{ "adcUnitsPerVolt", RC_DATA_Float },
{ "batteryDisableVoltage", RC_DATA_Float },
{ "hysteresis", RC_DATA_Float }
};
Expand Down Expand Up @@ -395,7 +393,7 @@ class RCMv3ComponentMixer : public RCMv3Component {
}
};

#define RCMV3_COMPONENT_J_VOLTAGE_COMP_MEASURE_N 50
#define RCMV3_COMPONENT_J_VOLTAGE_COMP_MEASURE_N 25
class RCMv3ComponentJVoltageCompMeasure : public RCMv3Component {
protected:
float batteryDisableVoltage;
Expand Down Expand Up @@ -423,14 +421,11 @@ class RCMv3ComponentJVoltageCompMeasure : public RCMv3Component {
void run()
{
float batteryVoltage = ((JVoltageCompMeasure<RCMV3_COMPONENT_J_VOLTAGE_COMP_MEASURE_N>*)internalInstance)->getSupplyVoltage();
if (allowEnabled) {
if (batteryVoltage < batteryDisableVoltage) {
allowEnabled = false;
}
} else {
if (batteryVoltage > batteryDisableVoltage + hysteresis) {
allowEnabled = true;
}
if (batteryVoltage < batteryDisableVoltage) {
allowEnabled = false;
}
if (batteryVoltage > batteryDisableVoltage + hysteresis) {
allowEnabled = true;
}
if (allowEnabled == false) {
disableEnabled = true;
Expand Down Expand Up @@ -707,7 +702,6 @@ class RCMv3ComponentFactory {
return false;
}
} break;
case RC_DATA_VoltageMonitorCalibrationVal:
case RC_DATA_Float: {
if (!data[i].is<float>()) {
create_component_error_msg += " invalid float value for parameter " + String(i);
Expand Down Expand Up @@ -755,6 +749,7 @@ class RCMv3ComponentFactory {
} break;
case RC_DATA_ComponentInputIndex: {
if (!data[i].is<int>()) {
create_component_error_msg += " invalid input index type ";
return false;
}
} break;
Expand Down
10 changes: 9 additions & 1 deletion docs/ds/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h1>RCMv3 Driver Station</h1>
<button onclick="loadWifiSettings();">load wifi settings from robot</button>
<br>
enable robot:
<input id="robot-enabled" type="checkbox"></input>
<input id="robot-enabled" type="checkbox" style="width:30px;height:30px;"></input>
<br>
<div class="outer-flex-box">
<canvas class="ds" id="ds" width="600" height="1000"></canvas>
Expand Down Expand Up @@ -89,6 +89,14 @@ <h1>RCMv3 Driver Station</h1>
</div>
</span>
</div>
<br>
<div id="load-projects-div">
load example project from <a target="_blank" rel="noopener noreferrer"
href="https://github.com/RCMgames/RCMv3-examples">here</a>:
<input id="project-name" type="text"></input>
<button onclick="loadProject();">load project</button>
</div>
<br>
<div id="console"></div>
<br>
<footer style="text-align: center;">
Expand Down
69 changes: 53 additions & 16 deletions docs/ds/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,9 +1142,9 @@ function refreshDSItems() {
}

function downloadUIData() {
let data = { controls: [] };
let data = { "UIdata": [] };
for (let i = 0; i < DSItems.length; i++) {
data["controls"].push(DSItems[i].jsonify());
data["UIdata"].push(DSItems[i].jsonify());
}
downloadFile(JSON.stringify(data), 'UIdata.json');
}
Expand All @@ -1162,8 +1162,8 @@ function uploadUIData() {
reader.onload = e => {
const data = JSON.parse(e.target.result);
clearDSItems();
for (let i = 0; i < data.controls.length; i++) {
const item = new DSItem(document.getElementById("ds"), data.controls[i]);
for (let i = 0; i < data.UIdata.length; i++) {
const item = new DSItem(document.getElementById("ds"), data.UIdata[i]);
item.beingEdited = driverstationEditable;
DSItems.push(item);
document.getElementById("ds-list").appendChild(item.nameElement());
Expand Down Expand Up @@ -1273,8 +1273,8 @@ function saveUI() {
console.log(response);
});
}
function loadUI() {
fetch('/loadUI.json')
function loadUI(fromURL = '/loadUI.json') {
fetch(fromURL)
.then(response => {
if (response.ok) {
return response.text();
Expand All @@ -1286,6 +1286,7 @@ function loadUI() {
return JSON.parse(data.substring(0, data.lastIndexOf('}') + 1));
})
.then(data => {
console.log(data);
if (data.UIdata != undefined) {
clearDSItems();
for (let i = 0; i < data.UIdata.length; i++) {
Expand Down Expand Up @@ -1363,6 +1364,7 @@ class ActiveComponent {
this.parameters = [];
for (let i = 0; i < boardInfo.potential_components[this.typeid]["parameters"].length; i++) {
switch (boardInfo.potential_components[this.typeid]["parameters"][i].type) {
// TODO: if there is a parameter_preset with a matching mask maybe use it instead?
case "pin":
this.parameters.push(null);
break;
Expand All @@ -1378,7 +1380,6 @@ class ActiveComponent {
case "int":
this.parameters.push(0);
break;
case "VoltageMonitorCalibrationVal":
case "float":
this.parameters.push(0.0);
break;
Expand Down Expand Up @@ -1671,7 +1672,7 @@ class ActiveComponent {
helper.value = this.parameters[i];
helper.onchange = (event) => {
if (event.target.value) {
this.parameters[i] = event.target.value;
this.parameters[i] = parseInt(event.target.value);
input.value = this.parameters[i];
}
}
Expand Down Expand Up @@ -1731,7 +1732,9 @@ class ActiveComponent {
input.value = this.parameters[i];
}
}
element.appendChild(helper);
if (helper.children.length > 1) {
element.appendChild(helper);
}

}
break;
Expand All @@ -1748,7 +1751,33 @@ class ActiveComponent {
}
element.appendChild(label);
element.appendChild(input);


let helper = document.createElement("select");
let defaultOption = document.createElement("option");
defaultOption.value = null;
defaultOption.textContent = "select";
helper.appendChild(defaultOption);
for (let j = 0; j < loadedParameterPreset.length; j++) {
if (loadedParameterPreset[j].type == "float" && loadedParameterPreset[j].mask.includes(constructorParameter.name)) {
let option = document.createElement("option");
option.value = loadedParameterPreset[j].value;
option.textContent = loadedParameterPreset[j].name;
helper.appendChild(option);
}
}
helper.value = this.parameters[i];
helper.onchange = (event) => {
if (event.target.value) {
this.parameters[i] = parseFloat(event.target.value);
input.value = this.parameters[i];
}
}
if (helper.children.length > 1) {
element.appendChild(helper);
}
}

break;
case "BSED":
{
Expand Down Expand Up @@ -1894,9 +1923,9 @@ function clearConfig() {
}

function saveConfigToFile() {
let componentDataToSend = [];
let componentDataToSend = { "components": [] };
for (let i = 0; i < activeComponentList.length; i++) {
componentDataToSend.push(activeComponentList[i].jsonify());
componentDataToSend["components"].push(activeComponentList[i].jsonify());
}
componentDataToSend = JSON.stringify(componentDataToSend);
downloadFile(componentDataToSend, 'config.json');
Expand All @@ -1909,7 +1938,8 @@ function loadConfigFromFile() {
const file = e.target.files[0];
const reader = new FileReader();
reader.onload = e => {
const data = JSON.parse(e.target.result);
const dataFile = JSON.parse(e.target.result);
const data = dataFile["components"];
for (let i = 0; i < data.length; i++) {
activeComponentList.push(new ActiveComponent(data[i], activeComponentList.length, true));
}
Expand Down Expand Up @@ -1945,11 +1975,11 @@ function loadBoardInfo(errorCallback) {
errorCallback();
});
}
// TODO: SHOW saving... and loading... message
function loadConfig() {

function loadConfig(fromURL = '/loadConfig.json') {
document.getElementById("config-status").innerHTML = "Loading...";
document.getElementById("config-status").style.backgroundColor = "yellow";
fetch('/loadConfig.json')
fetch(fromURL)
.then(response => response.json())
.then(data => {
document.getElementById("config-status").innerHTML = "reloaded";
Expand Down Expand Up @@ -2058,7 +2088,6 @@ async function loadPresets() {
document.getElementById("board-type-selector").dispatchEvent(new Event('change'));
}
});

}

function saveMiscConfigInfo() {
Expand Down Expand Up @@ -2087,3 +2116,11 @@ function saveMiscConfigInfo() {
});
});
}

function loadProject() {
let projectName = document.getElementById("project-name").value;
// TODO: load from any URL, just default to RCMv3-examples
let projectURL = "https://raw.githubusercontent.com/RCMgames/RCMv3-examples/refs/heads/main/" + projectName;
loadUI(projectURL + "/UIdata.json");
loadConfig(projectURL + "/config.json");
}

0 comments on commit 86bed36

Please sign in to comment.