Skip to content

Commit 9453f6f

Browse files
authored
Merge branch 'master' into dgt/sr2022-servo-board
2 parents 6aed762 + be25f03 commit 9453f6f

File tree

11 files changed

+199
-243
lines changed

11 files changed

+199
-243
lines changed

_sass/docs.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@
9696
float: right;
9797
margin-left: 10px;
9898
}
99+
100+
&.half {
101+
max-width: 50%;
102+
}
99103
}
100104

101105
iframe.video {

images/content/marker-0.png

-943 Bytes
Binary file not shown.

images/content/vision/marker-0.png

1.64 KB
Loading

images/content/vision/spherical.png

41.2 KB
Loading
29.2 KB
Loading

programming/sr/motors/index.md

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,72 +6,72 @@ title: Motors
66
Motors
77
======
88

9-
The `motors` object is used to control a collection of Motor Boards.
10-
Similar to `ruggeduinos` and `servos`, `motors` can be used like a list.
11-
To do something with the **first Motor Board**, you would use:
9+
The `motor_board` object is used to control a collection of Motor Boards.
10+
11+
When a single Motor Board is connected to your robot, you can control it
12+
using the `motor_board` object.
1213

1314
~~~~~ python
14-
R.motors[0].something...
15+
R.motor_board.something...
1516
~~~~~
1617

17-
...because indexes are 0-based (counting starts from 0, not 1).
18-
19-
When you have more than one Motor Board connected to your kit they will be ordered based upon their SR Part Code, as written on the underside of the board.
20-
21-
The SR Part Code of each detected Motor Board is also printed to the log when your robot starts.
18+
The serial number of each detected Motor Board is printed to the log when your robot starts.
2219
It will look something like this:
2320

2421
~~~~~ not-code
25-
Found the following devices:
26-
- Motors:
27-
0: Motor( serialnum = "SR0XJ1F" )
28-
1: Motor( serialnum = "SR0A123" )
22+
sr.robot3.robot INFO - Found Student Robotics Motor Board v4 - srABC1
2923
~~~~~
3024

31-
32-
However, like `ruggeduinos` and `servos`, `motors` is actually a dictionary.
33-
As a result, in `motors` you can also use the SR Part Code of the Motor Board as a key.
34-
For example, if you had a board that was labelled "SR0A123",
25+
If you have more than one Motor Board attached, you need to specify which one you want to control. This is done using the serial number of the board. For example: if you had a board that was detected as "srABC1",
3526
you could do this instead:
3627

3728
~~~~~ python
38-
R.motors["SR0A123"].something...
29+
R.motor_boards["srABC1"].something...
3930
~~~~~
4031

32+
<div class="warning">
33+
When you have more than one Motor board connected to your kit,
34+
you must use `R.motor_boards` and index by serial number. This is so
35+
that the kit knows which Motor Board you want to control.
36+
</div>
37+
38+
4139
Setting motor power
4240
-------------------
4341

44-
Motor power is controlled using [PWM](https://en.wikipedia.org/wiki/Pulse-width_modulation) with 100% power being a [duty cycle](https://en.wikipedia.org/wiki/Duty_cycle) of 1. You set the power with an integer value between -100 and 100 inclusive (where a negative value puts the motor in reverse). The field to change the output power is `power`. As each Motor Board has two outputs you will need to specify which output you want to control:
42+
Motor power is controlled using [PWM](https://en.wikipedia.org/wiki/Pulse-width_modulation) with 100% power being a [duty cycle](https://en.wikipedia.org/wiki/Duty_cycle) of 1. You set the power with an integer value between -1 and 1 inclusive. Fractional values (such as 0.42) can be used to specify less than 100% power. Negative values run the motor in the opposite direction.
43+
44+
The field to change the output power is `power`. As each Motor Board has two outputs you will need to specify which output you want to control:
4545

4646
~~~~~ python
47-
from sr.robot import *
47+
from sr.robot3 import *
4848
import time
4949

5050
R = Robot()
5151

52-
# motor board 0, channel 0 to full power forward
53-
R.motors[0].m0.power = 100
52+
# motor board srABC1, channel 0 to full power forward
53+
R.motor_boards["srABC1"].motors[0].power = 1
5454

55-
# motor board 1, channel 0 to full power reverse
56-
R.motors[1].m0.power = -100
55+
# motor board srXYZ1, channel 0 to full power reverse
56+
R.motor_boards["srXYZ1"].motors[0].power = -1
5757

58-
# motor board 0, channel 1 to half power forward
59-
R.motors[0].m1.power = 50
58+
# motor board srABC1, channel 1 to half power forward
59+
R.motor_boards["srABC1"].motors[1].power = 0.5
6060

61-
# motor board 1, channel 0 stopped
62-
R.motors[1].m0.power = 0
61+
# motor board srXYZ1, channel 0 stopped
62+
R.motor_boards["srXYZ1"].motors[0].power = 0
6363

64-
# the following will put motor board 0, channel 1 at 25% power (forwards) for 2.5 seconds:
65-
R.motors[0].m1.power = 25
64+
# the following will put motor board srABC1, channel 1 at 25% power (forwards) for 2.5 seconds:
65+
R.motor_boards["srABC1"].motors[1].power = 0.25
6666
time.sleep(2.5) # wait for 2.5 seconds
67-
R.motors[0].m1.power = 0
67+
R.motor_boards["srABC1"].motors[1].power = 0
6868
~~~~~
6969

7070
You can read the current power value for a motor using the same field:
7171

7272
~~~~~ python
73-
# get the current output power of Motor Board 0, channel 0
74-
currentTarget = R.motors[0].m0.power
73+
# get the current output power of Motor Board srABC1, channel 0
74+
currentTarget = R.motor_boards["srABC1"].motors[0].power
7575
~~~~~
7676

7777
Stopping the motors
@@ -81,29 +81,28 @@ When you set the motor power to 0, this signals the Motor Board to actively stop
8181

8282
~~~~~ python
8383
# store the motor in a local variable because typing it out gets really boring
84-
molly = R.motors[0].m0
84+
molly = R.motor_boards["srABC1"].motors[1]
8585

86-
# set the power to 100 for a second, then stop immediately
87-
molly.power = 100
86+
# set the power to 100% for a second, then stop immediately
87+
molly.power = 1
8888
time.sleep(1)
8989
molly.power = 0
9090
~~~~~
9191

9292
However, you may also want to allow the motors to gently coast to a halt.
93-
This can be achieved by setting the `use_brake` field of the individual motor.
93+
This can be achieved by using the special `COAST` value.
9494

9595
~~~~~ python
96-
# set braking mode
97-
molly.use_brake = False
98-
99-
# set the power to 100 for a second, then coast to a stop
100-
molly.power = 100
96+
# set the power to 100% for a second, then coast to a stop
97+
molly.power = 1
10198
time.sleep(1)
102-
molly.power = 0
103-
104-
# Print the current braking mode (might be handy for debugging!)
105-
print("m0.use_brake = {0}".format(molly.use_brake))
99+
molly.power = COAST
106100
~~~~~
107101

108-
The `use_brake` value defaults to `True` and, just like the `power` value,
109-
will remain set until you change it.
102+
When the power of the motor is set to `0`, it is equivalent to setting
103+
the power to `BRAKE`.
104+
105+
~~~~~ python
106+
# set the motor to brake
107+
molly.power = BRAKE
108+
~~~~~

0 commit comments

Comments
 (0)