adeept / Adeept_AWR

Example Code for Adeept Wheeled Robot
15 stars 19 forks source link

Motor movement direction is incorrect #7

Open 51moon opened 9 months ago

51moon commented 9 months ago

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:

Dir_forward   = 1
Dir_backward  = 0

left_forward  = 1
left_backward = 0

right_forward = 0
right_backward= 1

So I invert the first two variables:

Dir_forward   = 0
Dir_backward  = 1

left_forward  = 1
left_backward = 0

right_forward = 0
right_backward= 1

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

adeept commented 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.

51moon commented 9 months ago

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