Drive to XY Position Commands

I wish to use the api for Drive-to-XY position. I have attempted to deduce its structure from the Raspi SDK without success. For example, what is the api for a 45 degree angle, X = Y=127, and flag =0. I do not understand why X & Y are in float form (I assume 2 bytes), since -127 to 127 can be stored in 1 byte where bit 7 is the sign. Also the angle must be calculated each time X or Y is changed.


Hey @ngl. Not sure about the Drive-to-XY command. But for streaming position, my arduino code reads the positions in 4 bytes. And the value had to be scaled to between 16000 and -16000.


Hi @ngl,

The goal of the drive to position command interface is to allow RVR to drive to a position in its plane of reference and stop and orient its self with respect to the yaw provided.

You can find SDK documentation that describes the drive to position command interfaces for Asyncio here and for Observer here. There are two functions in each file related to drive to position: drive_to_position_si and drive_to_position_normalized. The main difference between the two commands is that one uses some SI units while the other uses some normalized units. In drive_to_position_si , yaw_angle is a float value while in drive_to_position_normalized it is a int16_t value. In drive_to_position_si , linear_speed is in m/s and a float value while in drive_to_position_normalized it is in normalized units between 0 and 127 and a int8_t value. The drive_to_position_normalized command is useful for saving bandwidth when transferring many commands as it’s payload is smaller and when the user does not care about the units of linear_speed but rather going fast or slow.

You can find some example code for drive_to_position_si here and for drive_to_position_normalized here. You will notice that in each example the following code is run first.

# Reset the yaw and locator.
await rvr.reset_yaw()
await asyncio.sleep(.1)
await rvr.reset_locator_x_and_y()
await asyncio.sleep(.1)

The goal of this code snippet is to reset RVR’s current position to (0,0) in meters and the current yaw heading to 0 degrees. Position and yaw are independent. With respect to RVR the Y-axis is forward and the X-axis is to the right. Yaw follows the right hand rule, it increases to the left and decreases to the right. Lets look at an example command.

   await rvr.drive_to_position_normalized(
        yaw_angle = -90,             # 0 degrees is straight ahead, +CCW (Following the right hand rule)
        x = 0,                       # Target position X coordinate in meters
        y = 0.5,                     # Target position Y coordinate in meters
        linear_speed = 64 ,          # Max speed in transit to target.  Normalized in the range [0..127]
        flags = 0,                   # Option flags

This command will direct RVR to drive from it’s current position to a new position of (0, 0.5) in meters with respect to where position was last zeroed. On reaching the new position RVR will turn -90 degrees with respect to the last time yaw was zeroed and with respect to the right hand rule. While driving to the new position RVR will not exceed 64 normalized units in driving speed.


SPHERO Email Marketing -