Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to turn a raspberry pie car

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report