How to turn a raspberry pie car
This article introduces you how to turn the Raspberry Pi car. The content is very detailed. Interested friends can refer to it for reference. I hope it can help you.
Raspberry Pi car turns
The steering of general vehicles is a steering structure, but the car does not have a structure, so it can only start from the wheels. To achieve steering, either the left and right side motor differential, because the speed is not the same, the influence of friction, will inevitably lead to deviation, there is also a way to let the wheel rotate in the opposite direction. Based on this, to achieve a left turn, you can reverse the left wheel and rotate the right wheel forward:
#def turnLeft(speed, lefttime): leftMotor.ChangeDutyCycle(speed) GPIO.output(AIN1, False) GPIO.output(AIN2, True) rightMotor.ChangeDutyCycle(speed) GPIO.output(BIN1, True) GPIO.output(BIN2, False) time.sleep(lefttime)
AIN1, which was set to True when it went forward and turned it forward, is now set to False. The corresponding enable AIN2 is True, which reverses the wheel. It is not difficult to derive the code for the right turn in the same way:
#def turnRight(speed, righttime): leftMotor.ChangeDutyCycle(speed) GPIO.output(AIN1, True) GPIO.output(AIN2, False) rightMotor.ChangeDutyCycle(speed) GPIO.output(BIN1, False) GPIO.output(BIN2, True) time.sleep(righttime)
However, it should be noted that steering will lose some kinetic energy, which is estimated to be understood by those who have driven cars. Therefore, the duty cycle of 50 given for normal forward and reverse is not enough for steering, which may lead to steering failure because of the large value given.
if __name__ == '__main__': try: while True: forward(50,3) turnLeft(70, 3) backword(50,3) turnRight(70,3) except KeyboardInterrupt: GPIO.cleanup()
Finally decided to turn to 70. Of course, different cases, the value is slightly different. At this point, the basic functions of forward, backward, left and right are realized.
About how to turn the Raspberry Pi car to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.