Start a new topic

Controlling Vehicles Through Codes

Hi, I am trying to control vehicles with predefined code.

For example, one vehicle will move 3m/s speed for 5 seconds, then turn left and change the speed to 5m/s.

Instead of the joystick, I want to set the movement through the code and check later, whether it is working properly or not.


I don't know how to implement that.


Regards-
Dipu Kabir


You can do something like this with Python scripts connected to the Vehicle Systems via a Connection Container. There are several inputs that can be used for control: steering, gas pedal, brake, shifter. Remember that this is physics-based simulation and you won't be able to adjust the speed and heading directly. 


For example, you can use the Odometer Distance output to mesure the distance moved, then trigger a new command to the Steering input to change direction. You can use the vehicle's transform to figure out how many degrees the vehicle has turned, then stop the steering input once the desired heading has been reached. 


image


If you want, you can use the new Intersect Sensor (in release 2017b) to create even more advanced behaviors, such as have the vehicle change direction (or brake!) if an object comes within the sensor's detection volume. 


Have fun, and feel free to share your experiments here!


2 people like this

Thank you for helping.


We can perform automated simulation using time function. Such as setting speed as-

self.outputs.Engine_Speed.value = getSimulationTime()%10


The vehicle starts and stops following an interval.

Login to post a comment