Chapter 5: Building a Scorpion

Biomimicry is the study and application of creating products, systems, mechanisms, and solutions to problems based on biological processes and functions found in nature. It is incredible what we can learn from plants and animals to find solutions to our own problems.

One of the many fascinating animals on our planet is the scorpion, a creature that has some features perfect for robot building. In this chapter, you are going to build a scorpion robot designed around the famous features of this creature. In particular, you will be building the stinger and a body style similar to that of a scorpion, along with some additional features that the kit provides.

Here's what your build will look like by the end of this chapter:

Figure 5.1 – Completed Build

Figure 5.1 – Completed Build

In this chapter, we will break down the build and program into the following sections:

  • Building the scorpion body
  • Building the tail
  • Adding the color sensor detection triggers
  • Building the scorpion claws
  • Building the scorpion exoskeleton
  • Designing the tail
  • Writing the code
  • Making it your own

Technical requirements

For the building of the robot, all you will need is the Robot Inventor kit. For programming, you will need the LEGO MINDSTORMS app/software.

Access to the code for this chapter can be found here:

App code:

https://github.com/PacktPublishing/Smart-Robotics-with-LEGO-MINDSTORMS-Robot-Inventor/blob/main/Chapter%205%20Scorpion%20Controller%20Code.lms

Sensor code:

https://github.com/PacktPublishing/Smart-Robotics-with-LEGO-MINDSTORMS-Robot-Inventor/blob/main/Chapter%205%20Scorpion%20Sensor%20Code.lms

If you would like a more detailed photo-by-photo build process of the robot, please head here to view the images: https://bit.ly/3rNjwkY.

Building the scorpion body

The beauty of this robotics kit is that you can easily get started with any type of build because of the new pieces that are included. You are going to use the large LEGO 11x19 teal base plate as the main frame of the scorpion. This will be a vital piece where you will add motors to the wheels for movement, along with adding the entire top build of the scorpion. As with many builds in this book, you are utilizing this element to provide a base plate to hold everything together in a solid structure and format.

You can see what the base plate looks like in the following image:

Figure 5.2 – Starting with teal base plate

Figure 5.2 – Starting with teal base plate

One of the LEGO pieces not found in this kit is a LEGO Technic Steel Ball Caster ball, or even the plastic version found in the SPIKE Prime kit. You will have to design a new way to operate your robot. What a wonderful design challenge! While there are plenty of wheels to use, a scorpion does not look like a scorpion if it is all decked out with wheels. You will use two wheels and then hide the other wheels underneath. This build will have you use a modified version of the two tiny wheels used in the software build model named Tricky. You need your robot to be able to pivot and rotate when sensing danger, so this is a nice adaptation since you don't have the caster ball that would make this very easy to do.

Establishing the the base

Let's start off by getting the wheels attached to the bottom of the base and adding the Intelligent Hub. You will need the following pieces:

  • Two brown 5L axles with stop
  • One white axle connector
  • Two white pin axle connectors
  • Two tan axle pins
  • Two black 2L round connectors
  • Two black smooth wheels
  • Two black axle connector pin perpendicular double pieces

The required pieces can be seen in the following image:

Figure 5.3 – Layout of how the parts go together for wheels

Figure 5.3 – Layout of how the parts go together for wheels

The preceding image shows a basic flow of how to connect all the pieces. To start, slide the black axle and connector pin perpendicular double piece onto each of the brown axles through one of the pin holes. Add a tan axle pin into the axle hole of this piece.

The result can be seen in the following image:

Figure 5.4 – Building two of the same builds and putting them together

Figure 5.4 – Building two of the same builds and putting them together

After you add this part, then add the smooth wheel onto each axle, followed by the black round connector. You should now have enough of the brown axle left to connect the two sides together using the white axle connector, as illustrated in the following image:

Figure 5.5 – Wheels joined together

Figure 5.5 – Wheels joined together

Finally, add the white connector pins to each of the tan pins for this part to be completed. You can see the result in the following image:

Figure 5.6 – White connector pins added to be able to join to base plate

Figure 5.6 – White connector pins added to be able to join to base plate

Next, you will need the following parts to build up the frame for the wheels:

  • Two blue connector pins
  • Four black connector pins
  • Three black 11L beams

The required pieces can be seen in the following image:

Figure 5.7 – Building leverage for leveled height of robot

Figure 5.7 – Building leverage for leveled height of robot

You will build a bit of a base to level the scorpion build. To do this, start by adding the two blue connector pins to one of the black 11L beams into the third pin hole on either side. Connect another black beam and add one black connector pin to this second beam. Lastly, add another black beam with another three black connector pins (see Figure 5.7 for the placement of black connector pins). This stack of three beams will connect to the wheel build you just completed, as illustrated in the following image:

Figure 5.8 – Wheels and leveler piece together

Figure 5.8 – Wheels and leveler piece together

This part will be added to the teal base plate at the edge of the piece, as follows:

Figure 5.9 – Back wheels added to teal plate

Figure 5.9 – Back wheels added to teal plate

Let's now add the motors. You will need the following pieces:

  • Two motors
  • Ten black connector pins
  • Two black rubber tire wheels
  • Four gray connector pins with bushings

First, attach the wheels to each of the motors using two gray connector pins with bushings. Proceed to add five black connector pins to each of the motors, placing four pins by the wheels and one to the inside pin hole on the back, as illustrated in the following image:

Figure 5.10 – Preparing the motors

Figure 5.10 – Preparing the motors

You will add the motors to the opposite side of where you added the wheel build on the teal base plate, as illustrated in the following image:

Figure 5.11 – Motors and wheels added to base plate

Figure 5.11 – Motors and wheels added to base plate

Flip this over to ensure your build is level and that everything is securely connected. It should look like this:

Figure 5.12 – Base plate should be level

Figure 5.12 – Base plate should be level

For the next part, you will need the following pieces:

  • One Intelligent Hub
  • Four black connector pins
  • Two wire connectors

Add four black connector pins to the underside of the Intelligent Hub, as follows:

Figure 5.13 – Intelligent Hub prep

Figure 5.13 – Intelligent Hub prep

Attach the Intelligent Hub to the teal base plate. You will add the Intelligent Hub to the third pin hole from the end of the teal base plate, opposite where the wheels are attached. Once you do that, go ahead and secure the wires so that they are not sticking out. The result should look like this:

Figure 5.14 – Intelligent Hub added along with wire clips

Figure 5.14 – Intelligent Hub added along with wire clips

From the other angle, you should have a nice tight-looking build up until this point. You can see what it looks like from the back to see how the wires can be tucked away, as illustrated in the following image:

Figure 5.15 – Back view of the robot

Figure 5.15 – Back view of the robot

The base is now complete and the main body is ready to move. It is now time to add the next parts to our scorpion.

Building the tail

Our next step is to add motors three and four to the sides. You are going to use two motors for an equal balance of the body. This will also allow the tail to be strongly held to the body of the robot.

To get started, you will need the following pieces:

  • Two motors
  • Four black connector pins
  • Two white perpendicular connector pins
  • Four wire clips
  • Two blue connector pins
  • Two black 11L beams
  • One distance sensor
  • Two black round elbow connectors
  • Four blue axle pins

Using two black connector pins for each motor, attach the motors to the sides of the teal base plate, as follows:

Figure 5.16 – Side motors for the tail

Figure 5.16 – Side motors for the tail

Next, insert a white perpendicular connector pin to each of the motors on the top of each motor on the edge, as follows:

Figure 5.17 – White connector pin added to top of each motor

Figure 5.17 – White connector pin added to top of each motor

This is also a great time to use the wire clips to organize your wires. Later on, this might be a bit tricky to go back and do. Organization early on is always important, especially as you work in some tight spaces. The wire clips can be seen in the following image:

Figure 5.18 – Using the wire clips to help with wire management

Figure 5.18 – Using the wire clips to help with wire management

This is also a good time to connect both of your motors to your Intelligent Hub. You will want to plug your motors to the following ports:

  • Tail motors motors are plugged into ports A and E
  • Wheel motors are plugged into ports B (left wheel) and F (right wheel)

You can see a side view of the build here:

Figure 5.19 – Side view of robot build

Figure 5.19 – Side view of robot build

Finally, you will extend the back side with two beams to allow proper room for the distance sensor to be added to the back. Use the two blue connector pins to attach the two black 11L beams to the back of the robot, as illustrated in the following image:

Figure 5.20 – Black beams to extend the back of robot

Figure 5.20 – Black beams to extend the back of robot

Once you have the blue connector pins inserted on the two black beams, go ahead and add them to the back of the teal base plate. They will stand out a bit at the back at this point, but it will all come together in later steps.

At this point, your build should look like this:

Figure 5.21 – Black beams added for the sensor

Figure 5.21 – Black beams added for the sensor

You now add the distance sensor to detect any movement from behind, using the black round elbow connectors to secure the back of the sensor. The black round elbow connectors will attach to the teal base plate, using two blue axle pins. You will plug this sensor into port C. The result should look like this:

Figure 5.22 – Sensor attached with black elbow connector pins

Figure 5.22 – Sensor attached with black elbow connector pins

Here is what the back of the robot should look like at this point in time:

Figure 5.23 – Sensor added to the teal base plate and rest on black beams

Figure 5.23 – Sensor added to the teal base plate and rest on black beams

Now that you have the distance sensors added and the base of the robot is all assembled, let's proceed with adding the color sensor to help the scorpion robot respond to its environment.

Connecting the color sensor

Let's head to the front of the scorpion and get our color sensor in place. This sensor will detect any creature that moves too close to the scorpion and will be dealt an attack with the deadly stinger.

You will notice that you are securing both sensors (distance and color) with the black, round, 90-degree elbow pieces to attach from behind, giving us space on the sides to expand our builds later.

You will need the following pieces:

  • Two black round elbow connectors
  • Four blue axle pins
  • One color sensor
  • Two teal 3L beams
  • One teal 9L beam
  • Six black connector pins

The required pieces can be seen in the following image:

Figure 5.24 – Layout of parts

Figure 5.24 – Layout of parts

To begin this section, add the blue axle pins to the black round elbow connectors, as illustrated in the following image:

Figure 5.25 – Prep for the color sensor

Figure 5.25 – Prep for the color sensor

Attach these to the back of the color sensor and then attach the color sensor to the front of the robot build, as follows:

Figure 5.26 – Color sensor attached using black round elbow connector

Figure 5.26 – Color sensor attached using black round elbow connector

Prep your teal beams. Add two black connector pins to each of the teal 3L beams. Add two more pins to the ends of the 9L teal beam.

The result can be seen in the following image:

Figure 5.27 – Parts to secure the color sensor

Figure 5.27 – Parts to secure the color sensor

Install one of the 3L beam to either side of the color sensor to help hold it in place. Add the 9L beam to the front of the teal base plate. You will also plug the color sensor into port D.

The result should look like this:

Figure 5.28 – 3L beams added to sides of color sensor

Figure 5.28 – 3L beams added to sides of color sensor

Once the sensors are in place, it's now time to begin to bring the scorpion to life. To do this, you will need the following pieces:

  • Two gray connector perpendicular pins
  • Two teal 3L beams
  • Eight black connector pins
  • Three black 5x7 open frames
  • Two black 3x5 L beams

Take two of the black 5x7 open frames. On one of the 7L sides, add a gray connector perpendicular pin. On the gray connector pin, attach a teal 3L beam. Finally, add a black connector pin to the middle pin hole of the teal 3L beam.

The result should look like this:

Figure 5.29 – Open frame prep and setup

Figure 5.29 – Open frame prep and setup

Add each of these parts to both sides of the color sensor. Remember that there is already a teal 3L beam attached to either side of the color sensor. Add this part on top of that teal beam, as follows:

Figure 5.30 – Open frames added to top of 3L beam

Figure 5.30 – Open frames added to top of 3L beam

Locate your third 5x7 black open frame and add four black connector pins to each of the four corners, as illustrated in the following image:

Figure 5.31 – Open frame for the front of the robot

Figure 5.31 – Open frame for the front of the robot

Install this piece on the front of the robot. This will serve as a structure around the color sensor and will also secure the two open frames sitting on top of it.

The result should look like this:

Figure 5.32 – Open center frames joining the other two open frames

Figure 5.32 – Open center frames joining the other two open frames

The last part to this section of the robot is to add the two 3x5 L beams to the bottom of the front of the robot. Connect each one to the side of the open frame using a black connector pin, as illustrated in the following image:

Figure 5.33 – Front view of robot at this point of the build

Figure 5.33 – Front view of robot at this point of the build

You now have the color sensor installed, but at this point it is not functional. You need to add some triggers to help the color sensor trigger commands in the code, so in the next part, you will build and install the color sensor triggers for your robot.

Adding the color sensor detection triggers

Now that you have installed the sensors, you have to find a way to activate the scorpion as it would act and behave when feeling threatened. In this build, you will use red and yellow 3L beams to create a trigger in our code so that when something bumps into the scorpion from the front, it will go into attack mode by lunging its tail forward toward the enemy. Through the use of pins and rubber bands, you can create a trigger mechanism that will push the red and yellow pieces forward to activate the color sensor.

When nothing is pressing on these elements, the rubber bands will pull them back to their original starting position.

You will need the following pieces:

  • Two yellow 3L beams
  • Two red 3L beams
  • Two black 3x7 angular beams
  • Two blue connector pins
  • Two tan axle pins
  • Two gray axle pins
  • Two gray bush stops
  • Two gray connector pins with bush stops

In the following screenshot, you can see how to build two of these triggers. Both will be built the same way but with the bush stops being on the outside of the black 3x7 angular beam.

The red beams will go on the left side (if the robot is facing you, it will be on your left) and the yellow beams to your right.

To build this these triggerstrigger mechanism, start with a 3x7 angular black beam. To the inside of the beam, connect the 3L beams using a blue connector pin and gray axle pin. On the outside, add a tan axle pin and attach the bush stop to the axle side of that pin.

The result can be seen in the following image:

Figure 5.34 – Layout for color sensor triggers

Figure 5.34 – Layout for color sensor triggers

When both parts are built, you should have the following:

Figure 5.35 – Completed sensor triggers

Figure 5.35 – Completed sensor triggers

Attach each of these parts using the gray connector pins with bush stops by connecting to the underside of the corner of the open frames. These triggers will activate the color sensor when pushed into the view of the color sensor.

Your build should now look like this:

Figure 5.36 – Triggers added to the robot

Figure 5.36 – Triggers added to the robot

A key detail to this part of the build process lies within the build component that contains the yellow and red elements. When you attach these parts to the open frames with the gray pins with bush stops, you will connect the triggers from the corner of the open frame and the third hole on the 3x7 angular beam.

It is now time to expand your use of the elements to build out the claws. These claws don't move, but what they do is capture whatever is in the path of the scorpion and force it toward the center. As your scorpion moves forward, the claws funnel the creature to the triggers awaiting the attack!

Before you build the claws, let's finish up the trigger part of this build by adding the rubber bands and a few additional parts.

You will need the following pieces:

  • Two white rubber bands
  • Six black connector pins
  • Two black 11L beams
  • Two blue axle pins
  • Two gray bush stops

Begin by adding three black connector pins to each of the black 11L beams, as illustrated in the following image:

Figure 5.37 – Beams to add to the open frames

Figure 5.37 – Beams to add to the open frames

Attach both of these to the sides of the open frames, as follows:

Figure 5.38 – Beams added to the open frames

Figure 5.38 – Beams added to the open frames

Check the alignment of your beams just added to the side. The next image provides a side view to help you check better:

Figure 5.39 – Side view of the robot

Figure 5.39 – Side view of the robot

On each side, add a blue axle pin with a bush stop added to the axle side of the pin. Install this piece on the third pin hole from the end of the black 11L beam, as illustrated in the following image:

Figure 5.40 – Bush stop added to side for the rubber bands to wrap around

Figure 5.40 – Bush stop added to side for the rubber bands to wrap around

Take your two rubber bands and stretch them around the gray bush stop you just added to the side and to the other bush stop on top of the color sensor trigger, as illustrated in the following image:

Figure 5.41 – Rubber bands added for triggers for color sensor

Figure 5.41 – Rubber bands added for triggers for color sensor

You should be able to press the triggers toward the color sensor, and when you let go they should pop back to their original position.

You can continue on to build the claws now that the trigger elements are working.

Building the scorpion claws

You will need the following pieces:

  • Two black double-bent beams
  • Two black round elbow connectors
  • Four blue axle pins

Start with the two black round elbow connectors. Add a blue axle pin to both sides of each of the black round elbow connectors. Add one of each to the black double-bent beams on the second hole of the long part of the beam, as illustrated in the following image:

Figure 5.42 – Building out the first part of the claws

Figure 5.42 – Building out the first part of the claws

Each of these will then connect to the 11L black beam on the sides of the robot using the fourth pin hole.

Next, locate the following parts:

  • Two black double-bent beams
  • Six blue axle connector pins
  • Two white axle connectors
  • Two black 90-degree axle pins
  • Two black connector pins
  • Two black 3L beams

Again, you will build two of the same parts for each side of the robot. Begin by adding a blue connector pin to the pin hole right before the first bend of the black beam. On the opposite side of the beam, add one of the 90-degree axle pins to the end of the beam. Slide on a white connector and then add a blue connector pin to the other end of the white connector, as illustrated in the following image:

Figure 5.43 – Build for second frame of the claws

Figure 5.43 – Build for second frame of the claws

These two pieces will attach to the very last pin hole of the 11L beam on the robot. This will connect to the previous black double-bent beam using a blue connector pin, as illustrated in the following image:

Figure 5.44 – Pins for the claws

Figure 5.44 – Pins for the claws

On the end of the double-bent beam you just installed, add a blue axle connector pin and black connector pin. Then, attach a 3L black beam to each of the ends.

The result should look like this:

Figure 5.45 – 3L beams added to pins

Figure 5.45 – 3L beams added to pins

Finally, you need to build the claws. You will need the following pieces:

  • Four small white angled panels
  • Two black 3L beams
  • Four black connector pins
  • Two blue connector pins
  • Two white connector pins with pin hole

Let's continue by starting with the blue connector pins. Add each blue pin through the white connector pin. Use this piece to then attach the two white angled panels on either side to build the look of the claw. Next, secure these pieces in place using a black 3L beam and two black connector pins to hold them in place.

You will build two of these claws. They should look like this:

Figure 5.46 – Claw builds

Figure 5.46 – Claw builds

Each of these claws will then be added to the pin hole on the 3L black beam that is on the end of each of the robot arms, as illustrated in the following image:

Figure 5.47 – Claws added to robot

Figure 5.47 – Claws added to robot

This is how the claws look from the top:

Figure 5.48 – Top view of the claws

Figure 5.48 – Top view of the claws

Before moving on to the next step, ensure your pins are strong and that the elements are in a good sound structure. You might need to check that your pins are properly secured. The claws will have some movement based on the design but should not fall off or break with some contact.

Building the scorpion's exoskeleton

You will now use many of the white elements typically used for vehicles and robot body designs to create the look of a scorpion. Additionally, these pieces help secure the build and hide wires underneath to give the build a sleeker look. You will notice there are some wire clips used on the sides of the Intelligent Hub, so be sure to use these as you build to hide as much of the wire as you can.

You will now finish up the frame of the robot by adding the head and some structural elements before moving into the final details of the build.

You will need the following pieces:

  • One white 13L beam
  • Eight black connector pins
  • Two white panels
  • Four white pins with friction ridges
  • One curved white panel
  • One small curved white panel
  • Two gray connector pins with bush stops
  • Two red axle pins
  • Two teal round axle connectors

Begin by adding a black connector pin to each end of the 13L beam. Attach this piece to the open frames on the top of the robot. This will provide additional support and help to build out the exoskeleton of the scorpion.

The result should look like this:

Figure 5.49 – White beams provide structure to open frames

Figure 5.49 – White beams provide structure to open frames

Next, add a white pin with friction ridges piece to either side of the white panel piece using black connector pins, as illustrated in the following image:

Figure 5.50 – White panel prep

Figure 5.50 – White panel prep

This piece will then be added to the top of the robot body. Using the white pins, you will connect to the open frame and have it line up with the 13L white beam you just added in the previous step, as illustrated in the following image:

Figure 5.51 – White panel on top of robot

Figure 5.51 – White panel on top of robot

Next, add a white connector pin to either side of your small white curved panel piece using black connector pins, as follows:

Figure 5.52 – Small curved panel to be added for the exoskeleton

Figure 5.52 – Small curved panel to be added for the exoskeleton

This piece will be installed on the robot on top of the open frame that sits at the front of the robot. You will connect it using the white pins and installing it onto the white panel piece you just added in the previous step.

The result should look like this:

Figure 5.53 – White panel on top of open frame

Figure 5.53 – White panel on top of open frame

Next, add a gray connector pin with bush stops to the holes on the small curved white panel at the front of the robot. Insert a red axle connector to the bush stop of the gray connector pin. Add a round teal axle connector to give a look of scorpion's eyes, as illustrated in the following image:

Figure 5.54 – Scorpion eyes

Figure 5.54 – Scorpion eyes

Here is a side view of the robot at this point in the build:

Figure 5.55 – Side view of exoskeleton

Figure 5.55 – Side view of exoskeleton

Looking at the side of the robot, you will now use two black connector pins to add another white panel to the curved white panel that has the eyes installed, as illustrated in the following image:

Figure 5.56 – Another white panel added behind the curved panel

Figure 5.56 – Another white panel added behind the curved panel

Using two more black connector pins, add another curved white panel to smooth the build down to the Intelligent Hub, as illustrated in the following image:

Figure 5.57 – White panels in place for exoskeleton

Figure 5.57 – White panels in place for exoskeleton

The body of the scorpion is now complete with an exoskeleton. You now need to move into the key feature of the scorpion: the tail. Let's get to the tail build so that we can protect our robot!

Designing the tail

To design the tail, we will have to build a frame first around the distance sensor. This frame will help stabilize the tail that you are about to build. As your scorpion attacks, moves, swings, and seeks out prey, you need to make sure the tail does not drop low and trigger your distance sensor, or else you will have one strange-acting animal!

Adding this frame is a perfect fit that still does not take away from the body while providing support and helping the tail stay in place.

To build the frame, you will need the following pieces:

  • One black 7x11 open frame
  • Four black connector pins
  • Two teal 3x5 L beams
  • 2 gray connector pins with bush stops

Begin this build component by adding the 3x5 teal beams to the inside of the open frame using the black connector pins, as illustrated in the following image:

Figure 5.58 – Open frame with teal L beams

Figure 5.58 – Open frame with teal L beams

Add this piece by connecting the 3x5 L beams to the pin hole on the side of the distance sensor and using the gray connector pins with bush stops on the front, as illustrated in the following image:

Figure 5.59 – Adding open frame around distance sensor

Figure 5.59 – Adding open frame around distance sensor

Let's build the tail. To do this, you will need the following pieces:

  • Two curved white panels
  • Nine black connector pins
  • Two medium-angled white panels
  • Three blue connector pins
  • One blue axle pin
  • One teal 2x4 L beam
  • One teal 5L beam
  • One black 7L beam
  • One white 13L beam

Start by adding two black connector pins to one end of the two curved white panels, as follows:

Figure 5.60 – Beginning parts of the tail

Figure 5.60 – Beginning parts of the tail

On each of the curved panels, Attach the medium-angled white panels to each of the curved panels, as follows:

Figure 5.61 – Extending the tail with white angled panels

Figure 5.61 – Extending the tail with white angled panels

With both pieces facing each other, add a white 13L beam between them and connect them together using three blue connector pins, one blue axle pin, and one black connector pin, as illustrated in the following image:

Figure 5.62 – White beam to connect white panels

Figure 5.62 – White beam to connect white panels

At the top of the piece, add one teal 2x4 L beam, as follows:

Figure 5.63 – Teal 2x4 L beam serves as the stinger

Figure 5.63 – Teal 2x4 L beam serves as the stinger

Hold this build together using a teal 5L beam and two black connector pins. Add two more black connector pins to the white curved panels. Add a black 7L beam connected to those black pins.

The result should look like this:

Figure 5.64 – Black beam to secure tail

Figure 5.64 – Black beam to secure tail

Locate the following pieces to build the attachment to connect the tail to the scorpion body:

  • Fourteen black connector pins
  • Two blue axle connectors
  • Two teal axle connectors with two pin holes
  • Three teal 9L beams
  • Two teal 5L beams
  • Two teal 3x5 L beams
  • Two teal 3L beams
  • Four blue connector pins

Start this part of the tail by adding two black connector pins at one end of two teal 9L beams, as illustrated in the following image:

Figure 5.65 – Teal beams to build tail connection to motors

Figure 5.65 – Teal beams to build tail connection to motors

Attach both of these pieces to the black beam on the tail, as illustrated in the following image:

Figure 5.66 – Teal beams added to tail

Figure 5.66 – Teal beams added to tail

Secure these pieces in place using another teal 9L beam and two black connector pins, as illustrated in the following image:

Figure 5.67– Another teal beam to secure the other beams

Figure 5.67– Another teal beam to secure the other beams

Add two black connector pins to each pin hole of the teal axle connector with two pin holes and add a blue axle connector to the axle hole, as illustrated in the following image:

Figure 5.68 – Prep for the tail attachment

Figure 5.68 – Prep for the tail attachment

Add these parts you just put together in Figure 5.68 to the ends of the teal beams and then attach a teal 5L beam to each end, as illustrated in the following image:

Figure 5.69 – Adding the teal 5L beams

Figure 5.69 – Adding the teal 5L beams

Using four more black connector pins, add two of them to each of the 3x5 L beams. Add these pieces to the 5L teal beam. Next, add two blue connector pins to the two 3L teal beams.

The result should look like this:

Figure 5.70 – Attaching L beams and the prep for 3L beams

Figure 5.70 – Attaching L beams and the prep for 3L beams

The final aspect of the tail is to build a system of elements that you can attach to the motors on the side of the scorpion. Keeping everything symmetrical is an important aspect of this build. Once it is completed, the tail looks awesome. It almost looks like a mini scorpion itself. Here is another view of the tail:

Figure 5.71 – Final view of the tail before adding to the motors

Figure 5.71 – Final view of the tail before adding to the motors

Now, it's time to attach the tail to the two motors. Check to make sure everything is secure and clicked into place. Once you have everything secured, it's time to write some code to make this scorpion come to life.

This is how the tail looks from behind:

Figure 5.72 – Rear view of the tail when raised

Figure 5.72 – Rear view of the tail when raised

Check that the tail moves up and down by gently moving it up and down with your hand. Your scorpion should now look like a scorpion. Check out the following image for a top view of the body:

Figure 5.73 – Aerial view of the build with the tail

Figure 5.73 – Aerial view of the build with the tail

You have now completed the build. You now have one incredible-looking scorpion. Let's head over to the coding platform to bring our scorpion to life. You will build two coding programs: one for self-control using the app, and an autonomous program.

Writing the code

You will be writing two programs for this build. The first program will allow the robot to move autonomously without any help from its human companion. The second program will be a program that will allow you to control the robot using the remote-control feature of the app.

Connecting sensors and motors to the ports

Before we get into the programming, let's make sure all motors and sensors are properly plugged into the Intelligent Hub. The two motors for the tail should be plugged into ports A and E. The two-wheel motors will be plugged into ports B and F. The left wheel will be in port B and the right wheel will be plugged into port F.

For the sensors, you will plug the distance sensor into port C. Finally, the color sensor will plug into port D.

Check all connections using the Port View in the software.

This view is reproduced here:

Figure 5.74 – Port View in the MINDSTORMS software

Figure 5.74 – Port View in the MINDSTORMS software

Now that you have all your motors and sensors properly plugged in, let's begin the coding journey to bring your scorpion to life.

Writing an autonomous robot program

This section is going to walk through the steps to write a program that will allow your scorpion to operate on its own using sensors and motors. The following steps will show you how to write this code:

  1. Open up the MINDSTORMS software.
  2. Click on Projects at the bottom of the menu bar.
  3. Scroll down to Other and click on Create New Project.
  4. Choose to make a Word Blocks program., as illustrated in the following screenshot:
    Figure 5.75 – Choosing Word Blocks option

    Figure 5.75 – Choosing Word Blocks option

    Once you select Word Blocks, you should now see the coding canvas begin to add your coding blocks. This is illustrated in the following screenshot:

    Figure 5.76 – Here is our coding screen once you are ready

    Figure 5.76 – Here is our coding screen once you are ready

  5. Under the Events block, when when the program starts, you want to turn on some lights on the robot, just to give you a foundation as you build out the code. You will head to the purple section for light commands and turn on the distance sensor lights along with the 5x5 pixels on the Intelligent Hub. You will use blue so that you can use other colors later to indicate an alarmed or triggered state for the scorpion.

    In this sample code, a pixel version of a scorpion has been designed, but you can design any pattern you wish.

    Here is the code to activate the lights:

    Figure 5.77 – Code to activate lights!

    Figure 5.77 – Code to activate lights!

  6. The next step is to program the robot to react when the distance sensor detects an object in close proximity. To do this, you will start with a block from the Events section and bring over the distance sensor block. Then, you will adjust the proximity. In this example, we use the % option of 15%, but you can adjust this to your liking or use centimeters or inches if you would rather use a specific distance.
  7. With this block, you can then decide what you want to happen when an object gets too close to the back of our scorpion. You will use the pink Movement blocks to create an action of the scorpion quickly spinning around to face the object.
  8. You will need to set the movement motors to the wheels on ports F and B, then decide on the speed of the motors, and finally move to the right for 1.25 rotations to have the scorpion face the object.

    Important note

    Note that you will have to make subtle adjustments based on the speed of your motors, in addition to the surface you have the robot placed on.

  9. Following this command of spinning around, you need to have the scorpion move to a strike pose. You will use the tan Control blocks to create a repeat set of actions. The Movement blocks will activate the tail to strike twice by striking forward and backward twice before ending the loop and kicking out of this entire segment of code.

    The process is illustrated in the following screenshot:

    Figure 5.78 – Creating a behavior based on distance sensor sensing alarm

    Figure 5.78 – Creating a behavior based on distance sensor sensing alarm

  10. Your next step is to write code for when the color sensor is triggered. You will actually write the code for one color and simply duplicate the code and change to the other color. Let's start by using the color sensor block from the Events section of the blocks. Choose the correct port D and choose the red color. When the color sensor sees red, you then need to move the scorpion to alert mode. Add a light block, changing the pixels from blue to red to indicate danger!

    The process is illustrated in the following screenshot:

    Figure 5.79 – Color sensor activated seeing red

    Figure 5.79 – Color sensor activated seeing red

  11. After that, you will create another loop, just like you did in the distance sensor part of the code. You can right-click on the repeat block and choose duplicate. Drag those blocks over to this segment of code.

    The process is illustrated in the following screenshot:

    Figure 5.80 – Loop block

    Figure 5.80 – Loop block

  12. You will need to add one more section of code to make the scorpion retreat. Scorpions ideally don't like to be bothered even if they sting, so you will have to make the scorpion move backward and await the next sense of danger.

    The process is illustrated in the following screenshot:

    Figure 5.81 – Retreat blocks added

    Figure 5.81 – Retreat blocks added

  13. You will add some Movement blocks after the repeat segment. You need to assign the proper motors, dial in the speed, and then have the motors move the scorpion backward. In the build design of this robot, you have the motors programmed in a backward fashion, so you will program the motors forward to achieve a backward movement.

    The process is illustrated in the following screenshot:

    Figure 5.82 – Reset scorpion back to normal state

    Figure 5.82 – Reset scorpion back to normal state

  14. Next, you will change the light back to blue to await the next sense of danger, as illustrated in the following screenshot:
    Figure 5.83 – Reset color back to blue

    Figure 5.83 – Reset color back to blue

  15. Finally, you will duplicate this whole section of code and change from red to yellow so that either color detection will activate these actions, as illustrated in the following screenshot:
Figure 5.84 – Strike color sensor activated

Figure 5.84 – Strike color sensor activated

The following screenshot shows the entire code. The nice thing about this code is the opportunity to code the scorpion to behave as you wish, so have fun editing and remixing the actions to your own liking:

Figure 5.85 – Complete view of the program in MINDSTORMS software

Figure 5.85 – Complete view of the program in MINDSTORMS software

You have just completed one program where the scorpion operates on its own using sensors. Let's take a look at another way of programming the scorpion, using the remote-control feature of the app.

Writing a remote-control program

Additionally, you can write a program where you can use your phone or tablet to control the scorpion yourself. The following steps will show you how to write this code:

  1. Open up the MINDSTORMS software.
  2. Click on Projects at the bottom of the menu bar.
  3. Scroll down to Other and click on Create New Project.
  4. Choose to make a Word Blocks program., as illustrated in the following screenshot:
    Figure 5.86 – Choosing Word Blocks option

    Figure 5.86 – Choosing Word Blocks option

  5. Before you can activate the Remote Controller blocks, you have to turn on the commands you need. In order to do this, you must click on the joystick icon on the left of the screen. This will give you the screen needed to build your remote control. Once you are here, then need to select the edit icon, which is the pencil in the upper right-hand corner. This can be seen in the following screenshot:
    Figure 5.87 – Choosing the pencil icon to create your controller

    Figure 5.87 – Choosing the pencil icon to create your controller

  6. You need to select the blue plus (+) icon at the bottom of the screen to add the necessary widgets. In this project, you will select two of them: the Joystick and Button widgets. There is no need to code for the color or distance sensors with this project. Be sure to select the blue check to save your design.

    The widgets are shown in the following screenshot:

    Figure 5.88– Choosing the Joystick and Button widgets

    Figure 5.88– Choosing the Joystick and Button widgets

    You can also move the widgets around the grid to place them where you would like for your remote controller. Every person has preferences, so adjust this to your needs.

    An example layout is shown in the following screenshot:

    Figure 5.89 – Controller layout

    Figure 5.89 – Controller layout

  7. Now that you have the widgets selected, you now have command blocks under the teal Remote Control section of code. This code is pretty straightforward. You will have a code block for each direction, so you can essentially code one direction, then duplicate the chunk of code and edit the movement to the proper direction.
  8. A key movement to include is when the joystick is released to keep the robot still. If you don't add this option, your robot will continue to move until you turn it off or stop the code entirely.
  9. In terms of the button code, you are basically using the same code from the autonomous code outlined earlier to have the tail move back and forth with each button press.

    Here is a complete view of the controller program:

Figure 5.90 – Complete view of the controller program in the MINDSTORMS software

Figure 5.90 – Complete view of the controller program in the MINDSTORMS software

And now, you have a scorpion robot that can work autonomously or with a remote control. The joy now comes from tweaking the design and code to make your own unique style and design. Have fun!

Making it your own

You have been given the framework of an awesome scorpion. How could you add some unique features to make this build even better? How could you possibly combine this with another set of animal features for a super-hybrid creature?

More importantly, how will you tweak the code to have the robot behave differently? What more could be done? You have been given some starter code to have initial success, but your challenge is to take things to the next level! What will you do in a pinch? (Pun intended.)

Here are some ideas to think about to expand on this scorpion build:

  • Could you use the color or distance sensor in different ways?
  • For movement of the scorpion, could you use the gyro sensor built within the Intelligent Hub?
  • Could you explore a scissor mechanism for the tail or limbs?

Summary

In summary, you explored the concept of biomimicry, understanding how incredible animals are by building a scorpion. Aspects of a scorpion have been used in numerous robot builds and designs, from start-up companies to the National Aeronautics and Space Administration (NASA). Understanding how to use sensors to detect motion and movement to activate a strike is a great aspect to your learning. Additionally, showcasing two ways to operate the robot within the software is another nice touch to this kit as you can now think of many new ways to use this robot.

In the next chapter, you will explore a similar type of thinking and design but for a different purpose. You will enter the world of sumobots, making a robot that will battle the best of the best in sumo arenas. Let's go!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset