2021W1 – Lab 5: Building your bot

Learning Goals

For the rest of the labs, including this one, we will be building and programming robots. This lab, you and your team will build a fully functioning, autonomous, robot vehicle. You will try to get the robot to move forward, left, right, and backwards. By the end of the four labs, you will have an autonomous vehicle that can follow other robots, line track and navigate walls and obstacles. Below are examples from past offerings of COGS 300 of the kind of robot you will be making.

Pre-Lab

  1. Review the instructions below about how to build a robot.
  2. You may want bring in a multi-tool to your lab (if you own one). This is not a requirement but it can prove to be extremely useful.
  3. Supplies to give your robot a costume are also encouraged, but optional.

Lab

Part 1: Building the chassis

One person on your team can start by attaching the freely rotating swivel wheel to the chassis. The others should look at the next part and start hooking up the motors. Note: the swivel wheel uses eight short bolts and four offset nuts.

Part 2: Hooking up the motors

Insert hookup wires into the copper loops on the motor. Note: do not use your jumper wires which have plastic parts with pins, but instead use the loose hookup wire we have provided.

Secure your motors by twisting the wires but NOT the copper loops. Be careful not to damage the loops! Note: if you’re having difficulties keeping the connection, your TA may be able to help you LATER by soldering your connection.

Find a motor driver. Hook both motors up to the motor driver by turning the screws in the green clamps to the left. Then insert the wires from the motors to the green clamps and turn the screws to the right to clamp down.

After attaching the wires from the motors to the motor driver, attach the motor driver to your Arduino. Follow this configuration:

Right motor to Motor_A:

  •  A_1A to Digital 8
  •  A_1B to Digital 9

Left motor to Motor_B:

  • B_1A to Digital 4
  • B_1B to Digital 5

Then:

  • VCC to power 5V
  • gnd to gnd

 

Part 3: Attaching the motors to the chassis

Again, best if one or two members of the team do this part while the others test the motors (next part).

Assemble the motor bracket by using two long bolts and corresponding short nuts. Orient the motors such that the leads are pointing towards the swivel wheel:

You can add the tires to the motors once they are secured to the chassis.

Part 4: Testing the motors

Ensure that your motors are working by adapting the code from the template provided below. Decide which direction is the front of the robot (suggest: swivel wheel at the back). You may want to swap the wires in the motor driver to ensure that motors are consistent in their directionality. Make sure you the motors can consistently go forwards and backwards.

Part 5: Drive straight, backwards, and turn

Define functions for driving straight, backwards, and turning left and right. You may want to play with these functions and adapt them to your needs. For example, you could define a turn where one wheel stops and the other rotates. But you could also define a turn where one wheel turns at a different speed than the other, or even a turn where one wheel turns one direction and the other turns the opposite direction. Play with your robot and see what makes sense for you.

Optional challenge

Temporarily add an ultrasonic sensor to the front of your robot. Next lab, we will be adding at least two ultrasonic sensors, so don’t make the position permanent yet. Define a function to make the robot come towards your hand and stop at a particular distance. Can you make the robot go both backwards and forwards away from your hand? Try a PID controller if you’re feeling very ambitious.

 

Optional starter code

Common Debugging

  • Is it a hardware or a software error?
  • Is your wiring okay? (Be especially careful of your motor driver wires falling out!)
  • Have you tried restarting?
  • Try power cycling if normal restarting isn’t working

Proof of Success (For Motivation!)

Line Tracking

Line Tracking & Stops at Wall 

Line Tracking & Turns at Wall, Stops Line Tracking