From bac049c561095e211ecb775fac23a5decab760ee Mon Sep 17 00:00:00 2001 From: Tomii Poll Date: Fri, 13 Aug 2021 17:07:29 +0100 Subject: [PATCH 01/10] Add simulator section --- content/api/arduino.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/content/api/arduino.md b/content/api/arduino.md index 67d691db..463c8042 100644 --- a/content/api/arduino.md +++ b/content/api/arduino.md @@ -21,7 +21,19 @@ from microswitches to LEDs. GPIO is only available on pins 2 to 13 and A0 to A5 because pins 0 and 1 are reserved for communication with the rest of our kit. -## Pin mode +## Simulator + +In the simulator, the Arduino's pins are pre-populated and pre-configured. +The first few digital pins are occupied by digital inputs, the next few by +digital outputs, and the analogue pins are attached to distance sensors. + +To find out how many inputs and outputs each type of robot has, check the +[robot docs](TODO_change_when_this_page_is_added). + +You won't be able to change pin mode or use the ultrasound sensors like in +a physical robot (see below), but pins 0 and 1 are stil unavailable. + +## Pin Mode (Unavailable in Simulator) GPIO pins have four different modes. A pin can only have one mode at a time, and some pins aren't compatible with certain modes. These pin @@ -113,7 +125,7 @@ The values are the voltages read on the pins, between 0 and 5. Pins `A4` and `A5` are reserved and cannot be used. {{% /notice %}} -## Ultrasound Sensors +## Ultrasound Sensors (Unavailable in Simulator) You can also measure distance using an ultrasound sensor from the Arduino. From bef12a01d195ba1ed4d2d81f45a6567f00966ba1 Mon Sep 17 00:00:00 2001 From: Tomii Poll Date: Fri, 13 Aug 2021 17:40:17 +0100 Subject: [PATCH 02/10] Add DIO section --- content/api/arduino.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/content/api/arduino.md b/content/api/arduino.md index 463c8042..aa2a472a 100644 --- a/content/api/arduino.md +++ b/content/api/arduino.md @@ -33,6 +33,30 @@ To find out how many inputs and outputs each type of robot has, check the You won't be able to change pin mode or use the ultrasound sensors like in a physical robot (see below), but pins 0 and 1 are stil unavailable. +### Digital Inputs + +Each robot has a number of digital inputs, starting from pin 2. If your +robot has 5 inputs, those would occupy pins 2-6. + +These all have a digital state which you can read as a boolean. + +```python +bumper_pressed = r.arduino.pins[5].digital_state +``` + +### Digital Outputs + +The digital outputs start the pin after the last input. If your robot has 5 +inputs and 3 outputs, the outputs would occupy pins 7-9. + +You can set their state similarly to reading the inputs, and you can also +read the last value that was set. + +```python +led_state = r.arduino.pins[8].digital_state +r.arduino.pins[8].digital_state = not led_state # Toggle output +``` + ## Pin Mode (Unavailable in Simulator) GPIO pins have four different modes. A pin can only have one mode at a From db215ff04c13792ddcb9eeb2763bb1f1bcd30164 Mon Sep 17 00:00:00 2001 From: Tomii Poll Date: Fri, 13 Aug 2021 18:13:09 +0100 Subject: [PATCH 03/10] Add analogue section --- content/api/arduino.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/content/api/arduino.md b/content/api/arduino.md index aa2a472a..d2ef1510 100644 --- a/content/api/arduino.md +++ b/content/api/arduino.md @@ -33,6 +33,18 @@ To find out how many inputs and outputs each type of robot has, check the You won't be able to change pin mode or use the ultrasound sensors like in a physical robot (see below), but pins 0 and 1 are stil unavailable. +### Analogue Inputs + +Any analogue input devices (e.g. distance sensors) are connected to the +Arduino's analogue input pins starting from pin `A0`. You can read their +values like this: + +```python +distance = r.arduino.pins[AnaloguePin.A0].analogue_value +``` + +The value read is returned as a float. + ### Digital Inputs Each robot has a number of digital inputs, starting from pin 2. If your From f4e8fa4ef0e8e965a6b42b067c5f839fac4945a4 Mon Sep 17 00:00:00 2001 From: Tomii Poll Date: Fri, 13 Aug 2021 21:19:54 +0100 Subject: [PATCH 04/10] Fix spelling --- .spelling | 4 ++++ content/api/arduino.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.spelling b/.spelling index c27e1e39..fc422e3e 100644 --- a/.spelling +++ b/.spelling @@ -70,3 +70,7 @@ vcc VSCode W3Schools Webots +www.python.org +python-396 +_f_ +× diff --git a/content/api/arduino.md b/content/api/arduino.md index d2ef1510..f29ff9b5 100644 --- a/content/api/arduino.md +++ b/content/api/arduino.md @@ -31,7 +31,7 @@ To find out how many inputs and outputs each type of robot has, check the [robot docs](TODO_change_when_this_page_is_added). You won't be able to change pin mode or use the ultrasound sensors like in -a physical robot (see below), but pins 0 and 1 are stil unavailable. +a physical robot (see below), but pins 0 and 1 are still unavailable. ### Analogue Inputs From 95d6b3389f64f9a8ff002c0e89c69d43072a37b6 Mon Sep 17 00:00:00 2001 From: Tomii Poll Date: Fri, 13 Aug 2021 23:41:52 +0100 Subject: [PATCH 05/10] Add distance sensor section --- content/api/arduino.md | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/content/api/arduino.md b/content/api/arduino.md index f29ff9b5..d45d2356 100644 --- a/content/api/arduino.md +++ b/content/api/arduino.md @@ -33,18 +33,6 @@ To find out how many inputs and outputs each type of robot has, check the You won't be able to change pin mode or use the ultrasound sensors like in a physical robot (see below), but pins 0 and 1 are still unavailable. -### Analogue Inputs - -Any analogue input devices (e.g. distance sensors) are connected to the -Arduino's analogue input pins starting from pin `A0`. You can read their -values like this: - -```python -distance = r.arduino.pins[AnaloguePin.A0].analogue_value -``` - -The value read is returned as a float. - ### Digital Inputs Each robot has a number of digital inputs, starting from pin 2. If your @@ -69,6 +57,27 @@ led_state = r.arduino.pins[8].digital_state r.arduino.pins[8].digital_state = not led_state # Toggle output ``` +### Analogue Inputs + +Any analogue input devices (e.g. distance sensors) are connected to the +Arduino's analogue input pins starting from pin `A0`. You can read their +values like this: + +```python +distance = r.arduino.pins[AnaloguePin.A0].analogue_value +``` + +The value read is returned as a float. + +### Distance Sensor + +Distance sensors are connected to 1 analogue pin each and measure the +distance to the object ahead of them in metres. You read them like any +other analogue pin. + +The value returned will be between 0 and 2 - anything further than 2m +will be capped at 2. + ## Pin Mode (Unavailable in Simulator) GPIO pins have four different modes. A pin can only have one mode at a From 7e1df46d950df1761161fd0ff89178550740cbd5 Mon Sep 17 00:00:00 2001 From: Tomii Poll Date: Fri, 13 Aug 2021 23:56:34 +0100 Subject: [PATCH 06/10] Fix spelling --- content/api/arduino.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/api/arduino.md b/content/api/arduino.md index d45d2356..f96930db 100644 --- a/content/api/arduino.md +++ b/content/api/arduino.md @@ -75,8 +75,8 @@ Distance sensors are connected to 1 analogue pin each and measure the distance to the object ahead of them in metres. You read them like any other analogue pin. -The value returned will be between 0 and 2 - anything further than 2m -will be capped at 2. +The value returned will be between 0 and 2 - anything further than 2 +metres will be capped at 2. ## Pin Mode (Unavailable in Simulator) From b949219f6fab4e226d1b248049058a155b4c546a Mon Sep 17 00:00:00 2001 From: Tomii Poll Date: Sun, 15 Aug 2021 13:38:02 +0100 Subject: [PATCH 07/10] Fix link --- content/api/arduino.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/api/arduino.md b/content/api/arduino.md index f96930db..13cb7e77 100644 --- a/content/api/arduino.md +++ b/content/api/arduino.md @@ -28,7 +28,7 @@ The first few digital pins are occupied by digital inputs, the next few by digital outputs, and the analogue pins are attached to distance sensors. To find out how many inputs and outputs each type of robot has, check the -[robot docs](TODO_change_when_this_page_is_added). +[robot docs](../../robots). You won't be able to change pin mode or use the ultrasound sensors like in a physical robot (see below), but pins 0 and 1 are still unavailable. From 142159433db3fd4e8c38b19f19739478f1982f33 Mon Sep 17 00:00:00 2001 From: Tommy Poll Date: Sun, 15 Aug 2021 15:46:26 +0100 Subject: [PATCH 08/10] Merge ultrasound info --- content/api/arduino.md | 33 ++------------------------------- content/api/ultrasound.md | 31 ++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/content/api/arduino.md b/content/api/arduino.md index 13cb7e77..95f8281e 100644 --- a/content/api/arduino.md +++ b/content/api/arduino.md @@ -25,12 +25,12 @@ rest of our kit. In the simulator, the Arduino's pins are pre-populated and pre-configured. The first few digital pins are occupied by digital inputs, the next few by -digital outputs, and the analogue pins are attached to distance sensors. +digital outputs, and the analogue pins are attached to ultrasound sensors. To find out how many inputs and outputs each type of robot has, check the [robot docs](../../robots). -You won't be able to change pin mode or use the ultrasound sensors like in +You won't be able to change pin mode like in a physical robot (see below), but pins 0 and 1 are still unavailable. ### Digital Inputs @@ -69,15 +69,6 @@ distance = r.arduino.pins[AnaloguePin.A0].analogue_value The value read is returned as a float. -### Distance Sensor - -Distance sensors are connected to 1 analogue pin each and measure the -distance to the object ahead of them in metres. You read them like any -other analogue pin. - -The value returned will be between 0 and 2 - anything further than 2 -metres will be capped at 2. - ## Pin Mode (Unavailable in Simulator) GPIO pins have four different modes. A pin can only have one mode at a @@ -169,23 +160,3 @@ The values are the voltages read on the pins, between 0 and 5. {{% notice warning %}} Pins `A4` and `A5` are reserved and cannot be used. {{% /notice %}} - -## Ultrasound Sensors (Unavailable in Simulator) - -You can also measure distance using an ultrasound sensor from the -Arduino. - -``` python -# Trigger pin: 4 -# Echo pin: 5 -u = r.arduino.ultrasound_sensors[4, 5] - -time_taken = u.pulse() - -distance_metres = u.distance() -``` - -{{% notice warning %}} -If the ultrasound signal never returns, the sensor will timeout and -return `None`. -{{% /notice %}} diff --git a/content/api/ultrasound.md b/content/api/ultrasound.md index e557da27..a2807d3e 100644 --- a/content/api/ultrasound.md +++ b/content/api/ultrasound.md @@ -7,15 +7,36 @@ Ultrasound sensors can measure distance of objects from the sensor. Ultrasound s Ultrasound sensors measure distance in a 18 degree diameter cone in front of the sensor, and report the closest measured distance in that cone. Ultrasound sensors also have a maximum distance. (Ultrasound sensors typically also have a minimum distance too, but we do not simulate that in our simulator). -In our robots, ultrasound sensors are connected to the 'Arduino' board, which is used to read sensors for many different purposes. Keep reading to learn how to take measurements. - +In our robots, ultrasound sensors are connected to the ['Arduino'](arduino) board, which is used to read sensors for many different purposes. Keep reading to learn how to take measurements. + ## Reading the ultrasound sensor - -The ultrasounds sensors will be connected to a specific pin in the Arduino, and will constantly measure distances. Consult the description of the [robot](../../robots/) to see which pin you should use. The analogue value of the pin will be the measured distance, in metres. + +### Simulator + +The ultrasound sensors will be connected to a specific pin in the Arduino, and will constantly measure distances. Consult the description of the [robot](../../robots/) to see which pin you should use. The analogue value of the pin will be the measured distance, in metres. Ultrasound sensors have a maximum range of 2 metres, if objects are further than 2m away from the robot, it will report a distance of 2m. ``` python # Get the closest distance to the ultrasound sensor is reading. distance_metres = r.arduino.pins[pin].analogue_value -``` \ No newline at end of file +``` + +### Physical + +Connect the ultrasound sensor to a pair of digital Arduino pins. You can read either the time taken for the sound pulse to reflect back or the precalculated distance from the API + +``` python +trigger_pin = 4 +echo_pin = 5 +u = r.arduino.ultrasound_sensors[trigger_pin, echo_pin] + +time_taken = u.pulse() + +distance_metres = u.distance() +``` + +{{% notice warning %}} +If the ultrasound signal never returns, the sensor will timeout and +return `None`. +{{% /notice %}} From 9b24695aa810b517032207af4e7a5e4d44fd9ebe Mon Sep 17 00:00:00 2001 From: Tommy Poll Date: Sun, 15 Aug 2021 18:31:48 +0100 Subject: [PATCH 09/10] Pre-calculated --- content/api/ultrasound.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/api/ultrasound.md b/content/api/ultrasound.md index a2807d3e..69d4d0df 100644 --- a/content/api/ultrasound.md +++ b/content/api/ultrasound.md @@ -24,7 +24,7 @@ distance_metres = r.arduino.pins[pin].analogue_value ### Physical -Connect the ultrasound sensor to a pair of digital Arduino pins. You can read either the time taken for the sound pulse to reflect back or the precalculated distance from the API +Connect the ultrasound sensor to a pair of digital Arduino pins. You can read either the time taken for the sound pulse to reflect back or the pre-calculated distance from the API ``` python trigger_pin = 4 From fff9ff190ed04e24de74d8f836090ad15569c6d1 Mon Sep 17 00:00:00 2001 From: Tommy Poll Date: Sun, 15 Aug 2021 18:36:27 +0100 Subject: [PATCH 10/10] Fix broken link --- content/api/ultrasound.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/api/ultrasound.md b/content/api/ultrasound.md index 69d4d0df..923543cb 100644 --- a/content/api/ultrasound.md +++ b/content/api/ultrasound.md @@ -7,7 +7,7 @@ Ultrasound sensors can measure distance of objects from the sensor. Ultrasound s Ultrasound sensors measure distance in a 18 degree diameter cone in front of the sensor, and report the closest measured distance in that cone. Ultrasound sensors also have a maximum distance. (Ultrasound sensors typically also have a minimum distance too, but we do not simulate that in our simulator). -In our robots, ultrasound sensors are connected to the ['Arduino'](arduino) board, which is used to read sensors for many different purposes. Keep reading to learn how to take measurements. +In our robots, ultrasound sensors are connected to the ['Arduino'](../arduino) board, which is used to read sensors for many different purposes. Keep reading to learn how to take measurements. ## Reading the ultrasound sensor