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: docs/tutorials/basic-movement.md
+9-13Lines changed: 9 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,13 @@
1
-
---
2
-
title: Basic Movement
3
-
---
1
+
# Basic movement
4
2
5
3
The example program we'll write will do a number of things with the motor: forwards and backwards, and different power settings, for example. Let's begin. To start off, we'll just make a motor move forwards, then backwards, and then repeat.
6
4
7
-
###Forwards & backwards
5
+
## Forwards & backwards
8
6
9
7
Doing this is actually very easy; the only thing you need to realise is that a positive number is forwards and a negative number is backwards.
10
8
11
-
{{% notice warning %}}
12
-
The actual direction of travel of a motor, when mounted on a robot, will depend on its orientation and the way in which the wires are connected to the motor board. If the motor appears to be going in the wrong direction, just swap the motor's positive and negative wires over.
13
-
{{% /notice %}}
9
+
!!! tip
10
+
The actual direction of travel of a motor, when mounted on a robot, will depend on its orientation and the way in which the wires are connected to the motor board. If the motor appears to be going in the wrong direction, just swap the motor's positive and negative wires over.
14
11
15
12
Here's the code:
16
13
@@ -37,19 +34,18 @@ while True:
37
34
r.sleep(4)
38
35
```
39
36
40
-
You're familiar with the first few lines; in fact, the only lines you may not be familiar with are the `r.motor_boards...` lines. For a comprehensive reference to the `motor` object, see [`motor` API](/api/motor-board) page.
37
+
You're familiar with the first few lines; in fact, the only lines you may not be familiar with are the `r.motor_boards...` lines. For a comprehensive reference to the `motor` object, see [`motor` API](../api/motor-board.md) page.
41
38
But, to summarise:
42
39
43
-
`r.motor_boards.m0.power = 0.5` sets the target power of the motor connected to output 0 on the first [motor board](/kit/motor-board) to half speed forwards (i.e. a duty-cycle of 0.5 forwards). As you would expect, then, `-0.5` will put the this motor into reverse at half power.
40
+
`r.motor_boards.m0.power = 0.5` sets the target power of the motor connected to output 0 on the first [motor board](../kit/motor-board.md) to half speed forwards (i.e. a duty-cycle of 0.5 forwards). As you would expect, then, `-0.5` will put the this motor into reverse at half power.
44
41
`r.motor_boards.m0.power = 0` will brake the motor and stop it.
45
42
46
43
So, if you put the above code on your robot, you should be able to see a motor spin forwards, stop, spin backwards, stop, and then repeat...
47
44
48
-
{{% notice note %}}
49
-
If you find that the motor doesn't turn when you run the above code, check that you've got all the cables connected to the right places, in particular note that the motor board has _two_ outputs.
50
-
{{% /notice %}}
45
+
!!! info
46
+
If you find that the motor doesn't turn when you run the above code, check that you've got all the cables connected to the right places, in particular note that the motor board has _two_ outputs.
51
47
52
-
###Changing the speed
48
+
## Changing the speed
53
49
54
50
Now we're going to modify the program to vary the speed of the motor. Our aim is to do the forwards and backwards bit (as above), but, before we loop round again, ramp the power up to 70%, then down to -70%, and then back to 0 (all in steps of 10%). Here's the code:
0 commit comments