Wixel 3PI+ network issue

I am trying to construct a wireless mesh network through 3pi+ robots and Wixel modules. It works perfectly for just 2 robots, and somewhat unstably, but also basically works with 3 robots. However, when I try to use 4 robots with almost exactly the same code, the network becomes too unstable, making it practically impossible to operate them. I’ve tried many times with different combinations of robots, different batteries, different channels, and different baud rates. I cannot figure out why it works perfectly with 2 robots, works reasonably well for 3 robots, but becomes drastically worse for 4 or more robots. Is there any solution for this type of problem?

Code that I used:

from pololu_3pi_2040_robot import robot
from pololu_3pi_2040_robot.extras import editions
from machine import UART, Pin
import time

# Set robot ID (1, 2, or 3)
ROBOT_ID = 1  # Change this for each robot

# Determine the next robot's ID
if ROBOT_ID == 1:
    NEXT_ROBOT_ID = 2
elif ROBOT_ID == 2:
    NEXT_ROBOT_ID = 3
elif ROBOT_ID == 3:
    NEXT_ROBOT_ID = 1

display = robot.Display()
motors = robot.Motors()
yellow_led = robot.YellowLED()

edition = editions.select()

if edition == "Standard":
    max_speed = 1500
elif edition == "Turtle":
    max_speed = 3000
elif edition == "Hyper":
    max_speed = 1125
    motors.flip_left(True)
    motors.flip_right(True)

def initialize_uart():
    uart = UART(0, baudrate=9600, tx=Pin(28), rx=Pin(29))
    return uart

def send_command(uart, target_id, command):
    packet = bytes([target_id, command])
    uart.write(packet)

def read_command(uart, buffer):
    while uart.any():
        byte = uart.read(1)
        if byte:
            buffer.append(byte[0])
    while len(buffer) >= 2:
        target_id = buffer[0]
        cmd = buffer[1]
        del buffer[:2]
        if target_id == ROBOT_ID:
            return cmd
    return None

uart = initialize_uart()
buffer = []  # Use list for buffer

display.fill(0)
display.show()
time.sleep(1)

cmd1 = 0x00  # Move forward command
cmd2 = 0x01  # Move backward command

# Robot 1 starts the cycle
if ROBOT_ID == 1:
    time.sleep(1)
    
    # Move forward
    yellow_led.on()
    motors.set_speeds(max_speed, max_speed)
    time.sleep(1)
    motors.set_speeds(0, 0)
    time.sleep(1)
    # Send backward command to next robot
    send_command(uart, NEXT_ROBOT_ID, cmd2)

while True:
    command = read_command(uart, buffer)
    
    if command == cmd1:
        # Move forward
        yellow_led.on()
        motors.set_speeds(max_speed, max_speed)
        time.sleep(1)
        motors.set_speeds(0, 0)
        time.sleep(1)
        # Send backward command to next robot
        send_command(uart, NEXT_ROBOT_ID, cmd2)
        
    elif command == cmd2:
        # Move backward
        yellow_led.off()
        motors.set_speeds(-max_speed, -max_speed)
        time.sleep(1)
        motors.set_speeds(0, 0)
        time.sleep(1)
        # Send forward command to next robot
        send_command(uart, NEXT_ROBOT_ID, cmd1)

This is the MicroPython code that I used for the robots, changing just the ‘ROBOT_ID’ parts in accordance with the number of robots.

Hello.

Can you post the programs you have on the Wixels, or tell us which app(s) you’re using if it’s one that we provide, along with the settings you’re using?

- Patrick

1 Like

Sorry for the too late reply. I think it must be ‘wireless-serial-v1.3.wxl’.

The Wireless Serial App is not designed for mesh networking as it does not include any mechanisms to ensure that multiple Wixels will be able to communicate without interfering with each other, such as by making sure the Wixels take turns transmitting or checking that every other Wixel has received the transmission.

- Patrick

I already knew about this issue, so I coded it myself to implement this. If you look at my code, I wrote ‘time.sleep(1)’ in various places to ensure that more than one Wixel module does not send and receive signals at the same time. Moreover, as I wrote above, they actually work well with two and three 3PI+ robots. What I want to know is, why does the performance drop drastically even if I just add one more Wixel module (increasing from 3 to 4 robots)?

The logic for acknowledgments and retransmissions implemented in the Wireless Serial App assumes there are only two Wixels on the channel, so I am not sure why it is working for you with 3 Wixels.

In case it helps you find a solution, you might try looking at Wixel apps other users have created; we have a list in this forum post. Specifically the “radio_multi” and “wireless_serial_channel” apps (both by Geoff) would probably be good to look at.

- Patrick

1 Like

Thank you so much. I’ll try them.