Uncategorized

Adeept 4WD python programming notes

Asked 
Active today
Viewed 15 times
1

I am unable to understand the code provided with the raspberry pi robo kit I got. I need help in understanding the code as I am new to raspberry. Thanks!

#!/usr/bin/python3
    # File name   : findline.py
    # Description : line tracking 
    # Website     : www.adeept.com
    # E-mail      : support@adeept.com
    # Author      : William
    # Date        : 2018/10/12
    import RPi.GPIO as GPIO
    import time
    import motor
    import turn
    import led

    def num_import_int(initial):        #Call this function to import data from '.txt' file
        with open("set.txt") as f:
            for line in f.readlines():
                if(line.find(initial) == 0):
                    r=line
        begin=len(list(initial))
        snum=r[begin:]
        n=int(snum)
        return n

    status     = 1          #Motor rotation
    forward    = 1          #Motor forward
    backward   = 0          #Motor backward

    left_spd   = num_import_int('E_M1:')         #Speed of the car
    right_spd  = num_import_int('E_M2:')         #Speed of the car
    left       = num_import_int('E_T1:')         #Motor Left
    right      = num_import_int('E_T2:')         #Motor Right

    line_pin_right = 35
    line_pin_middle = 36
    line_pin_left = 38

    left_R = 15
    left_G = 16
    left_B = 18

    right_R = 19
    right_G = 21
    right_B = 22

    on  = GPIO.LOW
    off = GPIO.HIGH

    spd_ad_1 = 1
    spd_ad_2 = 1

    def setup():
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(line_pin_right,GPIO.IN)
        GPIO.setup(line_pin_middle,GPIO.IN)
        GPIO.setup(line_pin_left,GPIO.IN)
        motor.setup()

    def run():
        status_right = GPIO.input(line_pin_right)
        status_middle = GPIO.input(line_pin_middle)
        status_left = GPIO.input(line_pin_left)
        if status_left == 1:
            turn.left()
            led.both_off()
            led.side_on(left_R)
            motor.motor_left(status, forward,left_spd*spd_ad_2)
            motor.motor_right(status,backward,right_spd*spd_ad_2)
        elif status_middle == 1:
            turn.middle()
            led.both_off()
            led.yellow()
            motor.motor_left(status, forward,left_spd*spd_ad_1)
            motor.motor_right(status,backward,right_spd*spd_ad_1)
        elif status_right == 1:
            turn.right()
            led.both_off()
            led.side_on(right_R)
            motor.motor_left(status, forward,left_spd*spd_ad_2)
            motor.motor_right(status,backward,right_spd*spd_ad_2)
        else:
            turn.middle()
            led.both_off()
            led.cyan()
            motor.motor_left(status, backward,left_spd)
            motor.motor_right(status,forward,right_spd)
        pass

    try:
        pass
    except KeyboardInterrupt:
        motor.motorStop()

As soon as I run the module, the wheels turn left and the left led turns RED. I am unable to understand the significance of the variables and the run function code. Please help. Thanks.

 New contributor
  • 1
    I can’t understand it either – ask the author. As far as I can see it will do nothing! None of the functions are ever executed. – Milliways 4 hours ago
  • 1
    @Milliways No Sir, this works with other modules. Here is the link to the project : github.com/adeept/Adeept_PiCar-B You can have a look at the server folder. Thanks, Sir – Vaibhav 3 hours ago
  • 1
    In other words you posted incomplete code – then you expect someone to make sense of it! You stated “As soon as I run the module” it will do nothing – Milliways 2 hours ago
  • Hi @Vaibhav, Welcome and nice to meet you. Ah, let me see. Your program listing gives too much details, Eg, I don’t care when and who wrote it, I only study the function doing the main task. In other words, I zoom in the wood, and blur the trees. Now I am guessing what the wood does and drafting my answer below. Ah, morning tea time, see you later. Cheers. – tlfong01 1 hour ago    

0

Answer

Now I am zooming in the wood and forget the trees:

mov function reading


Now I am chain sawing away the branches:

mov function 2


Now I am tidying up things.

moving function 3


*Now I am zooming out to the three big trees, namely the python modules “motor“*, “turn“, and “LED“.

moving function 4


Now I am zooming out even further, to LED

moving function 5


References

(1) Adeept 4WD Python Module – LED

(2) Adeept 4WD Python Module – Turn

(3) Adeept 4WD Python Module – Motor

(4) Adeept 4WD Python Module – Server

(5) Adeept 4WD Smart Robot Car PiCar-B


Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: