@@ -107,41 +107,41 @@ Doing this is actually very easy; the only thing you need to realise is that a p
107
107
Here's the code:
108
108
109
109
~~~~~ python
110
- from sr.robot import *
110
+ from sr.robot3 import *
111
111
import time
112
112
113
113
R = Robot()
114
114
115
115
while True :
116
116
117
- R.motors[0 ].m0. power = 50
117
+ R.motor_board. motors[0 ].power = 0.5
118
118
time.sleep(3.0 )
119
119
120
- R.motors[0 ].m0 .power = 0
120
+ R.motor_board. motors[0 ].power = 0
121
121
time.sleep(1.4 )
122
122
123
- R.motors[0 ].m0. power = - 50
123
+ R.motor_board. motors[0 ].power = - 0.5
124
124
time.sleep(1 )
125
125
126
- R.motors[0 ].m0 .power = 0
126
+ R.motor_board. motors[0 ].power = 0
127
127
time.sleep(4 )
128
128
~~~~~
129
129
130
- You're familiar with the first few lines; in fact, the only lines you may not be familiar with are the ` R.motors[0] ... ` lines.
131
- For a comprehensive reference to the ` motor ` object, see the ` sr.robot ` module's [ ` motor ` ] ( /docs/programming/sr/motors/ ) page.
130
+ 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.
132
132
But, to summarise:
133
133
134
134
<div class =" info " >
135
- `R.motors[0].m0. power = x` will set the power of the motor connected to output 0 (the `m0 ` part)
136
- on the first [motor board](/docs/kit/motor_board) (the `motors[0] ` part)
137
- plugged in to a USB hub to `x`, where `x` is a value between `-100 ` and `100 `,
138
- inclusive — in other words: `-100 ` ≤ `x` ≤ `100 `.
135
+ `R.motor_board. motors[0].power = x` will set the power of the motor connected to output 0 (the `motors[0] ` part)
136
+ on the first [motor board](/docs/kit/motor_board) (the `motor_board ` part)
137
+ plugged in to a USB hub to `x`, where `x` is a value between `-1 ` and `1 `,
138
+ inclusive — in other words: `-1 ` ≤ `x` ≤ `1 `.
139
139
</div >
140
140
141
- So, ` R.motors[0].m0. power = 50 ` sets the target power of the motor connected to output 0 on the first [ motor board] ( /docs/kit/motor_board )
141
+ 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
142
plugged in to a USB hub to 50% forwards (i.e. a duty-cycle of 0.5 forwards).
143
- As you would expect, then, ` R.motors[0].m0. power = -50 ` will put the this motor into reverse at 50% power.
144
- ` R.motors[0].m0 .power = 0 ` will output no power to the motor and stop it.
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
+ ` R.motor_board. motors[0].power = 0 ` will output no power to the motor and stop it.
145
145
146
146
So, if you put the above code on your robot,
147
147
you should be able to see a motor spin forwards, stop, spin backwards, stop, and then repeat...
@@ -161,53 +161,53 @@ Our aim is to do the forwards and backwards bit (as above), but, before we loop
161
161
Here's the code:
162
162
163
163
~~~~~ python
164
- from sr.robot import *
164
+ from sr.robot3 import *
165
165
import time
166
166
167
167
R = Robot()
168
168
169
169
while True :
170
170
171
- R.motors[0 ].m0. power = 50
171
+ R.motor_board. motors[0 ].power = 0.5
172
172
time.sleep(3.0 )
173
173
174
- R.motors[0 ].m0 .power = 0
174
+ R.motor_board. motors[0 ].power = 0
175
175
time.sleep(1.4 )
176
176
177
- R.motors[0 ].m0. power = - 50
177
+ R.motor_board. motors[0 ].power = - 0.5
178
178
time.sleep(1 )
179
179
180
- R.motors[0 ].m0 .power = 0
180
+ R.motor_board. motors[0 ].power = 0
181
181
time.sleep(4 )
182
182
183
183
# ^^ code from before ^^
184
184
185
- # power up to 70 (from 10)
185
+ # power up to 70% (from 10% )
186
186
for pwr in range (10 , 80 , 10 ):
187
- R.motors[0 ].m0. power = pwr
187
+ R.motor_board. motors[0 ].power = pwr / 100 # Convert from percentage
188
188
time.sleep(0.1 )
189
189
190
- # power down from 70 (to 10)
190
+ # power down from 70% (to 10% )
191
191
for pwr in range (70 , 0 , - 10 ):
192
- R.motors[0 ].m0. power = pwr
192
+ R.motor_board. motors[0 ].power = pwr / 100 # Convert from percentage
193
193
time.sleep(0.1 )
194
194
195
195
# set power to 0 for a second
196
- R.motors[0 ].m0. power = 0
196
+ R.motor_board. motors[0 ].power
197
197
time.sleep(1 )
198
198
199
- # power "up" to -70 (from -10)
199
+ # power "up" to -70% (from -10% )
200
200
for pwr in range (- 10 , - 80 , - 10 ):
201
- R.motors[0 ].m0. power = pwr
201
+ R.motor_board. motors[0 ].power = pwr / 100 # Convert from percentage
202
202
time.sleep(0.1 )
203
203
204
- # power "down" to -10 (from -70)
204
+ # power "down" to -10% (from -70% )
205
205
for pwr in range (- 70 , 0 , 10 ):
206
- R.motors[0 ].m0. power = pwr
206
+ R.motor_board. motors[0 ].power = pwr / 100 # Convert from percentage
207
207
time.sleep(0.1 )
208
208
209
209
# set power to 0 for a second
210
- R.motors[0 ].m0 .power = 0
210
+ R.motor_board. motors[0 ].power = 0
211
211
time.sleep(1 )
212
212
213
213
~~~~~
0 commit comments