Canada
Asked
Resolved Resolved by DJ Sures!

System Exception With Wheel Encoder Counter Skill

Could someone help me understand why I am getting this exception with the Wheel Encoder Counter skill?

  1. I uploaded the firmware DJ's UNO Firmware with Wheel Encoder Counter (Feb 8, 2019) on my Arduino UNO from this link: Arduino Uno Firmware by following the steps in this tutorial: Connecting Arduino to ARC.

  2. I connected the wheel encoders to port D2 and D3 on the UNO.

  3. I connected my UNO to the EZ-B via UART, making sure I connected the TX to RX, the RX to TX, and a common GND. I also provided 5V for the UNO.

Despite this, I get the following error:


System.Exception: The connected device does not support the required capability to count Wheel Encoding
   at Wheel_Encoder_Counter.FormMain.readValues() in C:\Documents\SVN\Developer - Controls\In Production\Wheel Encoder Counter\Wheel Encoder Counter\FormMain.cs

Did I miss something? Do you have any idea what I might have done wrong?

Note: I tried the following baud rates in the .INO file: EZ-Genuino_Wheel_Encoder_Uno.ino


#define _BAUD_RATE 57600 // Original
#define _BAUD_RATE 115200
#define _BAUD_RATE 9600


Related Hardware EZ-B v4

ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

#17   — Edited

That would be really good, yes, i would like to try it. Thank you!!

PRO
Synthiam
#18  

Okay let me whip something up for you to try. Stay tuned

PRO
Synthiam
#19  

@athena, the code in the wheel encoder robot skill to query the values is...

        var response = EZBManager.EZBs[0].SendCommandData(4, 0x00, 0x00);

        UInt16 leftWheel = BitConverter.ToUInt16(response, 0);
        UInt16 rightWheel = BitConverter.ToUInt16(response, 2);

That code only works when the controller is connected to ARC directly over USB. However, Taubore wants to communicate with that controller over the EZB UART. That means the JavaScript UART commands must be used to perform the same function. The BAUD Rate for the EZB UART will need to be 57600 , as that's what is configured in the Arduino firmware that the EZB will be communicating with. Place the EZB UART Init in the connection robot skill script so it only happens upon connection to an ezb. That way, it doesn't reinit the EZB uart for every query. The send commands 0x04, 0x00, 0x00, and the response will be in a separate "script" robot skill that can run in a loop with a slight delay.

Can you rewrite that code using the ARC javascript UART commands?

@Taubore, you will need to connect the Arduino's RX and TX to the EZB's UART. Remember to connect the RX to the TX and the TX to the RX. Also, the GND needs to be common across the EZB and Arduino.

PRO
Canada
#20  

Sure, I can help with that! Let's break down the steps to achieve this:

  1. Initialize the UART on EZ-B: This should be done in the connection script to ensure it only happens once when the EZ-B connects.
  2. Send Commands to the Arduino: This will be done in a loop to continuously query the wheel encoder values.
  3. Read the Response: Parse the response from the Arduino to get the wheel encoder values.

Step 1: Initialize the UART on EZ-B

Add the following script to the connection script of your EZ-B:

// Initialize UART on EZ-B
UART.initHardwareUart(0, 57600); // UART0 with baud rate 57600

Step 2: Send Commands and Read Response

Create a new script in the Script Collection to handle sending commands and reading responses. Here’s an example script:

// Function to query wheel encoder values
function queryWheelEncoders() {
    // Send command to Arduino
    UART.hardwareUartWrite(0, [0x04, 0x00, 0x00]);

    // Wait for a short period to ensure response is received
    sleep(100);

    // Read response from Arduino
    var response = UART.hardwareUartRead(0, 4); // Expecting 4 bytes response

    if (response.length === 4) {
        // Parse the response
        var leftWheel = (response[0] << 8) | response[1];
        var rightWheel = (response[2] << 8) | response[3];

        // Print the values to the console
        print("Left Wheel: " + leftWheel);
        print("Right Wheel: " + rightWheel);

        // Optionally, store the values in global variables
        setVar("$LeftWheel", leftWheel);
        setVar("$RightWheel", rightWheel);
    } else {
        print("Invalid response length: " + response.length);
    }
}

// Loop to continuously query wheel encoders
while (true) {
    queryWheelEncoders();
    sleep(500); // Adjust the delay as needed
}

Step 3: Connect the Hardware

Ensure the hardware connections are correct:

  • Arduino RX to EZ-B TX
  • Arduino TX to EZ-B RX
  • Common GND between Arduino and EZ-B

Putting It All Together

  1. Connection Script: Initialize the UART.
  2. Script Collection: Add the script to query the wheel encoders.
  3. Run the Script: Ensure the script runs in a loop to continuously get the encoder values.

Example of Connection Script

// Initialize UART on EZ-B
UART.initHardwareUart(0, 57600); // UART0 with baud rate 57600

Example of Script Collection Script

// Function to query wheel encoder values
function queryWheelEncoders() {
    // Send command to Arduino
    UART.hardwareUartWrite(0, [0x04, 0x00, 0x00]);

    // Wait for a short period to ensure response is received
    sleep(100);

    // Read response from Arduino
    var response = UART.hardwareUartRead(0, 4); // Expecting 4 bytes response

    if (response.length === 4) {
        // Parse the response
        var leftWheel = (response[0] << 8) | response[1];
        var rightWheel = (response[2] << 8) | response[3];

        // Print the values to the console
        print("Left Wheel: " + leftWheel);
        print("Right Wheel: " + rightWheel);

        // Optionally, store the values in global variables
        setVar("$LeftWheel", leftWheel);
        setVar("$RightWheel", rightWheel);
    } else {
        print("Invalid response length: " + response.length);
    }
}

// Loop to continuously query wheel encoders
while (true) {
    queryWheelEncoders();
    sleep(500); // Adjust the delay as needed
}

Running the Script

  1. Connect to EZ-B: Ensure the connection script initializes the UART.
  2. Run the Script Collection Script: This will continuously query the wheel encoders and print the values.

This setup should help you query the wheel encoder values from the Arduino via the EZ-B UART. If you encounter any issues, feel free to ask for further assistance!


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.