Skip to content

mit212/lab2_2025

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lab 2: 2-DoF Robot Assembly

2.12/2.120 Intro to Robotics
Spring 20251

1 Hardware Assembly

Below is an image of the 2-DoF robot arm you will assemble. Completing this section should take less than 20 minutes, so please ask for help if you feel like you are taking longer! We want you to have enough time to complete the remaining sections.

Figure 1

Materials:

Steps:

  1. Attach the 2 motors on either end of a single arm link (Fig. 2).

    Figure 2

  2. Add the hubs onto each shaft using 2 set screws (Fig. 3).

    Figure 3

  3. Attach the base made of 3 U-channels to one of the hubs (Fig. 4).

    Figure 4

  4. Attach a new arm to the other hub and attach the marker holder to the end of that arm if it is not already present (Fig. 5).

    Figure 5

  5. Use two clamps to hold the base down to the table. IMPORTANT: Ensure there is enough space for each arm link to move +/- 30° from the position when the arm is fully extended (both links are parallel) without hitting anything.

2 Wiring and Validation

Similar to Lab 1, we also need to wire and validate the microcontroller, motors, and encoders.

2.1 Microcontroller

  1. Plug the microcontroller in the breadboard so that the USB-C port is near the edge of the breadboard.

  2. Use solid wires to connect the 3.3V to both + rails and GND to both - rails.

    What is a rail?

    Rails on a breadboard refer to the two long strips labeled + and - on either side. They are typically located between red and blue lines parallel to the rails.

  3. Open the VSCode application. Click "File" on the upper-left corner then click "New Window".

  4. Clone this repository.

  5. Run blink_test.cpp. The onboard LED should change colors.

    How do I put the microcontroller in download mode again?

    Press and hold BOOT. Click RST while still holding down BOOT. Let go of BOOT.

2.2 Motors

  1. Wire the motors according to include/pinout.h. Remember to wire the GND pin of the motor driver to the - rail. Make sure that the motor ground wire is connected to the right of the terminal block, and the positive to the left (it should be the same order as the power supply pigtails).

    Can I see a wiring diagram? It is a good skill to be able to wire motors and sensors without an explicit wiring diagram. That being said, everyone in the class has different levels of experience with wiring components to microcontrollers. If your group is confused or needs guidance, feel free to take a look at the demo setup the TAs have built to see how the wiring was done.
  2. Connect the button/switch that has barrel jack connectors between the motor driver and the power supply. This should cut off the power supply's voltage when toggled, acting as an emergency stop.

  3. Reduce the power supply output to around 5.2V. Remember, the motors are powerful. Always keep the workspace clear of obstacles (laptops) and hold on to the power supply switch you just connected.

  4. Confirm that the motor driver has power. The green PWR LED should be on. If not, turn on the power supply switch.

  5. Push and hold the M1A, M1B, M2A, M2B buttons on the motor driver one at a time to check that the motors can spin in both directions. M1 should correspond to the motor attached to the base.

  6. Turn off the power supply switch. The power supply switch should always be off unless the motors need to move.

  7. Make the arm point straight up in full extension. This is the default position the arm should be in before running any code.

  8. Run motor_drive_test.cpp. You should see both motors turn slightly in both directions at two different speeds.

    Nothing is happening?

    Check that the motor driver has power by looking at the green PWR LED. If not, turn on the power supply switch.

  9. Turn off the power supply switch. The motor driver does not need power for the encoder wiring and validation.

2.3 Encoders

  1. Wire the encoders according to include/pinout.h. Use an extension cable for encoder 2.
  2. Use zip ties to attach the wires encoder 2 to link 1 so that M1 can rotate freely without snagging wires.
  3. Run encoder_basic_test.cpp and open the Serial Monitor. Observe which turn directions make the encoder count increase and think about why this is the case.
  4. Run encoder_test.cpp. Confirm that the position increases when turning link 1 counter-clockwise looking down at the table and decreases when turning link 2 counter-clockwise looking down at the table.
✅ CHECKOFF 1 ✅
Demonstrate encoder_test.cpp to a TA or LA!

3 Feedback Form

If you have any feedback, please fill out the form here: https://forms.gle/GXQCmbxuda3mm2cy6

X Optional

X.1 Adding the Joystick

Now that we have a validated 2-DoF robot, let's add a joystick to control it.

  1. Wire the joystick according to pinout.h: connect U/D+ and L/R+ to the 3.3v rail, the two GND pins to the ground rail, one L/R to XPIN, and one U/D to YPIN.
  2. To validate that you can read the joystick input, run joystick_test.cpp and open the Serial Monitor. You should see joystick readings in the range [-1, 1).

X.2 Moving in Joint Space

With the joystick in place, we can then use code to connect the joystick reading to the robot motion.

X.2.1 Refactoring Code

  1. Open include/joystick.h and define a struct to store the x and y values of a joystick reading as floats.

    What is a struct?

    A structure or struct is a user-defined data type that can group members of possibly different types into a single type. An example usage is shown below.

    struct Student {
      int id;
      float gpa;
    };
    
    Student bob = {1, 2.0}; // Initializes a Student variable called bob with id 1 and gpa 2.0
    bob.gpa = 2.3; // Updates the gpa member of bob to 2.3
    Serial.printf("GPA: %.2f\n", bob.gpa); // Prints the new gpa 2.3 in the Serial Monitor
    
  2. Open lab_code/joystick.cpp and complete the TODOs.

  3. Open test_code/joystick_test.cpp and complete the TODOs.

  4. Move joystick_test.cpp and joystick.cpp to the robot/ directory.

  5. Run the new joystick_test.cpp and open the Serial Monitor. Confirm that your joystick readings are the same as before.

X.2.2 Commanding the Robot

Open lab_code/drawing.cpp and complete all the TODOs. At a high level, the code should do the following:

  • reads the joystick
  • scales the joystick reading from [-1, 1) to [-pi/2, pi/2)
  • feeds the joystick reading to a position setpoint
  • smoothes the position setpoint using exponential smoothing
  • drives the motor using a PID controller

Simply put, the x-axis of the joystick controls the velocity of motor 1 and the y-axis of the joystick controls the velocity of motor 2. This is joint space!

X.2.3 Draw A Line

Attach a marker to the end of your 2-DoF robot and try drawing a straight line on your whiteboard. Make sure to move 2 files drawing.cpp and joystick.cpp from lab_code/ to robot/, and move joystick_test.cpp out of robot/.

✅ CHECKOFF 2 ✅
Show your work of art to a TA or LA!

Footnotes

  1. Version 1 - 2020: Rachel Hoffman
    Version 2 - 2024: Phillip Daniel
    Version 3 - 2024: Ravi Tejwani, Kentaro Barhydt
    Version 4 - 2024: Jinger Chong, Josh Sohn
    Version 5 - 2025: Roberto Bolli, Kaleb Blake

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published