Uncategorized

mars rover ai robot card code

Asked 
Active today
Viewed 31 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 9 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 8 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 7 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 6 hours ago
  • @Milliways Sorry, Sir! But thanks for helping me. – Vaibhav 2 hours ago
1

Executive Summary

Helping to understand the OP’s AI (OpenCV!) robot car code.


mars rover


/ to continue, …


Contents

1.0 Answer

1.1 Part 1 – Walking through low level (GPIO, DC motor) functions

2.0 References

3.0 Appendices

4.0 Figure, Images, Photos

/ to continue, …


1.0 Answer

Part 1 – Walking through low level (GPIO, DC motor) functions

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 Mars PiCar-B WiFi Smart Robot Car (Speech Recognition, OpenCV Target Tracking, Video Transmission) – Adeept US$95

(2) Adeept Mars Rover PiCar-B Tutorials

(3) Adeept Mars Rover PiCar-B Video (video)

(4) Adeept Mars Rover PiCar-B User Guide (pdf)

(5) Adeept Mars Rover PiCar-B Tutorial and Code (zip)

(6) Adeept 4WD Python Module – LED

(7) Adeept 4WD Python Module – Turn

(8) Adeept 4WD Python Module – Motor

(9) Adeept 4WD Python Module – Server

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

(11) AdaFruit PCA 9685 16 channel PWM servo controller

(12) Tony Dicola of AdaFruit Tutorials (Beginner: mcp23017, ds18b20, servo, buzzer, I2C & SPI; Immediate: PCA9685 (PWM, DC/stepping motor/ servo motor), ILI9341 TFT)


Appendices

Appendix A – Adeept PiCar-B Summary

Adeept Mars PiCar-B WiFi Smart Robot Car (Speech Recognition, OpenCV Target Tracking, Video Transmission) – Adeept US$95

Features

STEM Educational Robot

An complete AI (Artificial Intelligence) robot kit based on the Raspberry Pi (Compatible with RPi 3B/3B+/2B/2B+, Raspberry Pi is NOT included).

Speech Recognition – PiCar-B can be controlled by voice;

Object Recognition and Tracking – based on openCV;

Automatic Obstacle Avoidance – based on ultrasonic sensor;

Line Tracking – based on infrared reflection;

Client Server Architecture – can be remotely controlled by APP on PC;

WS2812 RGB LEDs – can change a variety of colors,

Real-time Video Transmission.

Easy to Assemble and Coding – A 81-page PDF manual with illustrations is considerately prepared for you, which teaches you to assemble your Raspberry Pi robot step by step; Easy-to-understand Python code is provided, with beautiful and practical GUI program(compatible with Windows and Linux operating systems).

Strong Technical Support – Official forum, Blog, YouTube video and instant feedback with E-mails.

Powered by 2×18650 batteries (NOT included). You need to prepare your own batteries.


Product description

The PiCar-B is an AI robot car kit based on Raspberry Pi. It is designed for beginners and professionals to learn AI, Robotics and electronics. We have written a detailed and illustrated manual with which you can quickly complete the assembly of the robot.

PiCar-B has the following characteristics:

  1. Speech Recognition – it can understand your words and then execute your commands;
  2. Object Recognition and Tracking – based on openCV,can track objects of a specific shape or color;
  3. Line Tracking – based on infrared reflection, it can walk along the route you set;
  4. Automatic Obstacle Avoidance – based on ultrasonic sensor, it can avoid obstacles ahead and find the next path;
  5. Real-time Video Transmission – it can transfer the real-time images taken by the Raspberry Pi camera to a remote computer.
  6. Remotely Controlled by APP – You can remotely control the robot through the buttons on the keyboard or the virtual buttons on the GUI.
  7. Equipped with 12x WS8212 serial RGB LEDs, these RGB LEDs can be controlled through only one GPIO pin, which can change a variety of colors and indicate the working state of the robot.

Video

Tutorials

Package List:

1 Set Acrylic Plates

1x Adeept Motor HAT V2.0

1x Raspberry Pi Camera(with Cable)

1x USB Microphone

1x Ultrasonic Sensor Module

2x Adeept RGB LED Module

4x Adeept WS2812 RGB LED Module

1x Adeept 3CH Line Tracking Module

3x Servo

1x Gear Motor

4x Wheels

1x Battery Holder

1x Cross Socket Wrench

2x Cross Screwdriver(Small and Large)

1x Winding Pipe

10x Bearing(6*F624ZZ + 4*F687ZZ)

2x Umbrella Gear Set

Other necessary accessories(Wires, Nuts, Screws, Copper Standoffs, Couplings)


  • 1
    Thanks a lot, sir! It is really helpful. I am new to the community and I thank you for helping me. – Vaibhav 2 hours ago
  • 1
    Dear sir, I have doubts in the turn.py code, should I post it here? Or should I post a new question? – Vaibhav 2 hours ago
  • 1
    Respected Sir, I have posted the question, please help me. Link is: raspberrypi.stackexchange.com/questions/108880/… – Vaibhav 2 hours ago
  • Hi @Vaibhav, you are very welcome. My first impression is that your Rpi smart robot car, using OpenCV, and voice recognition etc is rather advanced. The best thing is that it is open hardware and open software. So I think your question is a big contribution to the community. BTW I don’t know nothing about OpenCV, so I am reading the docs to learn how it can be used to track an object, NOT tracking a line! 🙂 – tlfong01 2 hours ago
  • Oh my goodness, you are indeed an impatient guy. I forgot to mention earlier that your robot card using the PWM controller PCA9685 is also a bit advanced. All in all, I think this is a STEM educational toy aiming for hacker like DIY makers. – tlfong01 1 hour ago
  • 1
    Thanks a lot sir for your help. The link tracking is done using the Adeept-3 channel line tracking IR module and DC motor sir. Respected sir, I want you to have a look at the question it is regarding Adafruit_PCA9685 and servo motor. I am really thankful that this community exists. – Vaibhav 1 hour ago
  • 1
    Sorry for being impatient, Sir. – Vaibhav 1 hour ago
  • So for the the impatient guy I have included in my reference list the Lady Ada’s tutorial on PCA9685. Me IQ97 need at least one hour to digest the PCA9685 stuff. So you need to tell me your IQ, so I can feed you not too fast to choke you. 🙂 – tlfong01 1 hour ago
  • Before I forgot, the WS2812 RGB LED Module is also a bit advanced. BTW – I very much agree Adeept saying that their educational toy is “It is designed for beginners and professionals to learn AI, Robotics and electronics.” – tlfong01 1 hour ago
Please avoid extended discussions in comments. Would you like to automatically move this discussion to chat?
.END

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: