Cheesy Drive

Hi guys,
I’ve been trying to find a way to change up our driving controls to give us more precise and intuitive control using split-arcade without switching over to tank drive. I was reading through articles on both the forum and the Sigbot’s Wiki page when I stumbled across the Cheesy Drive code. I searched through forum for any examples on the coding, specifically for python, but I found none for any type of coding. Based off of the short C++ example on the Wiki, I tried to code a version that, when uploaded, allowed the robot to move forwards and backwards at about 10% velocity. However, it had none of the Cheesy Drive functionality, and would only turn about half of the time when moving the joystick. Below I have my code. Any suggestions on how to fix it, or if there’s something I missed, would be greatly appreciated.

Thank y’all so much,
-11865A

# --- Cheesy Drive + Stop Logic for Controller 1 ---
DEADBAND = 5       # joystick deadband in %
SLEW_RATE = 4.0    # max % change per loop (~50ms loop → 80%/sec)

# Track last outputs for slew rate limiting
last_left_speed = 0.0
last_right_speed = 0.0

def apply_deadband(value, deadband):
    """Zero out small joystick values."""
    return 0 if abs(value) < deadband else value

def clamp(value, min_val, max_val):
    """Limit value to a range."""
    return max(min_val, min(max_val, value))

def slew_limit(target, last, rate):
    """Limit acceleration per loop."""
    delta = target - last
    max_change = rate
    if delta > max_change:
        return last + max_change
    elif delta < -max_change:
        return last - max_change
    else:
        return target

def cheesy_drive(throttle, wheel, quick_turn):
    """Cheesy Drive core algorithm."""
    sensitivity = 0.85
    over_power = 0.0

    if quick_turn:
        over_power = 1.0
        angular_power = wheel
    else:
        angular_power = abs(throttle) * wheel * sensitivity

    left_output = throttle + angular_power
    right_output = throttle - angular_power

    # Clamp outputs to safe range
    left_output = clamp(left_output, -100, 100)
    right_output = clamp(right_output, -100, 100)

    return left_output, right_output

# --- Main Controller Loop ---
def rc_auto_loop_function_controller_1():
    global drivetrain_l_needs_to_be_stopped_controller_1
    global drivetrain_r_needs_to_be_stopped_controller_1
    global controller_1_left_shoulder_control_motors_stopped
    global controller_1_right_shoulder_control_motors_stopped
    global remote_control_code_enabled
    global drivetrain_left_side_speed, drivetrain_right_side_speed
    global last_left_speed, last_right_speed

    while True:
        if remote_control_code_enabled:
            # Stop motors if inertial is calibrating
            if drivetrain_inertial.is_calibrating():
                left_drive_smart.stop()
                right_drive_smart.stop()
                while drivetrain_inertial.is_calibrating():
                    sleep(25, MSEC)

            # --- Read joystick inputs ---
            throttle = apply_deadband(controller_1.axis3.position(), DEADBAND)
            wheel = apply_deadband(controller_1.axis1.position(), DEADBAND)
            quick_turn = controller_1.buttonL1.pressing()  # Quick turn button

            # --- Cheesy Drive math ---
            drivetrain_left_side_speed, drivetrain_right_side_speed = cheesy_drive(throttle, wheel, quick_turn)

            # --- Apply slew rate limiting ---
            drivetrain_left_side_speed = slew_limit(drivetrain_left_side_speed, last_left_speed, SLEW_RATE)
            drivetrain_right_side_speed = slew_limit(drivetrain_right_side_speed, last_right_speed, SLEW_RATE)

            # Save for next loop
            last_left_speed = drivetrain_left_side_speed
            last_right_speed = drivetrain_right_side_speed

            # --- Left side control ---
            if drivetrain_left_side_speed == 0:
                if not drivetrain_l_needs_to_be_stopped_controller_1:
                    left_drive_smart.stop()
                    drivetrain_l_needs_to_be_stopped_controller_1 = True
            else:
                drivetrain_l_needs_to_be_stopped_controller_1 = False
                left_drive_smart.set_velocity(drivetrain_left_side_speed, PERCENT)
                left_drive_smart.spin(FORWARD)

            # --- Right side control ---
            if drivetrain_right_side_speed == 0:
                if not drivetrain_r_needs_to_be_stopped_controller_1:
                    right_drive_smart.stop()
                    drivetrain_r_needs_to_be_stopped_controller_1 = True
            else:
                drivetrain_r_needs_to_be_stopped_controller_1 = False
                right_drive_smart.set_velocity(drivetrain_right_side_speed, PERCENT)
                right_drive_smart.spin(FORWARD)