-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdemo_dual_motor.spin2
148 lines (114 loc) · 5.21 KB
/
demo_dual_motor.spin2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
'' =================================================================================================
''
'' File....... demo_dual_motor.spin2
'' Purpose.... Demonstrate driving a two-wheeled platform
'' Authors.... Stephen M Moraco
'' -- Copyright (c) 2022 Iron Sheep Productions, LLC
'' -- see below for terms of use
'' E-mail..... [email protected]
'' Started.... Feb 2022
'' Updated.... 9 Feb 2022
''
'' =================================================================================================
CON { timing }
CLK_FREQ = 270_000_000 ' system freq as a constant
_clkfreq = CLK_FREQ ' set system clock
CON { fixed io pins }
RX1 = 63 { I } ' programming / debug
TX1 = 62 { O }
SF_CS = 61 { O } ' serial flash
SF_SCK = 60 { O }
SF_SDO = 59 { O }
SF_SDI = 58 { I }
OBJ { our Drive Subsystem }
user : "isp_bldc_motor_userconfig" ' driver configuration
wheels : "isp_steering_2wheel" ' the dual-drive BLDC motors
PUB main() | basePinLt, basePinRt, voltage, motor, detectModeLt, detectModeRt
'' DEMO Driving a two wheeled platform
debug("* dual motor demo")
' validate user settings/choicess
' do NOT start motor unless all are legit!
basePinLt := wheels.validBasePinForChoice(user.LEFT_MOTOR_BASE)
basePinRt := wheels.validBasePinForChoice(user.RIGHT_MOTOR_BASE)
detectModeLt := wheels.validDetectModeForChoice(user.LEFT_BOARD_TYPE)
detectModeRt := wheels.validDetectModeForChoice(user.RIGHT_BOARD_TYPE)
voltage := wheels.validVoltageForChoice(user.DRIVE_VOLTAGE)
motor := wheels.validMotorForChoice(user.MOTOR_TYPE)
if basePinLt <> wheels.INVALID_PIN_BASE and basePinRt <> wheels.INVALID_PIN_BASE and voltage <> wheels.INVALID_VOLTAGE and motor <> wheels.INVALID_MOTOR and detectModeLt <> wheels.INVALID_DET_MODE and detectModeRt <> wheels.INVALID_DET_MODE
' start our dual motor driver
' start our motor drivers (left and right)
wheels.start(basePinLt, basePinRt, voltage, detectModeLt, detectModeRt)
' just don't draw current at stop
wheels.holdAtStop(false)
'wheels.setMaxSpeed(100) ' override 75% with 100%
' now drive!
waitUntilMotorReady()
debug("* BOTH Wheels")
wheels.driveDirection(80, -25)
wheels.stopAfterTime(15, wheels.DTU_SEC) ' hold at speed for 15 Sec
waitUntilMotorDone()
wheels.driveDirection(80, 25)
wheels.stopAfterTime(15, wheels.DTU_SEC) ' hold at speed for 15 Sec
waitUntilMotorDone()
'{
debug("* LT Wheel")
wheels.driveAtPower(100, 0)
wheels.stopAfterTime(15, wheels.DTU_SEC) ' hold at speed for 15 Sec
waitUntilMotorDone()
debug("* RT Wheel")
wheels.driveAtPower(0, 100)
wheels.stopAfterTime(15, wheels.DTU_SEC) ' hold at speed for 15 Sec
waitUntilMotorDone()
'}
' turn off our motor drivers
wheels.stop()
else
debug("* ERROR user configuration NOT valid!")
debug("* DONE")
PRI waitUntilMotorReady()
if wheels.isReady() == false
debug("* wait motors ready...")
repeat
if wheels.isReady()
quit
else
waitms(2)
debug("* Motors ready, let's drive!")
PRI waitUntilMotorDone()
if wheels.isStarting() == false
debug("* wait until motors start...")
repeat
if wheels.isStarting()
quit
else
waitms(2)
if wheels.isStopped() == false
debug("* wait until motors finish...")
repeat
if wheels.isStopped()
quit
else
waitms(2)
debug("* Motors stopped!")
CON { license }
{{
-------------------------------------------------------------------------------------------------
MIT License
Copyright (c) 2022 Iron Sheep Productions, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=================================================================================================
}}