You are here

Dev Tools (Scripting)

2 posts / 0 new
Last post
curt
Offline
Last seen: 2 months 3 weeks ago
VESC Free
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

nico01
Offline
Last seen: 3 weeks 4 days ago
VESC Free
Joined: 2024-07-28 11:38
Posts: 1

 Hello Curt,

The code below works on 6.02.

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.vescinterface 1.0
import Vedder.vesc.commands 1.0
import Vedder.vesc.configparams 1.0
import "qrc:/mobile"

Item {
  id: root
  anchors.fill: parent
  property Commands mCommands: VescIf.commands()
  property ConfigParams mMcConf: VescIf.mcConfig()

  property real vAdc1     : 0.0
  property real valueAdc1 : 0.5
  property real vAdc2     : 0.0
  property real valueAdc2 : 0.5

  Timer {
    id: rtTimer
    interval: 50
    running: true
    repeat: true
    onTriggered: {
      if (VescIf.isPortConnected() && visible) {
        mCommands.getDecodedAdc() }
      }
  }

  Connections {
    target: mCommands

    function onDecodedAdcReceived(value, voltage, value2, voltage2) {
      valueAdc1 = value
      vAdc1 = voltage
      valueAdc2 = value2
      vAdc2 = voltage2
    }
  }
  

  ColumnLayout {
    id: gaugeColumn
    anchors.fill: parent
    RowLayout {                     // ligne 1
      Layout.fillHeight: true
      Layout.fillWidth: true
      CustomGauge {                 // ADC 1 gauge
        id: adc1Gauge
        Layout.fillWidth: true
        Layout.preferredWidth: gaugeColumn.width * 0.3
        Layout.preferredHeight: gaugeColumn.height * 0.3
        maximumValue: 5
        minimumValue: 0
        tickmarkScale: 1
        tickmarkSuffix: ""
        labelStep: 1
        value: vAdc1
        precision: 2               
        unitText: "V"
        typeText: "ADC 1"
      }            
            
      CustomGauge {                 // ADC 2 gauge
        id: adc2Gauge
        Layout.fillWidth: true
        Layout.preferredWidth: gaugeColumn.width * 0.3
        Layout.preferredHeight: gaugeColumn.height * 0.3
        maximumValue: 5
        minimumValue: 0
        tickmarkScale: 1
        tickmarkSuffix: ""
        labelStep: 1
        value: vAdc2//1.10
        precision: 2                
        unitText: "V"
        typeText: "ADC 2"
      } 
    }               
  }
}

Tschüss