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
@@ -12,31 +12,15 @@ This documentation refers to a feature which is only available on the physical r
12
12
13
13
The Ruggeduino that came as part of your kit was shipped with a firmware that provides the functionality outlined in the [Ruggeduino](/docs/programming/sr/ruggeduinos) page.
14
14
You may wish to extend the functionality of this firmware, or completely replace it.
15
-
The `sr.robot` library provides support for three Ruggeduino firmware scenarios:
15
+
The `sr.robot3` library provides support for three Ruggeduino firmware scenarios:
16
16
17
17
1. Default SR firmware
18
18
2.[Extended SR firmware](#extension): Firmwares that add commands to the default SR firmware.
19
19
3.[Completely custom](#completely): Any firmware not derived from the SR firmware.
20
20
21
-
By default, the [`sr.robot`](/docs/programming/sr/) library assumes that all connected Ruggeduinos are running the SR firmware.
22
-
If you wish to use an extended SR firmware, or completely custom firmware,
23
-
then you need to tell the `Robot` object what to do with your Ruggeduino(s).
24
-
To do this, you will need to expand the initialisation of your `Robot` object as detailed [here](/docs/programming/sr/#CustomRobotInit).
25
-
Your code will then look something like this:
26
-
27
-
~~~~~python
28
-
from sr.robot import*
29
-
30
-
R = Robot.setup()
31
-
32
-
R.init()
33
-
34
-
R.wait_start()
35
-
36
-
# The rest of your code
37
-
~~~~~
38
-
39
-
The next step depends on whether you are running an extended SR firmware, or a completely custom firmware.
21
+
By default, the [`sr.robot3`](/docs/programming/sr/) library assumes that all connected Ruggeduinos are running the SR firmware
22
+
or firmware which is compatible with the SR Ruggeduino firmware.
23
+
If you're using completely custom firmware, you'll need to tell the kit to ignore the ruggeduino so that you're able to define your own setup logic.
40
24
41
25
[Extension of the SR firmware](#extension) {#extension}
42
26
------------------------------
@@ -95,149 +79,20 @@ Your command can read additional data from the serial port if it requires additi
95
79
It can also write a response back to the host (your Python code).
96
80
Have a look at the `command_read()` function to see how to do this.
97
81
98
-
### Step 2: Extend the `Ruggeduino` class
99
-
100
-
Your robot's python code will, by default, use a `Ruggeduino` object to communicate with the Ruggeduino.
101
-
The object returned to you when you type `R.ruggeduinos[0]` is a `Ruggeduino` instance.
102
-
This object knows how to talk to the default command handlers in the SR firmware.
103
-
104
-
<divclass="info"markdown="1">
105
-
Don't worry if you don't know what "object" means -- you can probably blag this without knowing!
106
-
If you do want to know about them, you'll find introductions to them all over the web.
107
-
You could try [this one](http://www.jesshamrick.com/2011/05/18/an-introduction-to-classes-and-inheritance-in-python/), for example.
108
-
</div>
109
-
110
-
You'll need to extend the `Ruggeduino` class, giving it at least one extra method to perform your command.
111
-
Start by adding this to your code:
112
-
113
-
~~~~~python
114
-
from sr.robot import*
115
-
116
-
classCustomisedRuggeduino(Ruggeduino):
117
-
pass
118
-
~~~~~
119
-
120
-
You've just declared a class called `CustomisedRuggeduino` (you will probably want to call it something else that makes more sense in your application).
121
-
At the moment, it behaves in exactly the same way as the `Ruggeduino` class.
122
-
You now need to add your custom method to it:
123
-
124
-
~~~~~python
125
-
from sr.robot import*
126
-
127
-
classCustomisedRuggeduino(Ruggeduino):
128
-
129
-
# Your function for instructing a Ruggeduino to bake a cake
130
-
defbake_cake(self):
131
-
withself.lock:
132
-
self.command("c")
133
-
~~~~~
134
-
135
-
Skipping ahead for a moment: Once we've told your `Robot` object about this `CustomisedRuggeduino`
136
-
class (which we do in the next step), you will be able to do this:
137
-
138
-
~~~~~python
139
-
R.ruggeduinos[0].bake_cake()
140
-
# and you'll still be able to do this:
141
-
R.ruggeduinos[0].digital_read(3)
142
-
~~~~~
143
-
144
-
<divclass="warning"markdown="1">
145
-
The IDE will unfortunately error about the lack of a `bake_cake` method (or your equivalent) in the above code.
146
-
This is an expected restriction of the way the IDE checks the syntax of your code.
147
-
148
-
You can therefore ignore these errors (though you should be careful that the error is one of these and not something else).
149
-
</div>
150
-
151
-
#### `with self.lock:`
152
-
153
-
You'll notice that the code above contains a line that reads:
154
-
155
-
~~~~~python
156
-
withself.lock:
157
-
~~~~~
158
-
159
-
Whenever you call `self.command`, you need to ensure that it is called within a block of code headed by this `with` statement.
160
-
This is a tool that makes your code "thread-safe".
161
-
If you're not using threads, then you will still need to use it, but it won't affect the behaviour of your program.
82
+
### Step 2: Use your new command from Python
162
83
163
-
#### Responses
164
-
165
-
The response from your command is returned by the `self.command` function.
166
-
Remember that it will be a string, so you will need to convert it as necessary.
167
-
168
-
If, for example, our cake-baking function on our Ruggeduino responds with the number of cakes that were baked, then we could do this:
84
+
You can send a custom command from your Python code to the Ruggeduino to control your cake-baking.
169
85
170
86
~~~~~python
171
-
classCustomisedRuggeduino(Ruggeduino):
172
-
173
-
defbake_cake(self):
174
-
withself.lock:
175
-
resp =self.command("c")
176
-
returnint(resp)
87
+
cake_result = R.ruggeduino.command("c")
177
88
~~~~~
178
89
179
-
180
-
### Step 3: Tell the `Robot` to use your extended class
181
-
182
-
Now that you've extended the `Ruggeduino` class to create your `CustomisedRuggeduino` class,
183
-
it's time to tell the `Robot` object about it using the `ruggeduino_set_handler_by_fwver` function:
The analogue pin numbers are available as `A0`, `A1`, `A2`, `A3`, `A4`, and `A5` respectively.
102
+
101
103
102
104
[Output](#output) {#output}
103
105
--------
104
106
105
107
You can only set digital outputs (there's no analogue output, although you may feel free to modify the Ruggeduino's firmware to add the ability to output [PWM](https://wikipedia.org/wiki/Pulse-width_modulation"Pulse-width modulation") if you desire). To set a digital output pin, you would use the following:
0 commit comments