SensorStreamingServices or SensorStreamingControl for normalized values?

Wondering if the normalized values are supposed to be returned when reading from RVR.
For instance, my velocity values are so small. They never make it to 1.
I guess I am a little confused since I saw the SensorStreamingControl which did show that the values were normalized.
Is that the right thought?

from sphero_sdk.common.sensors.sensor_streaming_control import SensorStreamingControl

await rvr.sensor_control.add_sensor_data_handler(
‘Velocity’, velocity_handler
)

1 Like

All the streaming values need to be normalized. See this table. After doing that calculation the values I get are good.

1 Like

ah…k. I tried normalize, but not sure the right range…
I am getting this for Velocity_X at high speed:
-0.0011152017398536884 to 0.0007611524781125922
seems rather small

async def velocity_handler(velocity_data):
print(‘Velocity data response:’, velocity_data)
global velocity_X
velocity_dict = velocity_data[‘Velocity’]
if velocity_dict[‘is_valid’]:
print(‘velocity’)
velocity_X = velocity_dict[‘X’]
velocity_X_norm = normalize(velocity_X, -2147483648, 2147483647, -5, 5)
print(“Velocity_x {} VelocityX_normalize :”, velocity_X, velocity_X_norm)
rvr_Velocity.publish(roslibpy.Message({‘data’:velocity_X}))

1 Like

You’re X value is going to be small. The Rvr orientation is X to the right and Y forward, and, of course, Z up. Straight movement is shown in the Y component.

Also, the input value is an unsigned 32 bit integer so the base value is 0, not a negative max 32 bit integer. Change your inputs to be:

normalize(velocity, 0, 4294967295, -5, 5);
1 Like

is this in your wiki? I went there, but should spend more time I think.

1 Like

I’m not sure. I haven’t been updating it recently so have lost track of what is and isn’t there.

1 Like

okay - still getting strange values -

Velocity_x {} VelocityX_normalize : -0.006987153321269091 -5.000000000016268

Velocity data response: {‘Velocity’: {‘X’: -0.13925850278215002, ‘Y’: 0.05872070907119742, ‘is_valid’: True}}
velocity
Velocity_x {} VelocityX_normalize : -0.13925850278215002 -5.000000000324237

async def velocity_handler(velocity_data):
print(‘Velocity data response:’, velocity_data)
global velocity_X
velocity_dict = velocity_data[‘Velocity’]
if velocity_dict[‘is_valid’]:
print(‘velocity’)
velocity_X = velocity_dict[‘X’]
velocity_X_norm = normalize(velocity_X, -0, 4294967295, -5, 5)
print(“Velocity_x {} VelocityX_normalize :”, velocity_X, velocity_X_norm)
rvr_Velocity.publish(roslibpy.Message({‘data’:velocity_X}))

1 Like

I am trying raw speed too and getting this:

speed
0.7828567923938057

Code:

async def speed_handler(speed_data):
print(“Speed data response:”, speed_data)
global speed
speed_dict = speed_data[‘Speed’]
if speed_dict[‘is_valid’]:
print(‘speed’)
speed = speed_dict[‘Speed’]
print(speed)
rvr_Speed.publish(roslibpy.Message({‘data’:speed}))

1 Like

would be helpful if they provided the raw values to be used…

1 Like

What speed are you setting?

That speed might be correct. Speed is in meters/sec and full speed is spec’ed at 1.5-1.7 m/s. If speed setting is around 128 it might be valid.

For a speed of 128 my raw reading is: 0x289A4080 or 681197696. The calculation is

(681197696 / 4294967295) * 5.0 ==> 0.79301849 m/s

Similarly for velocity x: 0x941DDE00 or 2484985344

(2484985344 / 4294967295) * (5.0 - (-5.0) + -5.0 ==> 0.785807372 m/s
1 Like

Hmmmm… I just read the values output by the ‘Speed’ attribute, no normalize and it is reading that 1.5.
I was stuck on the 0-5 from the attribute table…But if that is Mac speed then that’s right. But the other attributed don’t appear to be consistent.

1 Like

It may be more confusing than helpful but my table for normalization and the normalize method is in this file: https://bitbucket.org/rmerriam/rvr-cpp/src/master/rvr%2B%2B/include/SensorsStream.h

The routines that get the actual data pick out the 4 byte unsigned integer and pass is along with the table values to the normalize routine.

2 Likes

ah…right. so uint32 is going to be 4,294,967,296 and since it is unsigned, it starts at 0, otherwise it would be split down the middle and be -2,147,483,648‬ to 2,147,483,648‬.

1 Like