diff --git a/assets/tutorials/foam-dart-launcher/add-board.png b/assets/tutorials/foam-dart-launcher/add-board.png deleted file mode 100644 index cf2fe63936..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/add-board.png and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/assembled-foam-dart-launcher.jpg b/assets/tutorials/foam-dart-launcher/assembled-foam-dart-launcher.jpg deleted file mode 100644 index a105f460dc..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/assembled-foam-dart-launcher.jpg and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/base-cam-view.png b/assets/tutorials/foam-dart-launcher/base-cam-view.png deleted file mode 100644 index 0856c9aef3..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/base-cam-view.png and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/board-displaying-high.png b/assets/tutorials/foam-dart-launcher/board-displaying-high.png deleted file mode 100644 index 0dd30a6d9b..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/board-displaying-high.png and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/board-high.png b/assets/tutorials/foam-dart-launcher/board-high.png deleted file mode 100644 index 8ecbf7a7c1..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/board-high.png and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/board-low.png b/assets/tutorials/foam-dart-launcher/board-low.png deleted file mode 100644 index f34907cc04..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/board-low.png and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/camera-cam-view.png b/assets/tutorials/foam-dart-launcher/camera-cam-view.png deleted file mode 100644 index 0072ddcec3..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/camera-cam-view.png and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/config-base.png b/assets/tutorials/foam-dart-launcher/config-base.png deleted file mode 100644 index a66a5efb98..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/config-base.png and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/config-webcam.png b/assets/tutorials/foam-dart-launcher/config-webcam.png deleted file mode 100644 index d728394678..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/config-webcam.png and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/dual-h-bridge-motor-controller.jpg b/assets/tutorials/foam-dart-launcher/dual-h-bridge-motor-controller.jpg deleted file mode 100644 index 39633cc94c..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/dual-h-bridge-motor-controller.jpg and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/foam-dart-launcher-robot-demo.jpg b/assets/tutorials/foam-dart-launcher/foam-dart-launcher-robot-demo.jpg deleted file mode 100644 index a0edc255e9..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/foam-dart-launcher-robot-demo.jpg and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/left-motor.png b/assets/tutorials/foam-dart-launcher/left-motor.png deleted file mode 100644 index 05b6060361..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/left-motor.png and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/lr-motor-config-panes.png b/assets/tutorials/foam-dart-launcher/lr-motor-config-panes.png deleted file mode 100644 index 073373e50f..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/lr-motor-config-panes.png and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/ng-taped-to-rover.jpg b/assets/tutorials/foam-dart-launcher/ng-taped-to-rover.jpg deleted file mode 100644 index e4a0d993b3..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/ng-taped-to-rover.jpg and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/power-relay.jpg b/assets/tutorials/foam-dart-launcher/power-relay.jpg deleted file mode 100644 index 402d6d8674..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/power-relay.jpg and /dev/null differ diff --git a/assets/tutorials/foam-dart-launcher/right-motor.png b/assets/tutorials/foam-dart-launcher/right-motor.png deleted file mode 100644 index 528d30d10e..0000000000 Binary files a/assets/tutorials/foam-dart-launcher/right-motor.png and /dev/null differ diff --git a/docs/tutorials/projects/foam-dart-launcher.md b/docs/tutorials/projects/foam-dart-launcher.md index 6e67e13b58..0848fa2dc0 100644 --- a/docs/tutorials/projects/foam-dart-launcher.md +++ b/docs/tutorials/projects/foam-dart-launcher.md @@ -2,6 +2,8 @@ title: "Foam Dart Launcher Robot Tutorial" linkTitle: "Dart Launcher Robot" type: "docs" +layout: "empty" +canonical: "https://www.viam.com/post/foam-dart-launcher" description: "Build a foam dart launcher with a wheeled rover and a Raspberry Pi." videos: ["/tutorials/videos/foam-dart.webm", "/tutorials/videos/foam-dart.mp4"] videoAlt: "Robot launching a dart." @@ -16,370 +18,7 @@ viamresources: ["base", "camera", "motor", "board"] level: "Intermediate" date: "2022-11-29" # updated: "" -cost: "145" +cost: 145 no_list: true +resource: "blogpost" --- - -## Introduction - -This tutorial will show you how to build your very own foam dart launcher robot using Viam, a Raspberry Pi, a generic foam dart launcher with foam darts, a USB camera, a solenoid, a relay, and a motor controller. -This robot will be able to move around and launch foam darts. - -This project is a great place to start if you are new to building robots, have a love for Nerf toys, an occasion to target something and launch a dart at it, or if you just want to troll your friends. -Don’t forget to be careful and have fun! - -{{}} - -## What you’ll need for this tutorial - -You will need the following hardware, software, tools, and consumables to complete this project: - -{{% alert title="Important" color="note"%}} -If you use a different rover and/or motor controller, ensure that the motor driver is compatible with the motors on your rover. -For example, a brushed DC motor requires a brushed DC motor driver that is rated for the power requirements of the motor. -Also, the configuration files shown in this tutorial _must_ be modified if you use a different setup. - -You can find more information on configuring different motors in the [Motor Component](/components/motor/) topic. -{{% /alert %}} - -### Hardware and software requirements - -- [Raspberry Pi with microSD card](https://a.co/d/bxEdcAT), with `viam-server` installed per [our Raspberry Pi setup guide](/get-started/installation/). -- [A wheeled rover](https://www.amazon.com/Smart-Chassis-Motors-Encoder-Battery/dp/B01LXY7CM3/) -- [A foam dart launcher](https://www.amazon.com/Nerf-N-Strike-Elite-Jolt-Blaster/dp/B01HEQHXE8) -- [A USB camera (webcam)](https://www.amazon.com/gp/product/B0972KK7BC/) (optional, to see where you are going and aiming) -- [A solenoid](https://www.amazon.com/0530-Frame-Solenoid-Electromagnet-Stroke/dp/B07K35L4TH/) -- [A relay](https://www.amazon.com/HiLetgo-Channel-Isolation-Support-Trigger/dp/B00LW15D1M/) -- [A dual motor controller](https://www.amazon.com/Qunqi-Controller-Module-Stepper-Arduino/dp/B014KMHSW6/) - If you use a different motor driver, refer to the manufacturer’s data sheet and our [motor component topic](/components/motor/) to learn how to configure the pins. -- Jumper wires (breadboard wires) - -### Tools and consumables - -- Solder (optional) -- Small flathead screwdriver -- Cutting pliers (flush-cutting pliers preferred) -- Electrical tape -- Elastic/rubber bands - -## How to assemble your hardware - -### Motor controller setup - -A motor controller is a piece of hardware that takes digital signals from the Raspberry Pi and sends power to the motors accordingly. -For this setup we have one dual motor controller for the two motors. - -{{% alert title="Info" color="info" %}} -If you have more than two motors you will likely need two motor controllers. -{{% /alert %}} - -{{< figure src="/tutorials/foam-dart-launcher/dual-h-bridge-motor-controller.jpg" width="400px" alt="Dual H-bridge motor controller with four signal wires going in and two sets of motor power wires coming out." title="Dual H-bridge motor controller." >}} - -We need only worry about OUT1 through OUT4, IN1 through IN4, 12V, and ground. - -
    -
  1. Attach left to the motor controller. -
      -
    1. Use a small flathead screwdriver to loosen the Out1 and OUT2 screw terminals. -
    2. Place the red motor wire into OUT1 -
    3. Place the black motor wire into OUT2 -
    4. Use the flathead screwdriver to tighten the terminals to firmly hold the wires in place. -Note: Tightly twisting each stripped wire end and then tinning it makes it easier to insert and secure the jumper in screw terminal connectors. -
    -
  2. Connect the control wires IN1 and IN2 to your Raspberry Pi. -
      -
    1. The example robot has IN1 -> pin 11, IN2 -> pin 13 -
    -
  3. Repeat steps 1-2 for the right motor using OUT3, OUT4, IN3, IN4 -
      -
    1. The example robot has IN3 -> pin 16, IN4 -> pin 18 -
    -
  4. Connect the external power that will supply power to the motors. -
      -
    1. In the example we have 4 AA batteries connected to the motor driver giving us 6V of power for the motors. -
    -
- -### Camera setup - -This is as easy as plugging the camera into a USB slot on your Pi. -We’ll configure the camera in the Viam app in later steps. - -### Relay/Solenoid setup - -The solenoid component actuates the foam dart launcher trigger. -The relay works as a switch to turn on and off the solenoid. -This allows us to activate the foam dart launcher with a GPIO pin on the board. - -{{% alert title="Info" color="info" %}} -We cannot directly power these components from GPIO pins, since there is a board limitation that restricts GPIO pins to providing 3.3V and a very limited current supply (16mA). -Even the 3.3V and 5V power pins on the Pi supply are limited to about 1A. - -If a component attempts to pull more current than that, you risk power cycling the Pi. -That is why we use a relay to supply 5VDC with a higher current to actuate the solenoid. -This is standard practice for power control circuits in many situations. -For example, by using a common off-the-shelf 15A light switch to actuate a relay bank, it is possible to control hundreds of amps of lighting for an entire office floor. -{{% /alert %}} - -{{< figure src="/tutorials/foam-dart-launcher/power-relay.jpg" width="400px" alt="Power relay." title="Power relay." >}} - -
    -
  1. Connect the solenoid to the relay.
  2. -
      -
    1. Connect a wire to the Normally Open (NO) terminal connector.
    2. -
    3. Connect the other end to a ground pin on the Raspberry Pi.
    4. -
    -
  3. Connect the Relay COMmon pin.
  4. -
      -
    1. Connect the COM pin to the 3.3V power of the Raspberry Pi.
    2. -
    -
  5. Connect VCC (DC+) and ground (DC-) .
  6. -
      -
    1. Connect DC+ to the 6V of the external battery pack.
    2. -
    3. Connect DC- to ground on the Raspberry Pi.
    4. -
    -
  7. Connect IN.
  8. -
      -
    1. Connect IN to a GPIO pin on the Raspberry Pi.
    2. -
    3. For this example, we've connected to pin 37.
    4. -
    -
- -### Assemble solenoid/foam dart launcher - -{{< figure src="/tutorials/foam-dart-launcher/assembled-foam-dart-launcher.jpg" width="400px" alt="Solenoid attached to the orange foam dart launcher using rubber bands and electrical tape." title="Foam dart launcher/Solenoid Assembly." >}} - -1. Modify the foam dart launcher to make room for the solenoid. - Using cutting pliers, we cut the trigger guard off of the front as seen in the picture above. -2. Test that the solenoid has enough power to press the trigger when the foam dart launcher is loaded. -3. If the solenoid is not strong enough we can: - - Wrap the trigger with rubber bands to make the trigger easier to activate[^rb]. - - Increase the voltage to the solenoid. - Right now it receives 5 volts, but some solenoids can support up to 12 volts. - If necessary, you can connect the solenoid to another power supply such as a 9 volt battery. - Check the details of your solenoid[^solvolt]. -4. Tape the solenoid in such a manner that it makes good contact with the trigger when activated with the relay. -5. Attach all of your components to the base. - -[^rb]: - If you use the rubber band method, you may need to pull the rubber bands away from the trigger when reloading the foam dart launcher so it can reset and load properly. - Try activating the solenoid manually to ensure that it hits the foam dart launcher trigger in the right spot. - -[^solvolt]: If you choose to increase the voltage, you must connect **VCC** and ground (**DC+** and **DC-**) to the new voltage source rather than connecting them to the Raspberry Pi as described in Step 3 of [Assemble Solenoid/Foam Dart Launcher](#assemble-solenoidfoam-dart-launcher). - -{{< figure src="/tutorials/foam-dart-launcher/ng-taped-to-rover.jpg" alt="Foam dart launcher taped to a rover base using electrical tape." title="Foam dart launcher Taped to the Rover" width="400">}} - -## Configure your foam dart launcher robot with the Viam app - -Create a new machine in the Viam app and give it a name. -Navigate to your new machine's **Config** tab and click the **Components** subtab. - -### Board configuration (Raspberry Pi) - -Click **Create component** and add your [board](/components/board/). -Choose type `board` and model `pi`. -Name it `local` and click **Create**. - -{{}} - -You can name your board whatever you want, we picked `local`. -Just remember to use that name consistently in the following steps. - -### Motor configuration - -#### Left motor - -Click **Create component** and add the left [motor](/components/motor/) with type `motor` and model `gpio`. -Name it `left` and click **Create**. - -Select the name of the board the motor controller is wired to (for example, "local") from the **Board** dropdown. - -Toggle the **Component Pin Assignment Type** to **In1/In2** since that is compatible with the input type our motor controller expects. - -In the **A/In1** and **B/In2** dropdowns, choose `11 GPIO 17` and `13 GPIO 27`, respectively. - -Set **Max RPM** to `150`. - -{{}} - -Click **Save config** at the bottom of the screen. - -#### Right motor - -Click **Create component** and add the right [motor](/components/motor/) with type `motor` and model `gpio`. -Name it `right` and click **Create**. - -Select the name of the board the motor controller is wired to (for example, "local") from the **Board** dropdown. - -Toggle the **Component Pin Assignment Type** to **In1/In2**. - -For **A/In1** select `16 GPIO 23` and for **B/In2** select `18 GPIO 24`. - -Set **Max RPM** to `150`. - -{{}} - -Click **Save config** at the bottom of the screen. -Then go to the **Control** tab where you will now see the buttons you can use to control the motors: - -{{}} - -Now you can drive your left and right wheels separately. -Let’s add a base to be able to control them together. - -### Base configuration - -Configure a [base component](/components/base/) to coordinate your motors so you can move the base around with your keyboard. - -Click **Create component** and add the base with type `base` and model `wheeled`. -Give it a name (you can call it `base`) and click **Create**. - -From the **Right Motors** and **Left Motors** dropdowns, select `right` and `left`, respectively (the motors you configured in the previous step). - -Set the **Wheel Circumference** to `200` and the **Width** to `130` if you used [the same rover we did](https://www.amazon.com/Smart-Chassis-Motors-Encoder-Battery/dp/B01LXY7CM3/). -If you used different hardware, measure the diameter of your wheels and multiply by pi for the circumference. -Measure the distance between the centers of the right and left wheels to find the width. - -{{}} - -Now let’s add a camera to watch the video stream on the control panel as you move your rover. - -### Camera configuration - -Add your USB camera as a webcam. -Please refer to [our webcam documentation](/components/camera/webcam/) for complete instructions. - -{{}} - -If you go back to the **Control** tab and click to expand the base panel, you will see your base and camera: - -{{}} - -Toggle the switch under **Keyboard Disabled** to enable keyboard control, then use the W, A, S, and D keys on your keyboard to move your rover around. -You can view the camera stream at the same time. - -### Final config - -The full raw JSON config file generated by the configuration steps you just completed will look like this: - -{{% expand "Click to view the raw JSON for the dart launcher robot" %}} - -```json -{ - "components": [ - { - "name": "local", - "model": "pi", - "type": "board", - "namespace": "rdk", - "attributes": {}, - "depends_on": [] - }, - { - "name": "left", - "model": "gpio", - "type": "motor", - "namespace": "rdk", - "attributes": { - "pins": { - "a": "11", - "b": "13", - "pwm": "" - }, - "board": "local", - "max_rpm": 150 - }, - "depends_on": [] - }, - { - "name": "right", - "model": "gpio", - "type": "motor", - "namespace": "rdk", - "attributes": { - "pins": { - "a": "16", - "b": "18", - "pwm": "" - }, - "board": "local", - "max_rpm": 150 - }, - "depends_on": [] - }, - { - "name": "base", - "model": "wheeled", - "type": "base", - "namespace": "rdk", - "attributes": { - "width_mm": 130, - "wheel_circumference_mm": 200, - "left": ["left"], - "right": ["right"] - }, - "depends_on": [] - }, - { - "name": "camera", - "model": "webcam", - "type": "camera", - "namespace": "rdk", - "attributes": { - "video_path": "video0" - }, - "depends_on": [] - } - ] -} -``` - -{{% /expand %}} - -If you prefer you can copy paste it, replacing the **Raw JSON** field on your machine's **Config** tab instead of going through all the steps above. - -## Toggling GPIO pin states - -The board card in the **Control** tab provides a way to change the state of the pin connected to the solenoid. -If you click the board component, you will be able to see your GPIO pin and its current state. -In the **Set** part of the GPIO section, select pin **37** (the pin we wired to control the solenoid). -If you set the pin state to high, the solenoid will actuate. -If you set it to low, it should deactivate the solenoid. -Since we already assembled the robot, setting pin 37 to **high** launches your foam dart launcher if its loaded. - -{{< figure src="/tutorials/foam-dart-launcher/board-low.png" alt="Board component, G P I O section showing Low selected on the Pin State dropdown." title="Board component, GPIO section showing Low selected on the Pin State dropdown" width="800">}} - -{{< figure src="/tutorials/foam-dart-launcher/board-displaying-high.png" alt="Board component, G P I O section with pin 37 set to High." title="Board component, GPIO section with pin 37 set to High." width="800">}} - -{{< figure src="/tutorials/foam-dart-launcher/board-high.png" alt="Board component, G P I O section showing High selected on the Pin State dropdown." title="Board component, GPIO section showing High selected on the Pin State dropdown" width="800">}} - -## Control with the Viam app - -### Controlling the base - -1. Navigate to Viam app -> base component -2. Enable keyboard controls -3. Drive your robot around! - -### Activating the foam dart launcher - -1. Make sure your foam dart launcher is loaded and ready to go. -2. When you are ready, navigate to the Viam app -> **Control** tab -> board component and set the **IN** pin (pin 37 in our example) to high to activate. - -You can see the demo video of it in action here: - -{{