LORD-MicroStrain / MSCL

MicroStrain Communication Library
https://www.microstrain.com/software/mscl
MIT License
76 stars 57 forks source link

Inaccurate data output using WSDA-Base-LXRS and SG-LINL-OEM-LXRS in Python #395

Open nathaniel-chappelle opened 1 month ago

nathaniel-chappelle commented 1 month ago

Using python with the MSCL library. I am able to get connected to the basestation and node, but unable to change node configuration settings. I am also getting very inaccurate data from the node channels when compared to the data I can view within sensor connect. Here is my node configuration function:

def nodeConfiguration(node):
    # Create a wirelessNodeConfig which is used to set all node configuration options
    config = mscl.WirelessNodeConfig()

    enableChannelThree = False
    activeChannels = mscl.ChannelMask()
    activeChannels.enable(1)
    activeChannels.enable(3, enableChannelThree)
    config.activeChannels(activeChannels)

    node.applyConfig(config)
    print("Node configuration applied successfully.")
    print(f"Active channels: {node.getActiveChannels()}")

And here is my data collection function:


def dataCollection(basestation, duration):

    # Force table creation
    force = [["Force"], ["Time"]]
    timeAndDate = str(datetime.now())
    timeAndDate = timeAndDate.replace(" ", "_")
    timeAndDate = timeAndDate.replace(":", "-")

    # Record start time
    startTime = time.time()

    while True:
        # Check if duration has passed
        if time.time() - startTime > duration:
            break

        # Get all data sweeps that have been collected, with a timeout of 500 milliseconds
        sweeps = basestation.getData(500)

        for sweep in sweeps:
            sweep.nodeAddress()
            sweep.timestamp()
            sweep.tick()
            sweep.sampleRate()
            sweep.samplingType()
            sweep.nodeRssi()
            sweep.baseRssi()
            sweep.frequency()

            # get the vector of data in the sweep
            data = sweep.data()

            # Iterate over each point in the sweep (one point per channel)
            for dataPoint in data:
                match = re.match('^ch\d', dataPoint.channelName())
                if (match is not None):
                    print(dataPoint.channelName(), ":", dataPoint.as_float(), end=' ')
                dataPoint.channelName()
                dataPoint.storedAs()
                dataPoint.as_float()
                force[0].append(dataPoint.as_string())
                timeAndDate = str(datetime.now())
                force[1].append(timeAndDate)

    force = list(zip(*force))

    csvFileName = 'testFile.csv'
    with open(csvFileName, mode='w', newline='') as file:
        writer = csv.writer(file)
        writer.writerows(force)```

I am not sure what is going wrong, but my channel 1 value lands around 1000 newtons when it should be 80 newtons. Maybe I have to do some node configuration to change the units, but I am unable to do that. 
nathaniel-chappelle commented 1 month ago

Bump