You are here

Dev Tools (Scripting)

1 post / 0 new
curt
Offline
Last seen: 9 months 6 days ago
Joined: 2022-08-22 09:29
Posts: 1
Dev Tools (Scripting)

Hi all,

I am trying to read a voltage [0-3,3V] from ADC1(SCK_ADC_EXT) but I always get an error: ReferenceError: val is not defined

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.2
import Vedder.vesc.utility 1.0

import Vedder.vesc.commands 1.0
import Vedder.vesc.configparams 1.0

Item {
    id: mainItem
    anchors.fill: parent
    anchors.margins: 5
    
    property Commands mCommands: VescIf.commands()
    property ConfigParams mMcConf: VescIf.mcConfig()
    
    ColumnLayout {
        id: gaugeColumn
        anchors.fill: parent
        RowLayout {
            Layout.fillHeight: true
            Layout.fillWidth: true
            CustomGauge {
                id: adc1Gauge
                Layout.fillWidth: true
                Layout.preferredWidth: gaugeColumn.width * 0.45
                Layout.preferredHeight: gaugeColumn.height * 0.45
                maximumValue: 10
                minimumValue: 0
                tickmarkScale: 1
                labelStep: 1
                //value: 0
                unitText: "V"
                typeText: "ADC 1"
            }
            
        }
       
    }
    
    Timer {
        running: true
        repeat: true
        interval: 20        
       
        onTriggered: {
            VescIf.canTmpOverride(false, 113)
            
            mCommands.getDecodedAdc()
            mCommands.getValues()
            
            mCommands.ioBoardGetAll(113)
            
            VescIf.canTmpOverrideEnd()
           
        }
    }
    
    Connections {
        target: mCommands
        
        onValuesReceived: {
            
            console.log(values.vesc_id)
            console.log(values.rpm)
            
            console.log(val.adc_1_4[5])
        }
        
        onIoBoardValRx: {
            console.log("onIoBoardValRx")
            console.log(val.id)
            console.log(val.adc_1_4[0])
            // console.log(val.adc_5_8[0])
        }
    }
}

 

Did some of you already connect an external analog signal to the VESC reading the value? I want to use the value to optimize the control of two motors by a calculation using that measured value from ADC1.

Thanks for ideas