Some questions about async errors

I am setting up a controller to interface to the RVR, but running into some issues with async and await.
Not sure the suggested path, but all of my sensor data is coming in over async just like in multi_sensor_stream.py, but now I want to drive with heading based on a command I am receving.

The problem is that I have a callback function that provides the message I want to convert to RVR drive command, and it isn’t an async, so I have done what I can to separate the async and non-async, but still not able to get commands to the rvr.

rvr = SpheroRvrAsync(
    dal=SerialAsyncDal(
        loop
    )
)

callback function:

def getCommandVel(message):
     print("here")
     print(message)
     driveTheRobot(message)
async def driveTheRobot(message):
     print("let's try")
     print(message)
     await rvr.drive_with_heading(
         speed=155,
         heading=0,
         flags=DriveFlagsBitmask.none.value
     )

setting up callback in main:
rvr_cmd_vel.subscribe(getCommandVel)

If I try:

await driveTheRobot(message)

I get an error:

  File "multi_sensor_stream_rvr.py", line 122
    await  driveTheRobot(message)
                       ^
SyntaxError: invalid syntax

If I don’t await, then it runs, but doesn’t seem to call the driveTheRobot function.

Thoughts?

1 Like

alright, figured it out. Just had to add something to the event loop:
This line is inside a normal method:
def function doSomething:
image

1 Like

Now I seem to be running out of memory. Anyone know how to clear a task to open up memory?

1 Like

the Observer way https://sdk.sphero.com/docs/how_to/raspberry_pi/rp_python_how_to/#drive-raw-motors-1 of controlling RVR in Python seems to be an easier way than async / await :sunglasses:

1 Like

right, but i want to stream the sensor data and based on that data drive the motors… but mixing async and observer can’t work because of how it ties up the serial port.

1 Like

you may stream with observer as well, see the examples like https://github.com/sphero-inc/sphero-sdk-raspberrypi-python/blob/master/getting_started/observer/sensor_streaming/multi_sensor_stream.py