---
title: "Activity: Claw Attachment"
date: "2023-07-31"
categories: ["Activities", "All", "Simulator Activities"]
tags: ["Colour Sensors", "Branching", "Iteration", "Algorithm Design", "Advanced"]
excerpt: "Use the claw to grab the Meloncube and perform delivery tasks in a warehouse scenario. Use the colour sensors on the robot to read colour codes for delivery instructions. SetupThe initial activity can be to have an indicator line on the"
featuredImage: "/images/resources/activity-claw-attachment.jpg"
---

Use the claw to grab the Meloncube and perform delivery tasks in a warehouse scenario. Use the colour sensors on the robot to read colour codes for delivery instructions.

### Setup

The initial activity can be to have an indicator line on the ground using tape, which the robot starts behind. The Meloncube can be placed 30cm in front of this line, and students can be tasked to grab the cube and bring it back over the line. Depots can then be introduced to create a warehouse scenario.

Any object can be used in place of our Meloncube, however, if you wish to use it, head on over to Printables or Thingiverse to download the print file:

    [
      Printables: MelonCube
    ](https://www.printables.com/model/639390-micromelon-meloncube)

    [
      Thingiverse: MelonCube
    ](https://www.thingiverse.com/thing:6284246)

Depots are walled square areas for the rover to deposit a Meloncube in. The walls can be constructed from tape on the ground or solid materials in a 20cm x 15cm area. Use the diagrams below as a reference for the layout of the depots. A number can be allocated to each depot, and students can deliver the cube to each depot on demand.

Add coloured tape to the previous challenge to add more complexity. The tape could indicate which depot the cube must be delivered to. The rover can use the colour sensor to detect the colour of the tape and use the appropriate delivery instructions. A final extension challenge is leaving the cube in one of the depots and having the rover retrieve it and put it behind the indicator line.

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/65619701-0e77-46fb-92db-9d8b4d9531d9/Activity+1.PNG)

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/e520af9d-d7d9-4216-94a6-7907bcfbed04/Activity+2.PNG)

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/2612060c-142e-43c1-95bf-89720ef254ad/Activity+3.PNG)

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/6ceb0a5e-7715-408e-b51a-95ffea1fdfec/Challenge.PNG)

### Here’s Our Approach

**Constant - **A constant is a variable that never changes when the code is run. In python, we write this in all capitals with underscores between words.

#### 1) Setting the Constants:

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/28f3a018-8334-4ca7-9962-bb39221d8703/Constants.png)

Start by defining two constants: the servo claw open and close positions. Trial and error will have to be used to find the correct settings for your rover.

#### 2) Grab and Release:

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/40c9fd43-023e-4be9-a230-f4d55ee98e77/Functions.jpg)

Next, make two functions for ‘*grab*’ and ‘*release’. *While these functions only have the ‘Move Servo’ block, doing this makes it easier to understand the code.

#### **3) Data Input:**

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/d711d1c8-53ae-4124-9848-b5a73b82ada6/Input.png)

In the main code, we’ll make a variable named ‘Input’, which will request the depot number to deliver the cube.

If you’re using colour indicators instead, the input request can be replaced with an ‘if else’ statement that detects the colour and sets the input to a depot number.

#### **4) Secure the Cube:**

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/0954bd9f-a08b-46ca-b6cb-addfe659951b/move.png)

Once the robot has acquired the delivery instructions, the robot will approach the cube and use the ‘*grab*‘ function to pick up the meloncube.

#### 5) Delivering the Cube:

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/c682d5c0-13b9-41b2-937d-c28b673ff06b/Depot.png)

Depending on how your depots are set up, create delivery instructions using movement blocks to deliver the cube. Finish off the code by releasing the cube.

#### Complete Code:

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/deca8e70-c92c-47b5-9b0f-793819dd193f/Capture.PNG)

**Tip: **

You can add tracks on the ground for the rover to line-follow or create maze walls to allow the use of the IR sensors for navigation.

### Related Posts

          Resources

      [

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1639455538805-9NI7CPKR7IYG6D4RBKAN/high+quality+sumo.png)

  ](/resources/creating-a-sumo-unit)

	[All](/resources?category=All)

                [Creating A Sumo Unit For Your Digital Technologies Class](/resources/creating-a-sumo-unit)

	[All](/resources?category=All)

How to run a sumo unit in your digital technologies classroom.

                [Read More &#8594;](/resources/creating-a-sumo-unit)

	[All](/resources?category=All)

      [

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1637464845856-BBPD7GTIIHHOSJCFORWF/the+ultrasonic+sensor.png)

  ](/resources/ultrasonic-sensor)

	[All](/resources?category=All), [Guides](/resources?category=Guides)

                [The Ultrasonic Sensor](/resources/ultrasonic-sensor)

	[All](/resources?category=All), [Guides](/resources?category=Guides)

Learn all about the ultrasonic sensor!

                [Read More &#8594;](/resources/ultrasonic-sensor)

	[All](/resources?category=All), [Guides](/resources?category=Guides)

      [

![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1625616494179-LZHZP5MUA0E0MQKEB7HC/cropped+image+4.png)

  ](/resources/year-7-digital-tech-at-st-peters)

	[All](/resources?category=All), [Customer Stories](/resources?category=Customer+Stories)

                [Case Study: Year 7 Digital Tech at St Peters Lutheran College](/resources/year-7-digital-tech-at-st-peters)

	[All](/resources?category=All), [Customer Stories](/resources?category=Customer+Stories)

See how Meg Foley at St Peters conducted a challenge for their Year 7s using Micromelon.

                [Read More &#8594;](/resources/year-7-digital-tech-at-st-peters)

	[All](/resources?category=All), [Customer Stories](/resources?category=Customer+Stories)
