EasyManua.ls Logo

Freenove 4WD Smart Car Board for Raspberry Pi - Page 68

Default Icon
132 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Need support? support.freenove.com
64
Chapter 3 Module test (necessary)
The code is as below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from Motor import *
PWM=Motor()
def test_Motor():
try:
PWM.setMotorModel(1000,1000,1000,1000) #Forward
print "The car is moving forward"
time.sleep(1)
PWM.setMotorModel(-1000,-1000,-1000,-1000) #Back
print "The car is going backwards"
time.sleep(1)
PWM.setMotorModel(-1500,-1500,2000,2000) #Left
print "The car is turning left"
time.sleep(1)
PWM.setMotorModel(2000,2000,-1500,-1500) #Right
print "The car is turning right"
time.sleep(1)
PWM.setMotorModel(0,0,0,0) #Stop
print "\nEnd of program"
except KeyboardInterrupt:
PWM.setMotorModel(0,0,0,0)
print "\nEnd of program"
Reference
setMotorModel(data1,data2,data3,data4)
This function has four input parameters that control the left front motor, the left rear motor, the right front
motor, and the right rear motor. When the input parameter is within 0~4096, the motor will rotate forward.
If it is within -4096~0, the motor will rotate reversely. The larger the absolute value is, the faster the motor
is. When the input is 0, the motor will stop. If the function is input as follows: setMotorModel(2000,2000,
2000, 2000), four motors will rotate forward and the car will move forward.
Data1
Data2
Data3
Data4