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: content/hardware/08.edu/solution-and-kits/alvik/tutorials/user-manual/user-manual.md
+202-2Lines changed: 202 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,10 @@ In this tutorial, you will find useful information to get started, test, and mai
39
39
-[Distance Sensors](#distance-sensors)
40
40
-[Line Follower Sensor](#line-follower-sensor)
41
41
-[Color Sensor](#color-sensor)
42
+
-[Functions](#functions)
42
43
-[IMU](#imu)
44
+
-[Functions](#functions-1)
45
+
-[Example Usage](#example-usage)
43
46
-[Actuators](#actuators)
44
47
-[Motors and Encoders](#motors-and-encoders)
45
48
-[What the Robot Includes](#what-the-robot-includes)
@@ -68,6 +71,7 @@ In this tutorial, you will find useful information to get started, test, and mai
68
71
-[Following a Line](#following-a-line)
69
72
-[Sensing Colors](#sensing-colors)
70
73
-[Detecting Falling and Crashes (IMU)](#detecting-falling-and-crashes-imu)
74
+
-[Add I2C Grove](#add-i2c-grove)
71
75
-[Add Qwiic](#add-qwiic)
72
76
-[Want More?](#want-more)
73
77
-[Need Help](#need-help)
@@ -178,11 +182,207 @@ TODO: Content for this section
178
182
179
183
### Color Sensor
180
184
185
+
The color sensor on the Arduino Alvik robot is used to detect and identify colors on surfaces that the robot encounters. It provides both raw color readouts and labeled color information that can be used for various applications such as line following, object detection, and more.
186
+
187
+
#### Functions
188
+
189
+
1.**color_calibration**
190
+
191
+
The `color_calibration` function is used to calibrate the color sensor for accurate color detection. Calibration can be done against a white or black background.
192
+
193
+
```
194
+
color_calibration(background: str = 'white')
195
+
```
196
+
197
+
**Inputs:**
198
+
-`background`: A string specifying the background color for calibration. Can be "white" or "black".
199
+
200
+
2.**get_color_raw**
201
+
202
+
The `get_color_raw` function returns the raw readout from the color sensor. This is the direct sensor data before any processing or labeling. It can be useful for advanced applications where precise color data is needed.
203
+
204
+
```python
205
+
get_color_raw()
206
+
```
207
+
208
+
**Outputs:**
209
+
-`color`: The color sensor's raw readout.
210
+
211
+
3.**get_color_label**
212
+
213
+
The `get_color_label` function returns the label of the color as recognized by the sensor. This function processes the raw sensor data and converts it into a human-readable label, such as "red", "blue", "green", etc. It simplifies the use of color data for most applications however some flexibility is lost as colors are grouped into the nearest labeled color.
214
+
215
+
```python
216
+
get_color_label()
217
+
```
218
+
219
+
**Outputs:**
220
+
-`color`: The label of the color as recognized by the sensor. These can be:
221
+
- TODO add color labels
222
+
223
+
**Example Usage**
224
+
225
+
Here is an example of how to use the `get_color_label` function in a script that makes the robot walk in a straight line, detect three different colors (ignoring white), stop, and communicate the detected colors via serial every second:
226
+
227
+
```python
228
+
from arduino_alvik import ArduinoAlvik
229
+
import time
230
+
from time import sleep
231
+
232
+
# Initialization
233
+
alvik = ArduinoAlvik()
234
+
alvik.begin()
235
+
sleep(5) # Waiting for the robot to setup
236
+
237
+
# Calibrate color sensor for white
238
+
alvik.color_calibration('white')
239
+
240
+
# Main logic
241
+
detected_colors =set()
242
+
243
+
print("Starting to move and detect colors...")
244
+
245
+
try:
246
+
whilelen(detected_colors) <3:
247
+
alvik.set_wheels_speed(20, 20)
248
+
color = alvik.get_color_label()
249
+
250
+
if color !='WHITE'and color notin detected_colors:
251
+
detected_colors.add(color)
252
+
print(f"Detected color: {color}")
253
+
254
+
time.sleep(0.1) # Adjust the sleep time as needed
255
+
256
+
alvik.brake()
257
+
print("Detected three different colors. Stopping...")
258
+
259
+
# Communicate the detected colors via serial every second
The `get_color` function returns the normalized color readout of the color sensor. This function can output the color in either RGB or HSV format.
274
+
275
+
```python
276
+
get_color(color_format: str='rgb')
277
+
```
278
+
279
+
**Inputs:**
280
+
-`color_format`: The format of the color readout. Can be "rgb" or "hsv".
281
+
282
+
**Outputs:**
283
+
-`r` or `h`: The red component in RGB format or the hue in HSV format.
284
+
-`g` or `s`: The green component in RGB format or the saturation in HSV format.
285
+
-`b` or `v`: The blue component in RGB format or the value in HSV format.
286
+
287
+
5.**hsv2label**
288
+
289
+
TODO: CHECK THIS BETTER FUNCTION UNCLEAR
290
+
The `hsv2label` function returns the color label corresponding to the given normalized HSV color input. It converts HSV values to a human-readable color label.
291
+
292
+
```python
293
+
hsv2label(h, s, v)
294
+
```
295
+
296
+
**Inputs:**
297
+
-`h`: Hue value.
298
+
-`s`: Saturation value.
299
+
-`v`: Brightness value.
300
+
301
+
**Outputs:**
302
+
-`color label`: The label of the color like "BLACK" or "GREEN", if possible, otherwise returns "UNDEFINED".
303
+
304
+
You can use these functions depending on your needs:
305
+
306
+
- Use `color_calibration` to calibrate the sensor for accurate readings.
307
+
- Use `get_color_raw` to get the raw sensor data.
308
+
- Use `get_color_label` to get a human-readable label of the detected color.
309
+
- Use `get_color` to get normalized color data in RGB or HSV format.
310
+
- Use `hsv2label` to convert HSV values to a color label.
311
+
181
312
TODO: Content for this section
182
313
183
314
### IMU
184
315
185
-
TODO: Content for this section
316
+
The Arduino Alvik robot is equipped with an onboard IMU (Inertial Measurement Unit) that provides valuable information about the robot's motion and orientation. The IMU can measure acceleration, angular velocity, and orientation.
317
+
318
+
TODO add image of IMU
319
+
320
+
#### Functions
321
+
322
+
1.**get_orientation**
323
+
324
+
The [`get_orientation`](https://docs.arduino.cc/tutorials/alvik/api-overview/#get_orientation) function returns the orientation of the IMU, including roll, pitch, and yaw values. This can be useful for determining the robot's orientation in 3D space.
325
+
326
+
2.**get_accelerations**
327
+
328
+
The [`get_accelerations`](https://docs.arduino.cc/tutorials/alvik/api-overview/#get_accelerations) function returns the 3-axial acceleration of the IMU. This provides the acceleration values along the x, y, and z axes.
329
+
330
+
3.**get_gyros**
331
+
332
+
The [`get_gyros`](https://docs.arduino.cc/tutorials/alvik/api-overview/#get_gyros) function returns the 3-axial angular acceleration of the IMU. This provides the angular acceleration values along the x, y, and z axes.
333
+
334
+
4.**get_imu**
335
+
336
+
The [`get_imu`](https://docs.arduino.cc/tutorials/alvik/api-overview/#get_imu) function returns all the IMU's readouts, including both the acceleration and angular acceleration values.
337
+
338
+
#### Example Usage
339
+
340
+
Here is a combined example that utilizes all IMU functions:
0 commit comments