Page 2
Resources Link RobotName: Adeept_RaspClaws RobotURL: https://github.com/adeept/Adeept_RaspClaws RobotGit: https://github.com/adeept/Adeept_RaspClaws.git [Official Raspberry Pi website] https://www.raspberrypi.org/downloads/ [Official website] https://www.adeept.com/ [GitHub] https://github.com/adeept/Adeept_RaspClaws [Image file and Documentation for structure assembly] https://www.adeept.com/learn/detail-37.html...
Page 3
Components List Acrylic Plates The acrylic plates are fragile, so please be careful when assembling them in case of breaking. The acrylic plate is covered with a layer of protective film. You need to remove it first. Some holes in the acrylic may have residues, so you need to clean them before the use.
Page 6
Tools Self-prepared Parts 18650 battery specification: It is recommended to use lithium battery above 3000mAh and without overcurrent protection. The power supply current requirement is above 3A. Using 18650 lithium battery with overcurrent protection function, 18650 battery whose capacity is less than 1700mAh, 18650 battery specially for strong-light flashlight, 18650 battery with power shortage or counterfeit lithium battery produced by informal manufacturers will cause the unstable work of the robot,power cut and even damage to the Raspberry Pi and robot.The robot can be turned on normally,but the Raspberry Pi will automatically restart or shut down after, also because of the...
Content 1. Premise....................................1 1.1 STEAM and Raspberry Pi..............................1 1.2 About the Documentation..............................1 2. Raspberry Pi System Installation and Development Environment Establishment............3 2.1 Install An Operating System for The Raspberry Pi......................3 2.1.1 Method A: Write 'Raspbian' to The SD Card by Raspberry Pi Imager..............3 2.1.2 Method B: Download The Image File Raspbian and Write It to The SD Card Manually........
Page 8
14.1 Multi-threading Introduction............................. 87 14.2 Realization of Police Lights / Breathing Lights......................87 14.3 Warning Lights or Breathing Lights in Other Projects....................92 15 Real-Time Video Transmission............................94 16 Why OpenCV Uses Multi-threading to Process Video Frames..................98 16.1 Single Thread Processing of Video Frames.........................98 16.2 Multi-thread Processing of Video Frames........................99 ...
1. Premise 1.1 STEAM and Raspberry Pi STEAM stands for Science, Technology, Engineering, Arts and Mathematics. It's a type of trans disciplinary education idea focused on practice. As a board designed for computer programming education, Raspberry Pi has lots of advantages over other robot development boards.
2. Raspberry Pi System Installation and Development Environment Establishment 2.1 Install An Operating System for The Raspberry Pi 2.1.1 Method A: Write 'Raspbian' to The SD Card by Raspberry Pi Imager Raspberry Pi Imager is an image writing tool to SD card developed by the Raspberry Pi Organization. It comes with many versions working on different systems and it's quite easy to use;...
Page 12
●Insert the SD card into the card reader, connect the card reader with your computer. ●Run the Raspberry Pi Imager, select CHOOSE OS -> Raspbian(other) -> Raspbian Full - A port of Debian with desktop and recommended applications. ●Click on CHOOSE SD CARD for the SD card to write the Raspbian Full, please be noted that the image writing will automatically delete all files on the SD card if any.
●Do not remove the SD card connected after writing is completed, we'll use for configuring SSH and WiFi connection later. Otherwise, if you remove the card, insert it into the Raspberry Pi and boot, WiFi configuration without any peripherals may fail in the following process. 2.1.2 Method B: Download The Image File Raspbian and Write It to The SD Card Manually ●Since the image file is downloaded with Raspberry Pi Imager in 2.1.1, it can take a long time due to a slow network in some places.
Page 14
4. Download the image file `Raspbian` - Torrent file: [Raspbian-Raspbian Buster with desktop and recommended software] -Zip file: [Raspbian - Raspbian Buster with desktop and recommended software] 5. Unzip the file, be noted that the path should be in English for the `.img` file extracted, no special ...
Page 15
●On the Raspberry Pi website [Official Raspberry Pi website], select through Downloads -> Raspbian -> Raspbian Buster with desktop and recommended software, and click on the torrent or zip file to download. Unzip the file after download, be noted that the path should be in English for the .img file extracted, no special characters allowed;...
●Do not remove the SD card connected after writing is completed, we'll use for configuring SSH and WiFi connection later. Otherwise, if you remove the card, insert it into the Raspberry Pi and boot it up, WiFi configuration without any peripherals may fail in the following process. 2.1.3 Method C: Manually Download The Image File Provided by Us and Write It to The SD Card (Not Recommended) ●...
Page 17
3. Install the `Raspberry Pi Imager` 4. Download the image file `Adeept_RaspClaws` [Image file for the Adeept_RaspClaws Robot] 5. Unzip the file, be noted that the path should be in English for the `.img` file extracted, no special characters allowed. 6.
will automatically delete all files on the SD card if any. ●Click on WRITE, wait for the writing. ●Do not remove the SD card connected after writing is completed, we'll use for configuring WiFi connection later. Otherwise, if you remove the card, insert it into the Raspberry Pi and boot it up, WiFi configuration without any peripherals may fail in the following process.
2.2.1 Method A: Enable SSH with Peripherals ●If you use (2.1.3 to manually download the image file we provide and write it to the SD card) to write the operating system of the Raspberry Pi to the SD card, you do not need to refer to this section to open SSH, because The SSH service in the image is already enabled.
●If you haven't connected any monitor to the Raspberry Pi, follow these steps to enable SSH. 1. Do not remove the SD card after `Raspberry Pi Imager` writes the image file. 2. Create a file named `ssh` under any directory, without any extension name. You may create a `ssh.txt` and delete the `.txt` (make sure under Folder Options the box of Hide extensions for known file types is unchecked.
Page 21
4. Type in your own information for `Insert country code here`, `Name of your WiFi`, and `Password for your WiFi`. Pay attention to the capitalization. Refer to the example below: ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=US network={ ssid="MyName" psk="12345678" 5. Save and exit. Copy the `wpa_supplicant.conf` to the root directory of the SD card. 6.
Power supply. ●The Motor HAT board of the Adeept Raspberry Pi Robot can supply power for the Raspberry Pi via GPIO port. However, since it may take a long time to install software on the Raspberry Pi, it's not recommended to supply with the batteries during this process. You may skip the installation of the Motor HAT board or camera during software installation;...
of the Raspberry Pi, `raspberry` (pay attention to capitalization). There's no change on the screen when you're typing in, but it doesn't mean you're not entering the information. Press ‘enter’ after you finish typing in. ●So now you've logged into the Raspberry Pi. 3.2 Log into Raspberry Pi (Linux or Mac OS) ●Before connecting the Raspberry Pi via SSH, you need to know the IP address of the Raspberry Pi.
●In the previous section you've logged into the Raspberry Pi, and here type in the follow command in the terminal window: sudo git clone https://github.com/adeept/Adeept_RaspClaws.git ●Press ‘enter’ to start downloading the program of the robot from GitHub. It may take some time, please...
wait until it's done. 3.5 Install Corresponding Dependent Libraries ● Follow the steps below to install the libraries if you wrote the image file to the SD card based on 2.1.1 Write 'Raspbian' to the SD card by `Raspberry Pi Imager` and 2.1.2 Download the image file `Raspbian` and write it to the SD card manually.
● If it fails to enter the page, log into the Raspberry Pi via SSH, type in the command below to end the program auto run at boot to release resources, or else issues like camera initialization failure or occupied ports. sudo killall python3 ●Type in the command below to run `webServer.py`: sudo python3 Adeept_RaspClaws/server/webServer.py...
Page 27
If your servo does not return to the original position automatically, you can manually run the server.py file and then try to connect the servo. ●Preparations before Assembly 1. Connect the Raspberry Pi Camera and the ribbon.
Page 28
2. Connect the Raspberry Pi Camera and the RaspberryPi.
Page 30
3. Fix four M2.5x10+6 Copper Standoffs on Raspberry Pi.
Page 31
4.Connect the driver board to mpu-6050. Effect diagram after assembling...
Page 32
5.Connect the 18650 Battery Holder Set to the Adeept Motor HAT.
Page 35
● Before switching on, you need to insert the configured SD card into the Raspberry Pi. For details, please refer to the third chapter of the document. Otherwise, the servo will not rotate to the middle position after booting. In the next installation, the servos need to be connected to the robot HAT. And the Raspberry Pi will automatically adjust the servo to the correct angle.
4.2 Tips for Structural Assemblage ●Since many servos are used in the product, the servo installation is critical for the robot. Before installing the rocker arm to the servo, you need to connect the servo to power and make the servo shaft rotate to the central position, so the rocker arm installed at the designated degree will be in the central position.
Page 62
●You can also use a power lithium battery to power Motor HAT. Motor HAT supports the power supply that is below 15V. ●You can use a USB cable to supply power to Motor HAT when the installing the rocker arm of the servo during structural assembly.
5 Controlling A Robot via WEB App ●The WEB app is developed for common users to control the robot in an easier way. It's convenient to use WEB app; you may use it to wirelessly control the robot on any device with a web browser (Google Chrome was used for testing).
Page 64
Raspberry Pi. ●`Actions`window control unique functions of the robot: ·`MOTION GET`: Motion detection function based on OpenCV. When objects move in the view of the camera, the program will circle the part in the `Video` window, and the LED light on the robot will show respective changes.
6 Common Problems and Solutions(Q&A) ●Where to find the IP address of the Raspberry Pi? Before connecting the Raspberry Pi via SSH, you need to know the IP address of the Raspberry Pi. Check the Management interface for your router, or download the app `Network Scanner` -> search for a device named `RASPBERRY` or `Raspberry Pi Foundation` to get the IP address.
Page 66
●The servo doesn't return to the central position when connected to the driver board. In general, the Raspberry Pi will auto run `webServer.py` when booting, and `webServer.py` will run and control the servo ports to send a signal of rotating to the central position. When assembling the servo, you can connect it to any servo port anytime.
Page 67
●After running the server, I get an error and can't find config.txt This is because the installation script did not copy con fi g.txt to the specified location due to permissions problems during installation. The new version of webServer will not use this file, only the old version of the server will use it.
7 Set The Program to Start Automatically 7.1 Set The Specified Program to Run Automatically at Boot ●This section only introduces the auto-run method used by our products. If you need more information about the Raspberry Pi auto-run program, you can refer to this document from itechfythe document Auto-Run.
Page 69
●For example, if we want to replace webServer.py with server.py, we only need to edit the following: Replace sudo python3 [RobotName]/server/webServer.py with sudo python3 [RobotName]/server/server.py ●Save and exit so that the robot will automatically run server.py instead of webServer.py the next time the robot is turned on.
8 Remote Operation of Raspberry Pi Via MobaXterm ●To make daily use of the Raspberry Pi more convenient, we usually do not connect peripherals such as mouse, keyboard, and monitor to the Raspberry Pi. Since our Raspberry Pi is installed inside the robot, often with peripherals to control the Raspberry Pi, the efficiency of programming and testing will be seriously affected.
Page 71
to the Raspberry Pi again, if there is no save username and password will need to input the user name and password, if the IP address of the Raspberry Pi changed, you need to start a new dialogue. ● After a successful login, the left column is replaced with a file transfer system, which allows you to interact with the system inside the Raspberry Pi.
9 How to Control WS2812 RGB LED ●WS2812 LED light is a commonly used module on our robot products. There are three WS2812 lights on each module. Please pay attention when connecting. The signal line is different in direction, which needs to be connected to WS2812 after being led out from the Raspberry Pi.
Page 73
self.LED_COUNT, self.LED_PIN, self.LED_FREQ_HZ, self.LED_DMA, self.LED_INVERT, self.LED_BRIGHTNESS, self.LED_CHANNEL self.strip.begin() colorWipe(self, R, G, B): This function is used to change the color of the LED light color = Color(R, G, B) range(self.strip.numPixels()): Only one LED light color can be set at a time, so we need to do a loop self.strip.setPixelColor(i, color) self.strip.show() The color will only change after calling the show method...
Page 74
●Instantiate the object and execute the method function. The function colorWipe () needs to pass in three parameters, namely R, G, and B, which correspond to the brightness of the three primary colors of red, green, and blue. The value range is 0- 255, the larger the value, the higher the brightness of the corresponding color channel.
10 How to Control The Servo 10.1 Control The Steering Gear to Rotate to A Certain Angle ● Since the servo can use the PWM signal to control the rotation angle of a mechanism, it is a more commonly used module on robot products.
● pwm.set_pwm (3, 0, 300) This method is used to control the rotation of a servo to a certain position, where 3 is the servo port number, which corresponds to the number identified on the Motor HAT driver board, but pay attention to the rudder When the machine is connected to the drive board, do not insert the reverse direction of the ground wire, VCC and signal wire, brown to black, red to red, yellow to yellow;...
10.3 Non-blocking Control ●You can find the RPIservo.py file in the server folder of the robot product, copy it to the same folder as the program you want to run, and then you can use this method in your program. import RPIservo # Import a library that uses multiple threads to control the steering gear...
11 Calling the API to Control the Robot ●For the reason that the movement and other functions of walking robots are much more complicated than wheeled robots: • The wheeled robot only needs to control the high and low levels of a few GPIO ports to control the movement of the robot.
Page 79
init_pwm7 = 300 init_pwm8 = 300 init_pwm9 = 300 init_pwm10 = 300 init_pwm11 = 300 init_pwm12 = 300 init_pwm13 = 300 init_pwm14 = 300 init_pwm15 = 300 ●The code responsible for initialization is in move.py, call the initial value init_pwm in RPIservo.py through exec, use the for loop to take out all the initial values and assign it to pwm0, pwm1...
Page 81
●In webserver.py, use the functionSelect() function to start the action of the robot: functionSelect(command_input, response): direction_command, turn_command, SmoothMode, steadyMode, functionMode global 'scan' == command_input: pass elif 'findColor' == command_input: flask_app.modeselect('findColor') 'motionGet' == command_input: # Moving object detection elif flask_app.modeselect('watchDog') 'stopCV' == command_input: elif flask_app.modeselect('none')
Page 82
●We control the robot to move forward, move backward, turn left, turn right, switch between fast and slow gait, and maintain self-balance in move.py. When the webserver, py receives the forward command "command_input", it will call the commandInput() function in move.py. When the commandInput() function receives an instruction, it starts a thread, calls the corresponding action, and executes a fast gait by default, such as forward moving, backward moving, left turn, and right turn: move_thread():...
12 Automatic Stabilization Function ● Based on the automatic stabilization function of the robot realized by MPU6050 , after starting this function, you can place the robot on a panel, and then tilt the panel. The robot will keep the body balanced by changing the height of the corresponding leg.
Page 86
X = accelerometer_data['x'] X = kalman_filter_X.kalman(X) Y = accelerometer_data['y'] Y = kalman_filter_Y.kalman(Y) ''''' Carry out Kalman filtering on the data X_fix_output += -X_pid.GenOut(X - target_X) X_fix_output = ctrl_range(X_fix_output, steady_range_Max, -steady_range_Max) Y_fix_output += -Y_pid.GenOut(Y - target_Y) Y_fix_output = ctrl_range(Y_fix_output, steady_range_Max, -steady_range_Max) #LEFT_I left_I_input = ctrl_range((X_fix_output + Y_fix_output), steady_range_Max, steady_range_Min) left_I(0, 35, left_I_input)
13 Gait Generation Method of A Hexapod Robot ●For the hexapod robot, the gait generation method is almost the most complicated part of the program, because it needs to coordinate dozens of servos to move at the same time, and keeps every moment when walking forward and backward there must be at least three legs on the ground, which means that only three legs can be in the swing pair at least at any moment, and at least three legs should be in the support pair.
Page 88
return command == 'no': When the speed is positive, the robot moves forward. When the speed is negative, the robot move s backward. right_I(step_I, speed, 0) left_II(step_I, speed, 0) right_III(step_I, speed, 0) left_I(step_II, speed, 0) right_II(step_II, speed, 0) left_III(step_II, speed, 0) elif command == 'left': right_I(step_I, speed, 0)
14 Make A Police Light or Breathing Light 14.1 Multi-threading Introduction ● This chapter introduces the use of multi-threading to achieve some effects related to WS2812 LED lights. Multi-threading is a commonly used operation in robot projects. Because robots have high requirements for real-time response, when performing a certain task, try not to block main thread communication.
Page 96
Use the Threading module to create threads, inherit directly from threading.Thread, and then override the __init__ method and the run method class RobotLight(threading.Thread): __init__(self, *args, **kwargs): Here initialize some settings about LED lights self.LED_COUNT # Number of LED pixels. self.LED_PIN # GPIO pin connected to the pixels (18 uses PWM!).
Page 97
super(RobotLight, self).__init__(*args, **kwargs) self.__flag = threading.Event() self.__flag.clear() # Define functions which animate LEDs in various ways. setColor(self, R, G, B): Set the color of all lights color = Color(int(R),int(G),int(B)) range(self.strip.numPixels()): self.strip.setPixelColor(i, color) self.strip.show() setSomeColor(self, R, G, B, ID): Set the color of some lamps, the ID is the array of the serial number of this lamp color = Color(int(R),int(G),int(B)) #print(int(R),' ',int(G),' ',int(B)) self.strip.setPixelColor(i, color)
Page 98
Call this function to turn on the police light mode self.lightMode = 'police' self.resume() policeProcessing(self): The specific realization of the police light mode while self.lightMode == 'police': Blue flashes 3 times range(0,3): self.setSomeColor(0,0,255,[0,1,2,3,4,5,6,7,8,9,10,11]) time.sleep(0.05) self.setSomeColor(0,0,0,[0,1,2,3,4,5,6,7,8,9,10,11]) time.sleep(0.05) self.lightMode != 'police': break time.sleep(0.1) Red flashes 3 times range(0,3):...
Page 99
self.colorBreathB = B_input self.resume() breathProcessing(self): Specific realization method of breathing lamp while self.lightMode == 'breath': All lights gradually brighten range(0,self.breathSteps): self.lightMode != 'breath': break self.setColor(self.colorBreathR*i/self.breathSteps, self.colorBreathG*i/self.breathSteps, self.colorBreathB*i/self.breathSteps) time.sleep(0.03) All lights are getting darker range(0,self.breathSteps): self.lightMode != 'breath': break self.setColor(self.colorBreathR-(self.colorBreathR*i/self.breathSteps), self.colorBreathG-(self.colorBreathG*i/self.breathSteps), self.colorBreathB-(self.colorBreathB*i/self.breathSteps)) time.sleep(0.03) lightChange(self):...
run(self): Functions for multi-threaded tasks while self.__flag.wait() self.lightChange() pass __name__ == '__main__': RL=RobotLight() # Instantiate the object that controls the LED light RL.start() # Start thread Start breathing light mode and stop after 15 seconds RL.breath(70,70,255) time.sleep(15) RL.pause() Pause for 2 seconds time.sleep(2) Start the police light mode and stop after 15 seconds RL.police()
Page 101
RL=robotLight.RobotLight() # Instantiate the object that controls the LED light RL.start() # Start thread Start breathing light mode and stop after 15 seconds RL.breath(70,70,255) time.sleep(15) RL.pause() Pause for 2 seconds time.sleep(2) Start the police light mode and stop after 15 seconds RL.police() time.sleep(15) RL.pause()
15 Real-Time Video Transmission ● Real-time video and OpenCV function are the advantages of the Raspberry Pi robot. This chapter introduces the method of real-time video. In fact, there are many ways to transfer the images collected by the Raspberry Pi camera to other devices through the network The robot uses the open source project [ fl...
Page 103
display the Raspberry Pi on the page in real time. Camera screen. sudo nano app.py ●Here we use nano that comes with Raspbian to open app.py for editing in the console. Since it is just some operations for commenting and deleting comments, there is no need to use other IDEs for editing. ●After opening the IDE, we comment out the code: os.environ.get('CAMERA'): Camera = import_module('camera_' + os.environ['CAMERA']).Camera...
Page 104
from importlib import import_module import from flask import Flask, render_template, Response # import camera driver if os.environ.get('CAMERA'): Camera = import_module('camera_' + os.environ['CAMERA']).Camera else: from camera import Camera # Raspberry Pi camera module (requires picamera package) from camera_pi import Camera app = Flask(__name__) @app.route('/') index(): """Video streaming home page."""...
Page 105
sudo app.py ●Open the browser on the device on the same local area network as the Raspberry Pi (we use Google Chrome to test), and enter the IP address of the Raspberry Pi plus the video streaming port number: 5000 in the address bar, as shown in the following example: 192.168.3.157:5000 ●...
16 Why OpenCV Uses Multi-threading to Process Video Frames ●The OpenCV function is based on the GitHub project flask-video-streaming, we changed the camera_opencv.py to perform OpenCV related operations. 16.1 Single Thread Processing of Video Frames ● First, we introduce the process of single-thread processing of video frames. Let ’s start with a simple one, so that you will understand why OpenCV uses multiple threads to process video frames.
make it abnormally stuck. 16.2 Multi-thread Processing of Video Frames ●Next, the process of multi-thread processing of video frames is introduced: ● Process explanation: In order to improve the frame rate, we separate the analysis task of the video frame from the process of acquisition and display, and place it in a background thread to execute and generate drawing information.
Page 108
import threading import imutils class CVThread(threading.Thread): This class is used to process OpenCV analysis of video frames in the background. For more basic usage principles of the multi-threaded class, please refer to 14.2 __init__(self, *args, **kwargs): self.CVThreading = super(CVThread, self).__init__(*args, **kwargs) self.__flag = threading.Event() self.__flag.clear() mode(self, imgInput):...
Page 109
self.CVThreading = resume(self): Resume the thread self.__flag.set() run(self): Process video frames in the background thread while self.__flag.wait() self.CVThreading = self.doOpenCV(self.imgCV) class Camera(BaseCamera): video_source = 0 __init__(self): os.environ.get('OPENCV_CAMERA_SOURCE'): Camera.set_video_source(int(os.environ['OPENCV_CAMERA_SOURCE'])) super(Camera, self).__init__() @staticmethod set_video_source(source): Camera.video_source = source @staticmethod frames(): camera = cv2.VideoCapture(Camera.video_source) if not camera.isOpened(): raise...
Page 110
img = camera.read() cvt.CVThreading: If OpenCV is processing video frames, skip pass else: If OpenCV is not processing video frames, give the video frame processing thread a new video frame and resume the processing thread cvt.mode(img) cvt.resume() Draw elements on the screen img = cvt.elementDraw(img) # encode as a jpeg image and return it yield...
17 OpenCV Learn to Use OpenCV ●The real-time video transmission function comes from the open source project of Github the MIT open source agreement flask-video-streaming. ●First, prepare two .py files in the same folder in the Raspberry Pi. The code is as follows: ·app.py #!/usr/bin/env python3 from...
Page 112
from thread import get_ident except ImportError: from _thread import get_ident class CameraEvent(object): """An Event-like class that signals all active clients when a new frame is available. """ __init__(self): self.events = {} wait(self): """Invoked from each client's thread to wait for the next frame.""" ident = get_ident() ident not in...
Page 113
"""Invoked from each client's thread after a frame was processed.""" self.events[get_ident()][0].clear() class BaseCamera(object): thread = None # background thread that reads frames from camera frame = None # current frame is stored here by background thread last_access = # time of last client access to the camera event = CameraEvent() __init__(self): """Start the background camera thread if it isn't running yet."""...
Page 114
frame frames_iterator: BaseCamera.frame = frame BaseCamera.event.set() # send signal to clients time.sleep(0) # if there hasn't been any clients asking for frames in # the last 10 seconds then stop the thread time.time() - BaseCamera.last_access > 10: frames_iterator.close() print('Stopping camera thread due to inactivity.') break BaseCamera.thread = None...
18 Using OpenCV to Realize Color Recognition and Tracking 18.1 Color Recognition and Color Space ●For the development preparation and operation of OpenCV function, please refer to 18. ●Create camera_opencv.py in the folder where app.py and base_camera.py in 18. The code related to the OpenCV color tracking function to be introduced in this chapter is written in camera_opencv.py ●For safety reasons, this routine does not control the motor or servo motion, and only outputs OpenCV calculation results.
general process is as follows 18.3 Specific Code ●camera_opencv.py import import from base_camera import BaseCamera import numpy...
Page 117
Set target color, HSV color space colorUpper = np.array([44, 255, 255]) colorLower = np.array([24, 100, 100]) font = cv2.FONT_HERSHEY_SIMPLEX class Camera(BaseCamera): video_source = 0 __init__(self): os.environ.get('OPENCV_CAMERA_SOURCE'): Camera.set_video_source(int(os.environ['OPENCV_CAMERA_SOURCE'])) super(Camera, self).__init__() @staticmethod set_video_source(source): Camera.video_source = source @staticmethod frames(): camera = cv2.VideoCapture(Camera.video_source) if not camera.isOpened(): raise RuntimeError('Could not start camera.')
Page 118
c = max(cnts, key=cv2.contourArea) ((box_x, box_y), radius) = cv2.minEnclosingCircle(c) M = cv2.moments(c) center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"])) X = int(box_x) Y = int(box_y) Get the center point coordinates of the target color object and output print('Target color object detected') print('X:%d'%X) print('Y:%d'%Y) print('-------')
18.4 HSV Color Component Range in OpenCV HSV\color Black Grey Orange Yellow Green Cyan Purple White Blue H_min 0|156 H_max 10|180 S_min S_max V_min V_max...
19 Machine Line Tracking Based on OpenCV 19.1 Visual Line Inspection Process ●For the development preparation and operation of OpenCV function, please refer to 18. ●Create camera_opencv.py in the folder where app.py and base_camera.py in 18, the code related to the OpenCV visual line tracking function to be introduced in this chapter is written in camera_opencv.py.
19.2 Specific Code import import from base_camera import BaseCamera import numpy import time import threading import imutils Set the color of the line, 255 is the white line, 0 is the black line lineColorSet = Set the horizontal position of the reference, the larger the value, the lower, but not greater than the vertical resolution of the video (default 480) linePos = class...
Page 122
Convert the picture to black and white, and then binarize (the value of each pixel in the picture is 255 except 0) img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) retval, img = cv2.threshold(img, 0, 255, cv2.THRESH_OTSU) img = cv2.erode(img, None, iterations=6) #Use Corrosion Denoising colorPos = img[linePos] #Get an array of pixel values for linePos try:...
●Under normal circumstances, if the robot program is not connected to the WIFI when it is turned on, it will automatically turn on the hotspot. You can use your phone or computer to search for the WIF named Adeept. The default password is 12345678. Once the connection is successful, you can log in to 192.168 .12.1: 5000 using a browser to open the WEB application to control the robot.
21 Install GUI Dependent Item under Window ● Our old version of robot programs all provide a desktop GUI program to control the robot. The GUI program is written in Python language, but this method uses a higher threshold and difficulty, and is not recommended for novices.
22 How to Use GUI ●Because the web and the GUI are not connected, if you want to use the GUI to control the robot product, you need to manually run server.py. (The method is the same as manually running webserver.py, except that the object is changed to server.py).
23 Enable UART ●UART is a more commonly used communication protocol between devices. Using UART, you can allow MCUs such as Arduino, STM32, or ESP32 to communicate with the Raspberry Pi, which can make your robot more powerful. ●However, for some Raspberry Pis, the UART that is enabled by default is not a full-featured UART, so you need to refer to the following steps to enable the full-featured UART.
23.1 Mini UART and CPU Core Frequency ●The baud rate of the mini UART is linked to the core frequency of the VPU on the VC4 GPU. This means that, as the VPU frequency governor varies the core frequency, the baud rate of the mini UART also changes. This makes the mini UART of limited use in the default state.
23.3 UART Output on GPIO Pins ●By default, the UART transmit and receive pins are on GPIO 14 and GPIO 15 respectively, which are pins 8 and 10 on the GPIO header. 23.4 UARTs and Device Tree ● Various UART Device Tree Overlay definitions can be found in the kernel github tree. The two most useful overlays are disable-bt miniuart-bt...
Page 129
●The mini UART has smaller FIFOs. Combined with the lack of flow control, this makes it more prone to losing characters at higher baudrates. It is also generally less capable than the PL011, mainly due to its baud rate link to the VPU clock speed. ●The particular deficiencies of the mini UART compared to the PL011 are : ·No break detection ·No framing errors detection...
24 Control Your Adeept_RaspClaws with An Android Device ●If you want to use a mobile phone or tablet to control the robot, we first recommend that you use the WEB application to control the robot, because the WEB application has more functions, maintenance and updates are more frequent, and most importantly, the WEB application can be cross-platform No matter whether you use Android system or iOS system, as long as Google Chrome is installed, you can use the WEB application to control the robot.
If you want to try our other products, you can visit our website: www.adeept.com For more product information, please visit: https://www.adeept.com/learn/ For more product latest video updates, please visit: https://www.adeept.com/video/ Thank you for using Adeept products.
Need help?
Do you have a question about the RaspClaws and is the answer not in the manual?
Questions and answers