# Python controls the movement of the car, how to see the movement process in real time

Hi, I have a question. I use Python to control the movement of my robot (use the speed of the two wheels to control the direction), turn right and then turn left after 3 seconds, when I click “run” and pause for a while, I can only see the final result , that is, turn left directly. I can’t see the right turn 3S and then the left turn in real time in the 3D view. It’s been bothering me for a long time, hope I can get some help.

``````from pxr import Sdf, Gf, UsdPhysics, UsdLux, PhysxSchema
from omni.isaac.dynamic_control import _dynamic_control

stage = omni.usd.get_context().get_stage()

# get handle to the Drive API for both wheels
left_wheel_drive = UsdPhysics.DriveAPI.Get(stage.GetPrimAtPath("/car5/wheel_1/RevoluteJoint"), "angular")
right_wheel_drive = UsdPhysics.DriveAPI.Get(stage.GetPrimAtPath("/car5/wheel_2/RevoluteJoint"), "angular")

# Set the velocity drive target in degrees/second
left_wheel_drive.GetTargetVelocityAttr().Set(143)
right_wheel_drive.GetTargetVelocityAttr().Set(50)

# Set the drive damping, which controls the strength of the velocity drive
left_wheel_drive.GetDampingAttr().Set(1500)
right_wheel_drive.GetDampingAttr().Set(1500)

# Set the drive stiffness, which controls the strength of the position drive
# In this case because we want to do velocity control this should be set to zero
left_wheel_drive.GetStiffnessAttr().Set(50)
right_wheel_drive.GetStiffnessAttr().Set(143)

import time
time.sleep(3)
left_wheel_drive.GetTargetVelocityAttr().Set(50)
right_wheel_drive.GetTargetVelocityAttr().Set(143)
``````

Hi,
yes this is possible however the script has to be a bit more complex. Basically your sleep is just blocking the thread waiting for finish, you need to make sure the application is stepped.
Something like this should do the trick:

``````import asyncio
import omni.kit.app
import omni.client
from omni.kit.async_engine import run_coroutine
from pxr import UsdPhysics

async def turn_right():
time = 0.0
while time < 3.0:
time = time + await omni.kit.app.get_app().next_update_async()

drive = UsdPhysics.DriveAPI.Get(stage.GetPrimAtPath("/World/Cube_01/RevoluteJoint"), "angular")
drive.GetTargetVelocityAttr().Set(-50)

stage = omni.usd.get_context().get_stage()
omni.timeline.get_timeline_interface().play()
drive = UsdPhysics.DriveAPI.Get(stage.GetPrimAtPath("/World/Cube_01/RevoluteJoint"), "angular")
drive.GetTargetVelocityAttr().Set(50)

run_coroutine(turn_right())

``````

This is a simple script that can be executed from the script editor.

Regards,
Ales

Hi,@AlesBorovicka Thank you very much for your help, I tried the method you gave in Script Editor, but unfortunately it failed, suggesting that there is no “run_coroutine”.

Then you can skip using the run_coroutine and use asyncio directly:

``````import asyncio
import omni.kit.app
import omni.client
from pxr import UsdPhysics

async def turn_right():
time = 0.0
while time < 3.0:
time = time + await omni.kit.app.get_app().next_update_async()

drive = UsdPhysics.DriveAPI.Get(stage.GetPrimAtPath("/World/Cube_01/RevoluteJoint"), "angular")
drive.GetTargetVelocityAttr().Set(-50)

stage = omni.usd.get_context().get_stage()
omni.timeline.get_timeline_interface().play()
drive = UsdPhysics.DriveAPI.Get(stage.GetPrimAtPath("/World/Cube_01/RevoluteJoint"), "angular")
drive.GetTargetVelocityAttr().Set(50)