What does "restore initial default control systems" do?

I don’t see what restore_initial_default_control_systems does. I ran control_system_type_drive_with_yaw and drive_with_yaw_basic_mode and get a 4 back from get_active_control_system_id. Run restore_initial_default_control_systems but still get a 4.

What does it restore?

1 Like

Hi Rud,

When you send get_default_control_system_for_type(control_system_type_drive_with_yaw) it should return 3 for drive_with_yaw_advanced_mode after restoring default control systems (see page 4 of the RVR Control System Manual for defaults). It does what the name implies, and what it sounds like you were expecting.

The default control system for a type is the one that will actually service any incoming drive commands of that type. If you request a change to control system defaults, they will take effect when the robot is next stopped, which might explain your observations. We decided not to build a hot-swap system to hand off execution of a single drive command between different controllers due to the corner cases it would have added.

I modified the observer control_system_selection.py example script to use drive_with_yaw_normalized() instead of drive_rc_si_units(), and I don’t see any issues. I did have to insert a few delays to get the console printing to show up in the correct order (I would guess this is something to do with the way the Pi is buffering serial and console I/O):

import os
import sys
import time
sys.path.append('/home/pi/sphero-sdk-raspberrypi-python')

from sphero_sdk import SpheroRvrObserver
from sphero_sdk import ControlSystemTypesEnum
from sphero_sdk import ControlSystemIdsEnum

rvr = SpheroRvrObserver()

control_system_type = None

def get_default_control_system_response_handler(response):
    global control_system_type
    print(response)
    controller_id = ControlSystemIdsEnum(response['controller_id'])
    print('Default controller for {} is {}'.format(control_system_type.name, controller_id.name))


def get_active_control_system_id_response_handler(response):
    controller_id = ControlSystemIdsEnum(response['controller_id'])
    print('Active controller: {}'.format(controller_id.name))


def main():
    """ This program demonstrates setting and getting the default controller
        for a given control system type.  This allows you to select the
        underlying controller that handles driving.

        A "control system type" is a category of driving control style.  For
        example, RC style takes a target speed and rotational velocity, just
        like an RC car.  Another example is tank drive, which takes individual
        wheel speeds for RVR's left and right treads.

        A "controller" is the underlying mechanism that handles a particular
        control system type.  Selecting the controller allows you to choose
        how RVR handles different situations.  For example, RC driving provides
        two controller options: (1) the "slew mode" which uses a slewed target
        yaw to achieve RVR's rotation, and (2) the "rate mode" which uses
        rotation rate measured directly from the gyroscope.  These controllers
        differ in how they handle obstacles.  Slew mode is "smart" about
        heading.  If RVR encounters an uneven surface or is bumped while
        driving, the slew mode controller will actively adjust RVR's rotation
        to compensate, fighting to maintain its intended, rotating target yaw.
        The "rate mode" is more similar to a traditional RC car.  An uneven
        surface or bump will more directly affect the driving direction. In
        this example, Sphero recommends "slew mode" for programmed maneuvers
        and "rate mode" for a more natural driving experience.

        An important note: a new controller selection takes effect when RVR is
        stopped, so you must issue a stop command to change.
    """
    try:
        global control_system_type

        rvr.wake()

        # Give RVR time to wake up
        time.sleep(2)

        rvr.reset_yaw()

        # Get the default controllers for stop and RC
        control_system_type = ControlSystemTypesEnum.control_system_type_stop
        rvr.get_default_control_system_for_type(
            control_system_type=control_system_type,
            handler=get_default_control_system_response_handler
        )

        time.sleep(0.2)

        control_system_type = ControlSystemTypesEnum.control_system_type_drive_with_yaw
        rvr.get_default_control_system_for_type(
            control_system_type=control_system_type,
            handler=get_default_control_system_response_handler
        )

        # We are currently stopped. Get the currently active control system.
        print('Getting current control system...')
        rvr.get_active_control_system_id(
            handler=get_active_control_system_id_response_handler
        )

        time.sleep(0.2)

        # Drive a bit with RC and check the active control system
        print('Driving with yaw...')
        rvr.drive_with_yaw_normalized(
            linear_velocity=32,  # Valid linear_velocity values are in the range [-127..+127]
            yaw_angle=0  # Valid yaw values are traditionally [-179..+180], but will continue wrapping outside of that range
        )
        rvr.get_active_control_system_id(
            handler=get_active_control_system_id_response_handler
        )

        # Delay to allow RVR to drive
        time.sleep(1)

        # Stop the robot
        print('Stopping...')
        rvr.drive_stop()

        # We don't actually need it to stop, so no delay here.  We just needed the RC drive command to be inactive

        # Set the default control system for RC and drive some more
        control_system_type = ControlSystemTypesEnum.control_system_type_drive_with_yaw
        controller_id = ControlSystemIdsEnum.drive_with_yaw_basic_mode
        print('Setting default control system for RC drive to {}'.format(controller_id.name))
        rvr.set_default_control_system_for_type(control_system_type = control_system_type, controller_id = controller_id)

        print('Driving with yaw...')
        rvr.drive_with_yaw_normalized(
            linear_velocity=32,  # Valid linear_velocity values are in the range [-127..+127]
            yaw_angle=0  # Valid yaw values are traditionally [-179..+180], but will continue wrapping outside of that range
        )
        rvr.get_active_control_system_id(
            handler=get_active_control_system_id_response_handler
        )

        # Delay to allow RVR to drive
        time.sleep(1)

        # Stop the robot
        print('Stopping...')
        rvr.drive_stop()

        # Restore initial default control systems
        print('Restore initial default control systems')
        rvr.restore_initial_default_control_systems()

        print('Driving with yaw...')
        rvr.drive_with_yaw_normalized(
            linear_velocity=32,  # Valid linear_velocity values are in the range [-127..+127]
            yaw_angle=0  # Valid yaw values are traditionally [-179..+180], but will continue wrapping outside of that range
        )
        rvr.get_active_control_system_id(
            handler=get_active_control_system_id_response_handler
        )

        # Delay to allow RVR to drive
        time.sleep(1)

    except KeyboardInterrupt:
        print('\nProgram terminated with keyboard interrupt.')

    finally:
        rvr.close()


if __name__ == '__main__':
    main()

I was trying to do a change on-the-fly. Not likely something to be done in operation.

What I found is get_active_control_system_id is only valid while the RVR is running a command. Once it stop either due to time out or a drive_stop the returned value is 0 for decelerating_stop. The limits the utility of the get_active_control_system_id. Again, not likely something to be done in operation.

I was dismayed at first by the RVR Control System Manual apparent complexity. Now that I’ve gotten to writing the code it is straightforward so good work. Got most of the drive commands and their get capabilities working. Need to do the notifications and haven’t even thought about the skew capabilities.

Update: One way to avoid losing the control system info is to use the drive command setting it to 0 values. This stops motion but doesn’t change the control system id.

For various reasons I moved to using GitLab for the C++ RVR++ V2 library. The Wiki hasn’t caught up to V2.

SPHERO Email Marketing -