Skip to content

Commit 0b09b9a

Browse files
committed
Update robot API page - Add comp mode page
1 parent 77dc7ad commit 0b09b9a

File tree

2 files changed

+90
-64
lines changed

2 files changed

+90
-64
lines changed

programming/robot_api/comp_mode.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,37 @@ title: Competition Mode
55

66
# Competition Mode
77

8-
TODO
8+
9+
## What is Comp Mode
10+
11+
During a competition match a Competition Mode USB is inserted into a spare USB port on your robot (See the [kit assembly guide]({{ site.baseurl }}/tutorials/assembly) for details on the spare USB port you need to leave).
12+
This will instruct your robot that it is in competition mode and will enable a game timeout, disable the WiFi and update certain `robot` attributes.
13+
14+
15+
## Effects of Comp Mode
16+
17+
* Enabling Game timeout
18+
19+
When in competition mode the robot will automatically stop at the end of a match, where the duration of a match is defined in the [rules]({{ site.baseurl }}/tutorials/assembly).
20+
The duration of the match is defined from when the start button is pressed.
21+
22+
* Disabling of WiFi and Web interface
23+
24+
During competition matches remote control of robots is forbidden ([rules]({{ site.baseurl }}/tutorials/assembly)), so the WiFi and web interface are disabled to ensure a fair game.
25+
26+
* Updating of match-specific `robot` attributes
27+
28+
Certain robot attributes will change when in comp mode, these can be used to change your robot's behaviour.
29+
The affected attributes are:
30+
31+
mode
32+
: Whether the robot is running in competition mode.
33+
When in a competition match, this will be `COMP`, and at all other times this will be `DEV`.
34+
35+
zone
36+
: The number of the scoring zone that the robot is associated with.
37+
Between `0` and `3`.
38+
39+
The zone you are in defines which arena markers are near your scoring zone.
40+
You can use the knowledge of your zone to compensate for this, so your robot behaves correctly in all starting positions.
41+
See the [rules]({{ site.baseurl }}/tutorials/assembly) for where the scoring zones and arena markers are positioned.

programming/robot_api/index.md

Lines changed: 56 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,126 +3,119 @@ layout: page
33
title: Robot API
44
---
55

6-
Robot API
7-
=========
6+
# Robot API
87

98
Student Robotics has written a module — `sr.robot3` — which is used to interface with the hardware.
109
It handles all the low-level interactions so you don't have to.
11-
To set the output power of output 0 of the first motor board to -30%, for example, you would simply write:
1210

13-
~~~~~ python
14-
R.motor_board.motors[0].power = -0.3
15-
~~~~~
16-
17-
`-0.3` would be backwards (depending upon which way you wired up the motor) — 30% power in reverse.
18-
19-
To gain access to all of this functionality, all you need to do is write:
11+
For example, to set the power of output 0 on a Motor Board to 30%, you would simply write:
2012

2113
~~~~~ python
22-
from sr.robot3 import *
14+
robot.motor_board.motors[0].power = 0.3
2315
~~~~~
2416

25-
...at the top of your code (before you use any of its functionality, basically).
26-
This imports the Student Robotics module that we've written to interface with our hardware.
17+
<div class="info" markdown="1">
18+
See the [Motor Board]({{ site.baseurl }}/programming/motors) page for more details about this example.
19+
</div>
2720

28-
Then, within the `sr.robot3` module, there is a `Robot` class that should be instantiated, as follows:
21+
To gain access to all of this functionality, all you need to do at the top of your code is the following:
2922

3023
~~~~~ python
3124
from sr.robot3 import *
32-
R = Robot()
25+
robot = Robot()
3326
~~~~~
3427

35-
Within your `Robot` (`R` in this case), you then have access to the following attributes:
28+
This imports the Student Robotics module that we've written to interface with our hardware.
29+
We then use the `Robot` class from within the `sr.robot3` module, to create a `robot` object that sets up and gives you access to your robot's hardware.
3630

37-
* [motors](/docs/programming/motors)
38-
* [power](/docs/programming/power)
39-
* [servos](/docs/programming/servos)
40-
* [ruggeduinos](/docs/programming/arduino/)
41-
* [vision](/docs/programming/vision/)
31+
<div class="info" markdown="1">
32+
Most examples in the documentation will assume you have created a `robot` object from the `Robot` class.
33+
If you see `robot` in a code example, it is assumed you have run the two lines above.
34+
</div>
4235

43-
They can be used in your code just like the example above.
44-
Note that `motors`, `ruggeduinos`, and `servos` are Python lists, and so should be accessed as such.
45-
Here are some examples:
36+
Then, within your `robot` you can use the following attributes to access to the robot's hardware:
4637

47-
~~~~~ python
48-
R.motor_board.motors[0].power = 0.5 # WILL work, if motor 0 exists
49-
R.motor_board.motors[1].power = -0.2 # WILL work, if motor 1 exists
50-
R.motor_board.motors.power = 0.42 # WON'T WORK
38+
* [kch]({{ site.baseurl }}/programming/leds)
39+
* [motor_board]({{ site.baseurl }}/programming/motors)
40+
* [power_board]({{ site.baseurl }}/programming/power)
41+
* [servo_board]({{ site.baseurl }}/programming/servos)
42+
* [arduino]({{ site.baseurl }}/programming/arduino/)
43+
* [camera]({{ site.baseurl }}/programming/vision/)
5144

52-
# the above is similar to the situation for 'ruggeduinos' and 'servos'
53-
~~~~~
45+
The functions of each board are described on their respective pages.
5446

55-
A number of examples in the documentation will assume you've instantiated the required `Robot` class and have called it `R`.
56-
From here in, if you see a `R.something`, the requirement of the `sr.robot3` import line and the instantiation of `Robot` as `R` is implicit.
5747

58-
[Other Robot Attributes](#OtherRobotAttributes) {#OtherRobotAttributes}
59-
----------------------
48+
## Other Robot Attributes
6049

61-
As well as the attributes listed above, the Robot class also has the following attributes, which you may find useful:
50+
As well as the attributes listed above, the `Robot` class also has the following attributes, which you may find useful:
6251

6352
zone
64-
: The number of the zone that the robot is associated with. Between `0` and `3`.
53+
: The number of the scoring zone that the robot is associated with.
54+
Between `0` and `3`.
55+
56+
This attribute is only available after the start button is pressed and will throw an error if accessed before.
57+
See the [competition mode](./comp_mode) page for more information about this attribute.
6558

6659
mode
6760
: Whether the robot is running in competition mode.
68-
When in a competition match, this will be `RobotMode.COMP`, and at all other times this will be `RobotMode.DEV`.
61+
When in a competition match, this will be `COMP`, and at all other times this will be `DEV`.
62+
63+
This attribute is only available after the start button is pressed and will throw an error if accessed before.
64+
See the [competition mode](./comp_mode) page for more information about this attribute.
6965

7066
~~~~~ python
7167
from sr.robot3 import *
7268

73-
R = Robot()
69+
robot = Robot()
7470

75-
if R.mode == RobotMode.COMP:
76-
print("This is the competition!")
71+
if robot.mode == COMP:
72+
print("This is the competition!")
73+
elif robot.mode == DEV:
74+
print("This is development")
7775
~~~~~
7876

7977
usbkey
80-
: The path to the USB memory stick.
81-
Your code is unzipped and run from a temporary directory, therefore files you create will be lost when the kit is turned off.
82-
You can use this to easily read from and write to files on the stick itself.
83-
Note that the USB memory stick is mounted synchronously, so any writes to it will block until complete and may slow down your code.
78+
: The path to the USB stick.
79+
You can use this to easily read and write files on the USB stick itself.
8480

85-
An example of how the `usbkey` attribute might be used:
81+
An example of how the `usbkey` attribute might be used to read a file called `my-file.txt` which is stored on the USB stick:
8682

8783
~~~~~ python
8884
from sr.robot3 import *
8985
import os
9086

91-
R = Robot()
92-
print("The path to the USB key is:", R.usbkey)
87+
robot = Robot()
88+
print("The path to the USB stick is:", robot.usbkey)
9389
print("My file on the USB contains:")
94-
with open(os.path.join(R.usbkey, 'my-file.txt'), 'r') as f:
95-
print(f.read())
90+
with open(os.path.join(robot.usbkey, 'my-file.txt')) as file:
91+
print(file.read())
9692
~~~~~
9793

9894
is_simulated
9995
: A boolean value indicating whether or not the code is running in the simulator.
96+
This value is `True` when in the simulator and `False` when on the robot.
97+
10098

101-
[Custom Robot Object Initialisation](#CustomRobotInit) {#CustomRobotInit}
102-
----------------------
99+
## Custom Robot Object Initialisation
103100

104101
Normally the Robot object is initialised with the following:
105102

106103
~~~~~ python
107-
R = Robot()
104+
from sr.robot3 import *
105+
robot = Robot()
108106
~~~~~
109107

110-
However if you want to:
111-
112-
* customise your Ruggeduino firmware
113-
* initialise some hardware or software before the start button is pressed
114-
115-
Then Robot initialisation can be broken up as follows (this example is equivalent to the previous code excerpt):
108+
By default your robot will pause on this line waiting for the start button to be pressed.
109+
However if you want to initialise some hardware or software before the start button is pressed then Robot initialisation can be broken up as follows.
116110

117111
~~~~~ python
118-
R = Robot(auto_start=True)
112+
from sr.robot3 import *
113+
robot = Robot(wait_for_start=False)
119114

120115
# Initialisation phase.
121116
# Here you can perform hardware/software initialisation before start
122117

123-
R.wait_start()
118+
robot.wait_start()
124119
~~~~~
125120

126-
During the initialisation phase, all hardware is accessible.
127-
If you have any hardware which must be initialised before the start button is pressed,
128-
the initialisation phase is the time to do so.
121+
This will not pause on the line which creates the `robot` but will instead pause on the `robot.wait_start()` line, until the start button is pressed.

0 commit comments

Comments
 (0)