You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-13Lines changed: 44 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# DFRobot-Maqueenplus-Python
2
2
3
-
Python library for maqueenplus robot developed by DFRobot.
3
+
Python library for the Maqueen Plus robot developed by DFRobot.
4
4
5
5
This library is a python version of the one proposed by DFRobot used for block coding.
6
6
@@ -26,10 +26,10 @@ mq = mqn.MaqueenPlus()
26
26
27
27
### Move the robot
28
28
Move the robot along 4 axis :
29
-
* F -> forward
30
-
* B -> backward
31
-
* L -> left
32
-
* R -> right
29
+
- F -> forward
30
+
- B -> backward
31
+
- L -> left
32
+
- R -> right
33
33
34
34
Function definition :
35
35
```python
@@ -65,6 +65,32 @@ Example :
65
65
mq.motorControl(mq.MT_R,2,70)
66
66
```
67
67
68
+
### Move the robot for a precise distance
69
+
MaqueenPlus is equipped with wheel encoders. The function goto uses the wheel encoders to turn or move the robot over an exact number of encoder ticks:
70
+
- F -> drive a number of encoder ticks forward
71
+
- L -> turn left for a number of encoder ticks
72
+
- R -> turn right for a number of encoder ticks
73
+
74
+
Function definition :
75
+
```python
76
+
defgoto(self, dir, spd, dist):
77
+
"""
78
+
mot left: MT_L ; mot right: MT_R
79
+
dir(string) : "F" or "L" or "R"
80
+
spd max: 255; stop: 0
81
+
dist: the number of encoder ticks the robot should move
82
+
"""
83
+
```
84
+
85
+
Example :
86
+
```python
87
+
# drive forward with PWM speed 200 for 400 encoder ticks
88
+
mq.goto("F", 200, 400)
89
+
90
+
# turn left with PWM speed 70 for 144 ticks (about 180 degrees)
91
+
mq.goto("L", 70, 144)
92
+
```
93
+
68
94
### Stop
69
95
Stop the robot
70
96
@@ -127,30 +153,35 @@ Example:
127
153
```
128
154
129
155
### Ultrasonic sensor
130
-
Get the distance between the robot and an object.
156
+
Get the distance between the robot and an object. An optional argument maxDist was added so you can choose the range of the sensor, which can be important to limit delays in your program. The default setting is 0.4 meters.
131
157
132
158
Function definition:
133
159
```python
134
-
defultrasonic(self):
160
+
defultrasonic(self,maxDist=0.4):
135
161
"""Get the distance between the robot and an object.
136
162
163
+
Args:
164
+
[float, optional] The maximum distance in meters
165
+
If function is called with no arguments, defaults to 0.4
166
+
137
167
Returns:
138
-
[float]: distance to the object if one is detected else max value.
168
+
[float]: distance to the object if one is detected, else max value.
139
169
"""
140
170
```
141
171
142
172
Example:
143
173
144
174
```python
145
175
distance = mq.ultrasonic()
176
+
distance = mq.ultrasonic(0.8)
146
177
```
147
178
148
179
### Motor Speed
149
180
Get the linear speed of a given motor.
150
181
INFO : This method has no been tested yet but you can test it and set an issue for feedback.
151
182
152
183
153
-
Function defition:
184
+
Function definition:
154
185
```python
155
186
defmotorSpeed(self, mot):
156
187
"""Get the linear speed of a given motor
@@ -175,7 +206,7 @@ Example:
175
206
```
176
207
177
208
### RGB Lights
178
-
Turn on/off the rbg light of your choice with the color you want.
209
+
Turn on/off the rgb light of your choice with the color you want.
179
210
180
211
* RGB LED choice:
181
212
RGB_L : left led,
@@ -252,6 +283,6 @@ Example:
252
283
mq.clearEncoders()
253
284
```
254
285
255
-
256
-
# Updates
257
-
One major update that should be added soon concerns the rotation movements of the robot. In fact, when we ask the robot to move right of left no information is given concerning the angle to rotate. Only time.sleep(_) is used actually which is not accurate.
286
+
### Version history
287
+
- Version 1.0: Initial version
288
+
- Version 2.0: Compacted code style (short variable names, delete unnecessary space characters) to work around memory constraints and find space for adding functionality. Added goto function for moving the robot with use of the decoders. Added optional maximum distance argument to the ultrasonic function. Should still work with the micro:bit V1. if more functions to this library are added, you will probably need to equip your Maqueen Plus with the micro:bit V2. I am considering making a separate version of this library for the micro:bit V2
0 commit comments