Thanks again… I have some robot code which came off a remote control car which also had sonar and video, open source code is run on a raspberry PI. it has a simple app for android which allows you to control robot with remote control and view the camera as you move it. i want to replace the motor controller and associated code so that it can be replaced with the ODrive…
like all of these robots it has three py programs, one for avoidance, one to follow a line, the final one which allows remote control of the robot with webcam view… i figure the quickest is one of the simplest so i have attached…
#! /usr/bin/python
-- coding:utf-8 --
import RPi.GPIO as GPIO
import time
def FollowLine():
if (GPIO.input(IR_L) == False)&(GPIO.input(IR_R) == False):#黑线为高,地面为低
Motor_Forward()
return
elif (GPIO.input(IR_L) == False)&(GPIO.input(IR_R) == True):
Motor_TurnRight()
return
elif (GPIO.input(IR_L) == True)&(GPIO.input(IR_R) == False):
Motor_TurnLeft()
return
elif (GPIO.input(IR_L) == True)&(GPIO.input(IR_R) == True):#两侧都碰到黑线
Motor_Stop()
return
def Motor_Forward():
print ‘motor forward’
GPIO.output(ENA,True)
GPIO.output(ENB,True)
GPIO.output(IN1,True)
GPIO.output(IN2,False)
GPIO.output(IN3,True)
GPIO.output(IN4,False)
def Motor_Backward():
print ‘motor_backward’
GPIO.output(ENA,True)
GPIO.output(ENB,True)
GPIO.output(IN1,False)
GPIO.output(IN2,True)
GPIO.output(IN3,False)
GPIO.output(IN4,True)
def Motor_TurnLeft():
print ‘motor_turnleft’
GPIO.output(ENA,True)
GPIO.output(ENB,True)
GPIO.output(IN1,True)
GPIO.output(IN2,False)
GPIO.output(IN3,False)
GPIO.output(IN4,True)
def Motor_TurnRight():
print ‘motor_turnright’
GPIO.output(ENA,True)
GPIO.output(ENB,True)
GPIO.output(IN1,False)
GPIO.output(IN2,True)
GPIO.output(IN3,True)
GPIO.output(IN4,False)
def Motor_Stop():
print ‘motor_stop’
GPIO.output(ENA,False)
GPIO.output(ENB,False)
GPIO.output(IN1,False)
GPIO.output(IN2,False)
GPIO.output(IN3,False)
GPIO.output(IN4,False)
#管脚类型设置
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
########电机驱动接口定义#################
ENA = 13 #//L298使能A
ENB = 20 #//L298使能B
IN1 = 19 #//电机接口1
IN2 = 16 #//电机接口2
IN3 = 21 #//电机接口3
IN4 = 26 #//电机接口4
########红外传感器接口定义#################
IR_R = 18 #小车右侧巡线红外
IR_L = 27 #小车左侧巡线红外
#########电机初始化为LOW##########
GPIO.setup(ENA,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(IN1,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(IN2,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(ENB,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(IN3,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(IN4,GPIO.OUT,initial=GPIO.LOW)
#########红外初始化为输入,并内部拉高#########
GPIO.setup(IR_R,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(IR_L,GPIO.IN,pull_up_down=GPIO.PUD_UP)
time.sleep(2)
try:
while True:
FollowLine()
time.sleep(0.1)
except KeyboardInterrupt:
GPIO.cleanup()
how difficult is it to get this to a base case working code for odrive and hoverboard wheels ?