Skip to content

Commit 703d766

Browse files
authored
Documented goto and ultrasonic function
1 parent eb8e6b0 commit 703d766

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

README.md

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# DFRobot-Maqueenplus-Python
22

3-
Python library for maqueenplus robot developed by DFRobot.
3+
Python library for the Maqueen Plus robot developed by DFRobot.
44

55
This library is a python version of the one proposed by DFRobot used for block coding.
66

@@ -26,10 +26,10 @@ mq = mqn.MaqueenPlus()
2626

2727
### Move the robot
2828
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
3333

3434
Function definition :
3535
```python
@@ -65,6 +65,32 @@ Example :
6565
mq.motorControl(mq.MT_R,2,70)
6666
```
6767

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+
def goto(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+
6894
### Stop
6995
Stop the robot
7096

@@ -127,30 +153,35 @@ Example:
127153
```
128154

129155
### 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.
131157

132158
Function definition:
133159
```python
134-
def ultrasonic(self):
160+
def ultrasonic(self,maxDist=0.4):
135161
"""Get the distance between the robot and an object.
136162
163+
Args:
164+
[float, optional] The maximum distance in meters
165+
If function is called with no arguments, defaults to 0.4
166+
137167
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.
139169
"""
140170
```
141171

142172
Example:
143173

144174
```python
145175
distance = mq.ultrasonic()
176+
distance = mq.ultrasonic(0.8)
146177
```
147178

148179
### Motor Speed
149180
Get the linear speed of a given motor.
150181
INFO : This method has no been tested yet but you can test it and set an issue for feedback.
151182

152183

153-
Function defition:
184+
Function definition:
154185
```python
155186
def motorSpeed(self, mot):
156187
"""Get the linear speed of a given motor
@@ -175,7 +206,7 @@ Example:
175206
```
176207

177208
### 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.
179210

180211
* RGB LED choice:
181212
RGB_L : left led,
@@ -252,6 +283,6 @@ Example:
252283
mq.clearEncoders()
253284
```
254285

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

Comments
 (0)