Open 51moon opened 9 months ago
When the movement trajectory of the car cannot be adjusted correctly by modifying the Dir_forward
and Dir_backward
values, you can adjust it in the following ways.
Modify the move
function in the move.py
file. The left and right directions remain unchanged, but the front and rear directions are reversed to exchange the contents of forward
and backward
.
Change:
def move(speed, direction, turn, radius=0.6): # 0 < radius <= 1
#speed = 100
if direction == 'forward':
if turn == 'right':
motor_left(0, left_backward, int(speed*radius))
motor_right(1, right_forward, speed)
elif turn == 'left':
motor_left(1, left_forward, speed)
motor_right(0, right_backward, int(speed*radius))
else:
motor_left(1, left_forward, speed)
motor_right(1, right_forward, speed)
elif direction == 'backward':
if turn == 'right':
motor_left(0, left_forward, int(speed*radius))
motor_right(1, right_backward, speed)
elif turn == 'left':
motor_left(1, left_backward, speed)
motor_right(0, right_forward, int(speed*radius))
else:
motor_left(1, left_backward, speed)
motor_right(1, right_backward, speed)
elif direction == 'no':
if turn == 'right':
motor_left(1, left_backward, speed)
motor_right(1, right_forward, speed)
elif turn == 'left':
motor_left(1, left_forward, speed)
motor_right(1, right_backward, speed)
else:
motorStop()
else:
pass
To:
def move(speed, direction, turn, radius=0.6): # 0 < radius <= 1
#speed = 100
if direction == 'forward':
if turn == 'right':
motor_left(0, left_forward, int(speed*radius))
motor_right(1, right_backward, speed)
elif turn == 'left':
motor_left(1, left_backward, speed)
motor_right(0, right_forward, int(speed*radius))
else:
motor_left(1, left_backward, speed)
motor_right(1, right_backward, speed)
elif direction == 'backward':
if turn == 'right':
motor_left(0, left_backward, int(speed*radius))
motor_right(1, right_forward, speed)
elif turn == 'left':
motor_left(1, left_forward, speed)
motor_right(0, right_backward, int(speed*radius))
else:
motor_left(1, left_forward, speed)
motor_right(1, right_forward, speed)
elif direction == 'no':
if turn == 'right':
motor_left(1, left_backward, speed)
motor_right(1, right_forward, speed)
elif turn == 'left':
motor_left(1, left_forward, speed)
motor_right(1, right_backward, speed)
else:
motorStop()
else:
pass
In the move
function, forward
and backward
control the car to move forward and backward, and right
and left
control the car to move to the left front, right front, left rear, or right rear. no
controls the car to rotate, right
and left
control the car to turn left or right.
Your suggestion solves the direction problem.
But why do you set the direction variables in the motor_left()
and motor_right()
functions to left_backward
and right_backward
to move forward and vice versa?
Wouldn't it be more intuitive and logically consistent to set the direction variables in the motor_left()
and motor_right()
functions to left_forward
and right_forward
if the direction variable in the move()
function is set to forward and vice versa?
def move(speed, direction, turn, radius=0.6): # 0 < radius <= 1
#speed = 100
if direction == 'forward':
if turn == 'right':
motor_left(0, left_forward, int(speed*radius))
motor_right(1, right_backward, speed)
elif turn == 'left':
motor_left(1, left_backward, speed)
motor_right(0, right_forward, int(speed*radius))
else:
motor_left(1, left_forward, speed)
motor_right(1, right_forward, speed)
elif direction == 'backward':
if turn == 'right':
motor_left(0, left_forward, int(speed*radius))
motor_right(1, right_backward, speed)
elif turn == 'left':
motor_left(1, left_backward, speed)
motor_right(0, right_forward, int(speed*radius))
else:
motor_left(1, left_backward, speed)
motor_right(1, right_backward, speed)
elif direction == 'no':
if turn == 'right':
motor_left(1, left_forward, speed)
motor_right(1, right_backward, speed)
elif turn == 'left':
motor_left(1, left_backward, speed)
motor_right(1, right_forward, speed)
else:
motorStop()
else:
pass
I think there is another bug in the move()
function. You can find a description and a suggested solution here: https://github.com/adeept/Adeept_AWR/pull/6
The motor control of the wheels is set in the file server/move.py.
With the initial settings, forward and backward are reversed, right and left work correctly:
So I invert the first two variables:
Now forwards and backwards are correct, but right and left are reversed.
I think there is a bug in the
move()
function and I have a suggestion to fix it: https://github.com/adeept/Adeept_AWR/pull/6