background image

54 

 

you just adjusted  is turning forward. If the reversing works normally, click 

Run

 

again to stop the wheels from spinning. 

 

Turing Adjustment   

 

Currently the front wheels should be pointed at the exact front direction. But if it is 
not, you need to make some adjustments. In the Turning section in the Calibration 
window, click the left (

<==

) and right (

==>

) arrow buttons in the upper line to 

make  fine  adjustments,  and  those  in  the  lower  to  coarsely  adjust  the  turning 
direction. Keep adjusting until the wheels is oriented to the front exactly. Then you 
may place the car on the table and click 

Run

 to verify whether it runs in a straight 

line. If not, perform the adjustment again till it does.     

 

Mount Adjustment   

 

Now the pan servo on the car should be pointed at the exact front direction and the 
camera face up. But if not, you may need to adjust them similarly. In the Mount 
section, there are the adjustments for the pan servo and tilt one. Also you have two 
kinds of adjustments, fine and coarse. Keep adjusting until they are pointed at the 
right direction.   
After all the adjustments are done, click Confirm. Then the terminal on PC will print 
the contents of the file 

config

 after your adjustments. The calibration program will 

automatically  sends the 

config

 to the Raspberry Pi. You may need to enter your 

password.   

Summary of Contents for Smart Video Car Kit

Page 1: ...king something cool welcome to join us About This Kit The kit is suitable for the Raspberry Pi model B and Raspberry Pi 2 model B In this book we will show you how to build the smart car via description illustrations of physical components and schematic diagrams of circuits in both hardware and software respects You may visit our website www sunfounder com to download the user manual and also the ...

Page 2: ...dule Assembly 30 iii Circuit Connecting 31 Electrical Components Basics 41 i Raspberry Pi 41 ii Step down DC DC Converter Module 42 iii Servo 43 iv DC Motor Driver 44 v Servo Controller 45 vi USB Wi Fi Adaptor 45 Software Related 46 i Download and Install Raspbian on a TF Card 46 ii Get Source Code 46 iii Basic Software Environment 48 iv Calibration 51 v Program Analysis and Explanation 59 Summary...

Page 3: ...ogram is run on Raspberry Pi for direct control of the car And the video data are acquired and delivered via the open source software MJPG streamer in a real time manner The TCP client program is run on PC to send the control command Both the client and server programs are developed in Python language The smart car is developed based on the open source hardware Raspberry Pi and integrates the know...

Page 4: ...2 Components i Acrylic Plates ...

Page 5: ...self tapping screw 8 M2 10 screw 6 M2 5 6 screw 16 M3 10 countersunk screw 2 M3 8 screw 8 M3 12 screw 6 M3 30 screw 4 M4 25 screw 2 M2 5 8 copper pillar 16 M3 24 copper pillar 8 M2 nut 6 M2 5 nut 16 M3 nut 20 M4 self locking nut 2 F694ZZ flange bearing 2 ...

Page 6: ...4 ii Drive Parts Parts Name Quantity Tower Pro Micro Servo SG90 3 Gear reducer 2 Driven wheel 2 Active wheel 2 ...

Page 7: ...5 iii Electrical Components Parts Name Quantity Raspberry Pi Model B 1 16 Channel 12 bit PWM driver servo controller 1 L298N DC motor driver 1 ...

Page 8: ...6 Step down DC DC converter module 1 USB Wi Fi adapter 1 USB camera 1 18650 2 Battery holder 1 Ribbon 1 ...

Page 9: ...7 USB cable 1 Cross socket wrench 1 Cross screwdriver 1 20cm jumper wire F to F 4 10cm jumper wire F to F 5 10cm jumper wire M to F 2 20cm jumper wire M to M 2 ...

Page 10: ...8 iv Self provided Parts The following parts are not included in the set Parts Name Qty Needed 18650 3 7V rechargeable Li ion battery 2 TF Card 1 ...

Page 11: ... following acrylic plates with an M4 25 screw and an M4 self locking nut in the way as shown below b When completed the assembly should look like the figure below c Bear in mind that DO NOT over tighten the nut or else the wheel cannot turn flexibly Neither too loose in case the gap between the parts is too large ...

Page 12: ...h an M4 25 screw and an M4 self locking nut in the way shown as below b When completed the assembly should look like the figure below c Bear in mind that DO NOT over tighten the nut or else the wheel cannot turn flexibly Neither too loose in case the gap between the parts is too large ...

Page 13: ...aces as shown in the following figure Back Half Chassis Rear Wheels a Assemble the following two acrylic plates b When completed the assembly should look like the figure below c Assemble the gear reducer the active wheel and following acrylic plates with two M3 30 screws and M3 nuts ...

Page 14: ...k like the figure below a Assemble the following two acrylic plates b When completed the assembly should look like the figure below c Assemble the gear reducer the active wheel and the previously assembled part with two M3 30 screws and M3 nuts ...

Page 15: ...mbly should look like the figure below Back Half Chassis Copper Standoffs a Assemble 4 M3 24 copper standoffs and 4 M3 nuts into the acrylic plate part as shown below b When completed the assembly should look like the figure below ...

Page 16: ... from the servo freely as shown in the following figure b Turn the rocker arm within an angle of about 180 degrees c The rocker arm is placed in a random way at the beginning You need to adjust it to restrict its turning in an almost equal angle towards right and left ...

Page 17: ...p until the condition is met It matters to the subsequent installation d After the adjustment turn the rocker arm to the middle and remove it Note Make sure the step is carried out for all servos and that the axis of the servos is not moved accidentally in the subsequent installation If the axes are moved adjust them again before the installation ...

Page 18: ...h an M2 8 self tapping screw The M2 8 self tapping screw is contained in the package of the servo it is one of the two longest screws Also the rocker arm is packaged together with the servo b When completed the assembly should look like the figure below Be careful not to tighten the screw too much Keep a gap of about 1mm between the two ...

Page 19: ...M2 nuts Pay attention to the face of the plate Refer to the small hole in the plate as pointed by the arrow in the following figure b When completed the assembly should look like the figure below Note The servo should be placed with its output shaft toward the front of the plate see the following figure ...

Page 20: ...e of the servo it is the shortest of the screws in the package b When completed the assembly should look like the figure below Pay attention to the orientation during the assembly If you find any error in the assembly do not try to turn the axis of the servo instead you should disassemble it and then assemble the parts again ...

Page 21: ...19 Front Chassis Upper Plate a Connect the following parts and wheels with M3 8 screws M3 24 copper standoffs and M3 nuts 4 for each b When completed the assembly should look like the figure below ...

Page 22: ...te Copper Standoffs a Assemble 16 M2 5 8 copper standoffs and 16 M2 5 nuts into the acrylic plate as shown below b When completed the assembly should look like the figure below c The view from the back of the plate ...

Page 23: ...21 Back Chassis Upper Plate a Connect the two assembled parts with 4 M3 8 screws b When completed the assembly should look like the figure below c The view from the back of the plate ...

Page 24: ...10 countersunk screws and 2 M3 nuts You can thread a ribbon through the plate below so it will be easy to remove the battery which is up to you b When completed the assembly should look like the figure below c The view from the top is as follows Now the car assembly is completed ...

Page 25: ... screws The rocker arm is packaged together with the servo b When completed the assembly should be like the figure below a Connect the rocker arm of the servo to the acrylic plate below with four M1 2 5 screws The rocker arm is packaged together with the servo b When completed the assembly should be like the figure below ...

Page 26: ...screws and M2 nuts and we name it pan servo b When completed the assembly should look like the figure below a Connect the servo to the acrylic plate below with two M2 10 screws and M2 nuts and we name it tilt servo b When completed the assembly should look like the figure below ...

Page 27: ...rews and M3 nuts The two plates should be perpendicular to each other b When completed the assembly should look like the figure below a Connect the two parts at a right angle with two M3 12 screws and M3 nuts b When completed the assembly should look like the figure below ...

Page 28: ...26 Servo Rocker Arm a Connect the following parts without any screws b When completed the assembly should look like the figure below Top view Front view ...

Page 29: ...0 degrees left to right the tilt servo should rotate also 0 to 180 degrees front to back Pay attention to the orientation during the assembly If you find any error in the course do not try to turn the axis of the servo instead you should disassemble it and then assemble the parts again c Then fasten them with an M2 4 screw The M2 4 screw is contained in the package of the servo and is the shortest...

Page 30: ...28 3 Mount Car a Assemble the mount part and the car with two M3 12 screws and M3 nuts b When completed the assembly should look like the figure below ...

Page 31: ...mount part right and left to see if its turning works normally turning precisely left to right or vice versa 3 Turn the tilt servo front to back and see if it is able to turn from precisely front to back or vice versa If any of the three servos fails to meet the condition disassemble it and adjust based on Servo Adjustment on Page 14 Please DO follow the instructions to adjust the servos or else t...

Page 32: ...30 ii Electrical Module Assembly Assemble the electrical components to the car with M2 5 6 screws See the figure below ...

Page 33: ...31 iii Circuit Connecting Preview This is how it looks when all wiring is done Looks complicated but don t worry The detailed procedures will be given below step by step ...

Page 34: ...d PCB connector and plug it back after wiring Note It doesn t matter how to wire the motors After all the assembly is done if the car moves in an opposite direction of what you control just swap the wiring of the two motors and it will work normally After wiring it should be like this ...

Page 35: ...33 Step 2 Connect the motor driver with the Raspberry Pi GPIO port based on the following table Raspberry Pi GPIO Port DC Motor Driver Pin11 IN1 Pin12 IN2 Pin13 IN3 Pin15 IN4 ...

Page 36: ...34 Step 3 Connect the servo controller with the Raspberry Pi GPIO port as follows Raspberry Pi GPIO Port Servo Controller Pin2 5V VCC Pin3 SDA SDA Pin5 SCL SCL ...

Page 37: ...rvo that controls the car s direction to CH0 of the servo controller and the two servos that control the view of the camera to CH14 and CH15 respectively as shown below Step 5 Connect the motor driver with the servo controller ...

Page 38: ...tep 6 Connect the servo controller with the step down DC DC converter module For the connector loosen the screws insert the wire and then tighten the screws with a screwdriver The connection should be like ...

Page 39: ...37 Step 7 Connect the battery holder with the step down DC DC converter module and the DC motor driver Insert the four wires into two jacks of the connector two in each ...

Page 40: ...38 The whole picture of wiring should be like this ...

Page 41: ...39 Step 8 Connect the Raspberry Pi with the step down DC DC converter module the USB Wi Fi adapter and the USB camera ...

Page 42: ...40 Now the circuit is completed Congratulations The car should be assembled successfully as shown below ...

Page 43: ...to do from browsing the internet and playing high definition video to making spreadsheets doing word processing and playing games What s more the Raspberry Pi has the ability to interact with the outside world and has been used in a wide array of digital maker projects from music machines and parent detectors to weather stations and tweeting birdhouses with infra red cameras In this kit we use Ras...

Page 44: ...tput of 7 4V to 5V so as to supply power to Raspberry Pi and the servo As a DC to DC converter IC the chip has an input voltage ranging from 4 5V to 40V and generates an output voltage of 5V with a current of as high as 2A Please note only when the input voltage is up to 6 5V a 5V output can be supported ...

Page 45: ... defines the rotation angle of the output shaft via delivering specific PWM signals Generally a servo supports a maximum rotation angle of the shaft like 180 degrees It differs from a common DC motor in the rotation mode a DC motor rotates by circle when a servo rotates in a certain degree and does not rotate in a round circle Also the former is used for power supply by its whole circle rotation w...

Page 46: ... on L298N As a high voltage and large current chip for motor driving encapsulated with 15 pins the chip has a maximum operating voltage of 46V and an instant peak current of as high as 3A with an operating current of 2A and rated power of 25W Thus it is completely capable of driving two low power DC motors ...

Page 47: ...cy between 40Hz and 1000Hz and its duty cycle can be adjusted in a range of 0 to 100 It provides PWM signals for the servo and controls the rotation angle of the servo Meanwhile the module controls the duty cycle of the square waves output from channel 14 and 15 to regulate the rotational speed of the DC motor so as to control the speed of the car vi USB Wi Fi Adaptor The adapter helps Raspberry P...

Page 48: ...berryPi git Or If your Raspberry Pi is not connected to the Internet download the file Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi tar gz on our website For Linux Unplug the TF card and connect it with the computer with a card reader Then copy the file Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi tar gz to the directory home pi For Windows Since files in EXT2 3 4 format of Linux cannot be rea...

Page 49: ...t get you may go t o the link to download https github com sunfounder Sunfounder_Smart_Vid eo_Car_Kit_for_RaspberryPi or search for Sunfounder in Github and find Sunf ounder_Smart_Video_Car_Kit_for_RaspberryPi Repository Click Download ZIP on the right side of the page as below After download right click the file and click Extract here Or unzip it by command unzip Sunfounder_Smart_Video_Car_Kit_fo...

Page 50: ... apt get install python smbus Setup I2C port Comment out the i2c bcm2708 line from the raspi blacklist conf file sudo nano etc modprobe d raspi blacklist conf Add code below blacklist i2c bcm2708 Open etc modules sudo nano etc modules And add this line to the end of the file i2c dev From the prompt run sudo modprobe i2c_bcm2708 sudo modprobe i2c dev Check that the i2c modules are loaded and active...

Page 51: ...JPEG data allowing fast and performant M JPEG streams even from an embedded device running OpenWRT The input module input_uvc so captures such JPG frames from a connected webcam Installation Plug the USB camera into Raspberry Pi and run the command lsusb The Microdia represents the USB camera since it is printed on the screen it indicates the system has recognized the camera Check whether the driv...

Page 52: ...ype in the following address replace 192 168 0 xxx with your Raspberry Pi IP address at the address bar of your browser Firefox is recommended http 192 168 0 xxx 8080 stream html Press Enter and you will see the view captured by the camera displayed on the screen in a real time manner ...

Page 53: ...pberryPi server run the server cali_server py cd Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi server sudo python cali_server py Then the contents of config are printed and the last line Waiting for connection At this time the car might move a bit this is the original position set For Client Open another terminal Find the sketch downloaded and edit client cali_client py cd client sudo nano cali_c...

Page 54: ... to enter the password of the Raspberry Pi here since you want to obtain the configuration file on it Then a line appears as follows indicating the config file is obtained successfully And a window Raspberry Pi Smart Video Car Calibration pops up In the terminal remotely connected with the Raspberry Pi the IP address of the PC will be printed ...

Page 55: ...no matter what directions the pan servo is pointed at If not you may adjust the directions in Raspberry Pi Smart Video Car Calibration Start Calibration On the calibration UI there are three sections Motor Turning and Mount Motor Adjustment Click Run The car will walk forward Check whether both the back wheels move forward together If either fails to do so your wiring may be wrong But don t worry ...

Page 56: ... the car on the table and click Run to verify whether it runs in a straight line If not perform the adjustment again till it does Mount Adjustment Now the pan servo on the car should be pointed at the exact front direction and the camera face up But if not you may need to adjust them similarly In the Mount section there are the adjustments for the pan servo and tilt one Also you have two kinds of ...

Page 57: ...run the car here we name it Terminal 1 Terminal 2 Terminal 3 Terminal 1 is to open tcp_server py on the Raspberry Pi as a server Terminal 2 is to run web camera server on it and Terminal 3 is to open client_App py on PC as a client to remote In Terminal 1 The Raspberry Pi may be still at the server directory If not go to the directory with cd and run tcp_server py sudo python tcp_server py The ser...

Page 58: ...berry Pi remotely and switch to the directory under which the program of MJPG streamer lies cd Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi mjpg strea mer mjpg streamer Run the program sudo sh start sh Then the video data acquisition will start like this ...

Page 59: ...ss Enter and you will see the view captured by the camera displayed on the screen in a real time manner Open the last terminal Terminal 3 Go to client with cd and edit the file client py Similar to the change in calibration change the IP address in the client program in your PC After the alteration press Ctrl O and save and Ctrl X to exit Then run the client program sudo python client_app py ...

Page 60: ...gram must be run before you run the client program Some settings must be completed for the server before the service is done A communication endpoint needs to be created for the server to listen to requests from the client Take the server as a receptionist or an operator of the bus phone in a company Once the phone and device installation is completed and the receptionist or operator is in place t...

Page 61: ...ser interface GUI to conveniently control the Raspberry Pi remotely Both the client and server programs are written in Python Make sure that the circuit is connected properly Power the smart car log in t he Raspberry Pi remotely go to the directory Sunfounder_Smart_Video_Car_K it_for_RaspberryPi and check the files under it cd Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi ls You can see four file...

Page 62: ...er design After you have a good knowledge about it you can alter the pseudocode as you want s socket Create a socket for the server s bind Bind the address to the socket s listen Listen to the connection inf_loop Indefinite loop of the server c s accept Accept the connection from the client comm_loop Communication loop c recv c send Dialog receiving or sending data c close Close the socket of the ...

Page 63: ...ient socket c connect Try to connect a server comm_loop Communication loop c send c recv Dialog sending out and receiving data c close Close the client socket As mentioned above all sockets are created via the function socket socket Then the function connect can be called to connect the server After the connection is built the dialog between the client and the server is enabled When the dialog end...

Page 64: ...ogram c Create the GUI module needed on the object and enable the functions d Connect the GUI modules with the code at the system back end e Enter the main event loop Take a simple GUI program Create a file Tk_test py under the path home touch Tk_test py Add executable privilege to the file chmod x Tk_test py Open the file vim Tk_test py Type in the following code usr bin env python from Tkinter i...

Page 65: ...63 Process Diagram of Client Program ...

Page 66: ...arts like the servo Wi Fi adapter etc Also you ve learnt a lot of software and coding which lays a solid foundation for your future journey of exploring open source field The SunFounder Smart Video Car for Raspberry Pi is not only a toy but more a meaningful development kit for Raspberry Pi After all the study and hands on practice of the kit you should have a better understanding of Raspberry Pi ...

Reviews: