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: tutorials/basic_motor_control.md
+21-22Lines changed: 21 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,8 +10,7 @@ The aim of this tutorial is to get a motor turning with your kit.
10
10
To complete this tutorial, you'll need the following:
11
11
12
12
* The [power board](/docs/kit/power_board)
13
-
* The battery (charged, of course)
14
-
* The cable to connect the battery to the power board
13
+
* A battery (charged, of course)
15
14
* A [motor board](/docs/kit/motor_board)
16
15
* 2 large (7.5mm) green _CamCon_ connectors to plug the power board and motor board together
17
16
* 2 lengths of a suitable gauge of wire for powering the motor board from the power board (one should be black/grey)
@@ -42,9 +41,9 @@ The criteria are as follows:
42
41
43
42
<divclass="info">
44
43
When designing your robot you should bear in mind that while each motor board can deliver 10A on each output,
45
-
all the power needs to go through the power board, which is fused at 15A.
46
-
This means that across all the outputs for all the motors,
47
-
you can only draw up to 15A at any time.
44
+
all the power needs to go through the power board, which is limited to 30A overall.
45
+
This means that across all the outputs for all the motors (as well as the rest of your kit),
46
+
you can only draw up to 30A at any time.
48
47
</div>
49
48
50
49
Connecting a Motor
@@ -128,7 +127,7 @@ while True:
128
127
~~~~~
129
128
130
129
You're familiar with the first few lines; in fact, the only lines you may not be familiar with are the `R.motor_board...` lines.
131
-
For a comprehensive reference to the `motor` object, see the `sr.robot3` module's [`motor`](/docs/programming/sr/motors/) page.
130
+
For a comprehensive reference to the `motor` object, see the `sr.robot3` module's [Motors](/docs/programming/sr/motors/) page.
132
131
But, to summarise:
133
132
134
133
<divclass="info"markdown="1">
@@ -140,6 +139,7 @@ But, to summarise:
140
139
141
140
So, `R.motor_board.motors[0].power = 0.5` sets the target power of the motor connected to output 0 on the first [motor board](/docs/kit/motor_board)
142
141
plugged in to a USB hub to 50% forwards (i.e. a duty-cycle of 0.5 forwards).
142
+
143
143
As you would expect, then, `R.motor_board.motors[0].power = -0.5` will put the this motor into reverse at 50% power.
144
144
`R.motor_board.motors[0].power = 0` will output no power to the motor and stop it.
145
145
@@ -214,16 +214,18 @@ while True:
214
214
215
215
Again, as you've seen most of that before, it shouldn't be too difficult to get your head around.
216
216
The `for` loop may be new, however.
217
+
217
218
The [`for`](https://docs.python.org/tutorial/controlflow.html#for-statements)
218
-
loop accepts a Python `list` (a `list`, when `print`ed, appears in square brackets like so: `[1, 2, 3]`).
219
+
loop accepts anything that Python can iterate over to get multiple values, such as a `list` (a `list`, when `print`ed, appears in square brackets like so: `[1, 2, 3]`).
220
+
219
221
For a comprehensive introduction to to `list`s, have a look at [this WikiBooks article](https://en.wikibooks.org/wiki/Python_Programming/Lists).
220
222
The `for` loop will iterate over the `list` (i.e. take each element in turn)
221
223
and make it available in the loop's body as the variable after the the `for` keyword.
222
224
Here's an example:
223
225
224
226
~~~~~python
225
227
for i in [1, 2, 3]:
226
-
print(i)
228
+
print(i)
227
229
~~~~~
228
230
229
231
The above would output:
@@ -234,25 +236,22 @@ The above would output:
234
236
3
235
237
~~~~~
236
238
237
-
Then there's the [`range()`](https://docs.python.org/library/functions.html#range) function.
238
-
The `range()` function returns a `list` with its contents dependent on the arguments passed to it.
239
-
The Python documentation explains it quite nicely:
239
+
Then there's the [`range()`](https://docs.python.org/3/library/stdtypes.html#typesseq-range) object.
240
+
241
+
`range()` objects represent a sequence of numbers. They can be constructed with
242
+
one, two or three arguments to describe what the sequence of numbers should be.
240
243
241
-
> `range([start], stop[, step])` (note: the square brackets here mean 'optional')
242
-
>
243
-
> If the `step` argument is omitted, it defaults to `1`. If the `start` argument is
244
-
> omitted, it defaults to `0`. The full form returns a list of plain integers
245
-
> `[start, start + step, start + 2 * step, ...]`. If `step` is positive, the last
246
-
> element is the largest `start + i * step` less than `stop`; if `step` is negative,
247
-
> the last element is the smallest `start + i * step` greater than `stop`.
244
+
If only one argument is provided then the sequence starts at `0` and stops just
245
+
before the given number. Otherwise the first argument is the number to start at,
246
+
the second argument is the number to stop before and the (optional) third
247
+
argument is how big the steps should be (by default steps are `1`).
248
248
249
-
So, based on that, `range(3)` would return the list `[0, 1, 2]` because it is shorthand for `range(0, 3, 1)`.
250
-
From the quote, you can see that this would return a list starting from `0`,
251
-
and finishing with the integer one less than `3`, hence the `[0, 1, 2]`.
249
+
So, based on this, `range(3)` would represent the sequence `0`, `1`, `2` because
250
+
it is shorthand for `range(0, 3, 1)`.
252
251
253
252
So, taking `range(10, 80, 10)`, for example, would output `10` as the first element,
254
253
then `20, 30, ...` up until `x=10+i*10` for some `i` where `i` ensures `x < stop` (which, in this case, is `80`).
255
-
So, the `80`I've used could equally have been `77` or even `71` and the outputted `list` would still be `[10, 20, 30, 40, 50, 60, 70]`.
254
+
So, the `80`we've used could equally have been `77` or even `71` and the outputted sequence would still be `10`, `20`, `30`, `40`, `50`, `60`, `70`.
256
255
257
256
Putting all of that together should mean you understand the above code.
258
257
You might want to run the code on your kit to see if it does what you expect it to.
0 commit comments