调用上一章节所提到的小车基本运动代码库ROBOTCAR.pyhttps://blog.csdn.net/weixin_44845743/article/details/143571579?spm=1001.2014.3001.5502 开始小车的基本运动:
1. 小车前进
python
from LOBOROBOT import LOBOROBOT # 载入机器人库
import RPi.GPIO as GPIO
import os
if __name__ == "__main__":
clbrobot = LOBOROBOT() # 实例化机器人对象
try:
while True:
clbrobot.t_up(50,3) # 机器人前进
clbrobot.t_stop(1) # 机器人停止
except KeyboardInterrupt:
clbrobot.t_stop(0) # 机器人停止
GPIO.cleanup()
2. 小车后退
python
from LOBOROBOT import LOBOROBOT # 载入机器人库
import RPi.GPIO as GPIO
import os
if __name__ == "__main__":
clbrobot = LOBOROBOT() # 实例化机器人对象
try:
while True:
clbrobot.t_down(50,3) # 机器人后退
clbrobot.t_stop(1) # 机器人停止
except KeyboardInterrupt:
clbrobot.t_stop(0) # 机器人停止
GPIO.cleanup()
3. 小车左转
python
from LOBOROBOT import LOBOROBOT # 载入机器人库
import RPi.GPIO as GPIO
import os
if __name__ == "__main__":
clbrobot = LOBOROBOT() # 实例化机器人对象
try:
while True:
clbrobot.turnLeft(50,3) # 机器人左转
clbrobot.t_stop(1) # 机器人停止
except KeyboardInterrupt:
clbrobot.t_stop(0) # 机器人停止
GPIO.cleanup()
4. 小车右转
python
from LOBOROBOT import LOBOROBOT # 载入机器人库
import RPi.GPIO as GPIO
import os
if __name__ == "__main__":
clbrobot = LOBOROBOT() # 实例化机器人对象
try:
while True:
clbrobot.turnRight(50,3) # 机器人右转
clbrobot.t_stop(1) # 机器人停止
except KeyboardInterrupt:
clbrobot.t_stop(0) # 机器人停止
GPIO.cleanup()
5. 小车左移
python
from LOBOROBOT import LOBOROBOT # 载入机器人库
import RPi.GPIO as GPIO
import os
if __name__ == "__main__":
clbrobot = LOBOROBOT() # 实例化机器人对象
try:
while True:
clbrobot.moveLeft(50,3) # 机器人左移
clbrobot.t_stop(1) # 机器人停止
except KeyboardInterrupt:
clbrobot.t_stop(0) # 机器人停止
GPIO.cleanup()
6. 小车右移
python
from LOBOROBOT import LOBOROBOT # 载入机器人库
import RPi.GPIO as GPIO
import os
if __name__ == "__main__":
clbrobot = LOBOROBOT() # 实例化机器人对象
try:
while True:
clbrobot.moveRight(50,3) # 机器人右移
clbrobot.t_stop(1) # 机器人停止
except KeyboardInterrupt:
clbrobot.t_stop(0) # 机器人停止
GPIO.cleanup()
7. 小车前左斜
python
from LOBOROBOT import LOBOROBOT # 载入机器人库
import RPi.GPIO as GPIO
import os
if __name__ == "__main__":
clbrobot = LOBOROBOT() # 实例化机器人对象
try:
while True:
clbrobot.forward_Left(50,3) # 机器人前左斜
clbrobot.t_stop(1) # 机器人停止
except KeyboardInterrupt:
clbrobot.t_stop(0) # 机器人停止
GPIO.cleanup()
8. 小车后右斜
python
from LOBOROBOT import LOBOROBOT # 载入机器人库
import RPi.GPIO as GPIO
import os
if __name__ == "__main__":
clbrobot = LOBOROBOT() # 实例化机器人对象
try:
while True:
clbrobot.backward_Right(50,3) # 机器人后右斜
clbrobot.t_stop(1) # 机器人停止
except KeyboardInterrupt:
clbrobot.t_stop(0) # 机器人停止
GPIO.cleanup()
9. 小车前右斜
python
from LOBOROBOT import LOBOROBOT # 载入机器人库
import RPi.GPIO as GPIO
import os
if __name__ == "__main__":
clbrobot = LOBOROBOT() # 实例化机器人对象
try:
while True:
clbrobot.forward_Right(50,3) # 机器人前右斜
clbrobot.t_stop(1) # 机器人停止
except KeyboardInterrupt:
clbrobot.t_stop(0) # 机器人停止
GPIO.cleanup()
10. 小车后左斜
python
from LOBOROBOT import LOBOROBOT # 载入机器人库
import RPi.GPIO as GPIO
import os
if __name__ == "__main__":
clbrobot = LOBOROBOT() # 实例化机器人对象
try:
while True:
clbrobot.backward_Left(50,3) # 机器人后左斜
clbrobot.t_stop(5) # 机器人停止
except KeyboardInterrupt:
clbrobot.t_stop(0) # 机器人停止
GPIO.cleanup()