Rat Operated Vehicle (Version 3)

by jmspivey0 in Circuits > Arduino

1649 Views, 5 Favorites, 0 Comments

Rat Operated Vehicle (Version 3)

thumbnail_PXL_20210428_181321803.jpg

Author: Max Spivey

Overview

This car utilizes a Moebius chassis, 12V motors, 9V batteries, an Arduino UNO, a motor controller, micro switches, 3D printed parts, and Lexan. The following Instructable teaches how to construct a car for rats to drive. Rats compress levers on micro switches the drive and steer the vehicle. This car will be used for a collaboration research project between University of Richmond and Randolph-Macon College. Researchers at University of Richmond used two similarly designed cars to carry out research in the past.

Here is a link to the published paper about the original car: https://doi.org/10.1016/j.bbr.2019.112309 and a link to an Instructables about the first version of the car authored by L. E. Crawford & Thad Martin: https://www.instructables.com/Rat-Operated-Vehicle/

How does the car work?

The rat is placed inside the driving compartment by sliding up the door on the back side of the car. The front panel of the vehicle has window bars and panels connected to micro switches for driving. The rats drive the car by grabbing the panel connected to the micro switch causing it to compress the micro switch. The left switch makes the car turn left, middle switch makes the car drive forward, and right switch makes the car turn right. The windows enable you to easily reward the rats when teaching them how to drive the vehicle by interacting with the switches.

Links that may help:

Crimping GPIO connectors

Arduino information

Adafruit Motor Shield information

How to solder and make rails

Supplies

Here are the supplies needed to recreate this build. Links are provided for reference to the items and what we used to complete this project. By no means do you need to buy the exact same item.

Materials list

1x Arduino Uno

1x Moebius 10KG Load 4WD 80mm Mecanum Wheel Robot Car Chassis Kit with DC 12V Encoder Motor -

1x Adafruit Motor/Stepper/Servo Shield for Arduino v2.3 Kit

16x Right Angle Male Pin Connectors

2x 9V battery holder w/ switch

3x micro limit switch with lever

2x Rechargeable 9V Batteries

1x Spade connector kit

1x 30" x 30" sheet of 2.5mm thick lexan - you can get this at most local hardware stores, we used ACE, this link is for reference

1x Dupont connector kit for wiring

Male and female velcro

Wires

1x Grommets - optional step

1x Nylon standoff kit - optional step

2.5mm nuts and bolts

3D printer

3D Printer plastic

Tools Required:

Saw - for cutting the plastic

Drill - for drilling holes

2.5mm drill bit

Wrench and 2.5mm hex wrench

Screwdrivers

Pliers

Soldering Iron and solder

Wire stripper

Crimping Tool

Software Required:

Arduino IDE

Respective 3D print software

AutoDesk Inventor or other 3D modeling software to edit files

Assemble the Car and Hardware

thumbnail_PXL_20210402_173156219.jpg
car-wiring-diagram.png

Tools required for this step:

Soldering Iron

Wire Cutter/Stripper

Crimper

The chassis kit comes with instructions to assemble it. Follow those instructions completely.

Once the car is assembled it is time to get out the Arduino Uno, Motor Shield, and 9V battery holders. The Uno and 9V battery holders are ready to be placed on the car but the Motor Shield needs some soldering done first.

  1. The shield needs the entirety of the Digital I/O and Analog In soldered with GPIO Male Stacking Connectors. These pins allow for stacking the Motor Shield on the Arduino UNO. The male (long) end needs to be facing down in order for it to rest on top of the Arduino.
  2. The Male Right Angle Pin Connectors need to be soldered onto the shield to provide power to the Uno and to provide power for the micro switch signal. Follow the first image for where to place the Right Angle Pin Connectors.

Mount the Hardware and Attach Wires

thumbnail_PXL_20210430_175348573.jpg
motor-wiring.png

Tools required for this step:

Crimper

Flathead Screwdriver

Wire Cutter/Stripper

Phillips Head Screwdriver

It is time to mount the hardware now that the chassis is assembled and all of the required soldering is completed. The car should look like the first image

  1. Mount the Arduino Uno on the underbelly of the chassis near the round front of the car.
  2. Insert the Shield by the GPIO males pins into the Arduino.
  3. Velcro the two 9V battery holders onto the underbelly of the chassis.
  4. Connect one 9V battery holder to the positive/negative (+/-) terminal labelled power on the shield. This will power the motors.
  5. Take the other 9V battery holder and crimp Female GPIO pins onto the positive and negative wires attached to the holder.
  6. Connect the Female 9V battery to the VIN and GND Male Right Angle Connectors on the Shield. This will power the Arduino and signal for the micro switches.
  7. Create wires to connect the 3V pin to one of the rails and GND to the other rail.
  8. For each motor separate the inner wires from the outer left and outer right ones. If desired you can cut away the middle four wires as they will not be used.
  9. Follow the second image for wiring the motors in the correct order. The second image shows what the wiring should look like.

It is important that the wiring for the motors is followed precisely, else they may not spin the correct way.

Cut and Drill the Lexan

Side Panel.PNG
Top Panel.PNG

Tools required for this step:

Saw

Drill

2.5mm Drill bit

Now that the car is ready to go it is time to cut the lexan that will be used to shield the bottom and for the driving compartment.

  1. Saw three 198mm by 160mm panels out of the lexan, these will act as the walls and the door of the car.
  2. Drill to fit one two of the panels the holes to mount the side panels in the base and roof of the car. The third panel will act as the sliding door.
  3. Saw one 155mm by 192mm panel out of the lexan, this will act as the roof of the car.
  4. Drill to fit the holes to mount the roof panel into the roof of the car.
  5. Set aside these parts for the next step where you print and assemble the car.

Optional: Cut and Drill Under Shield

Bottom Panel.png
thumbnail_PXL_20210428_175303506.jpg

Tools required for this step:

Saw

Drill

2.5mm Drill bit

1/4 inch Drill bit - if using grommets

The original design of this includes an under shield cut out of lexan on the bottom to protect the wires. The intention is to protect the electronics will the car is in use, moved around in the lab, or in storage.

  1. Cut out a 260mm by 180mm panel of lexan.
  2. Drill the holes to mount the panel on the bottom of the car. If desired, drill the holes larger to fit grommets in to protect the lexan around the holes.

The holes should align with four holes on the front and back of the chassis. Use copper or plastic standoffs to mount this panel onto the chassis. It should rest flush against the motors. In the final design we also mounted the batteries on the bottom plate for easier access and to have them rest more naturally on the velcro.

It is best to put this plate on once everything is finished and the car is working. The second image is how it should fit on the bottom.

Build the Pilot's Seat

thumbnail_PXL_20210428_174951709.jpg
thumbnail_PXL_20210428_175056789.jpg

Tools required for this step:

Screwdriver

3D printer

Scissors

Set aside the chassis for now.

  1. Using the .STL files attached 3D print the roof, floor, and front of the car. Additionally, 3D print three of the switch panels.
  2. Fit the three driving panels onto the microswitches and mount them on the front with the switch facing up inside the compartment.
  3. Attach Velcro on the underside of the floor of the compartment and attach it to fit on the top of the chassis. Be careful to not have the 3D plastic touching the wheels.

At the end of these steps the assembled part should look like the second image. Ignore the wires as they come in the next step.

Complete Steering Wiring

My Post.jpg

Tools required for this step:

Crimper

Wire Stripper/Cutter

Now that everything is assembled the last step concerning hardware is to create the wiring to the switches that the driver will use to control the vehicle from within the compartment.

Notes before hopping into this:

  • All wires going to the same switch need to be as close to the same length as possible so the GPIO terminals fit and the wires do not flex.
  • The original design accounts for removal of the switches so you could make the wires go directly to the Angled Male GPIO pins on the Shield.
  • The original design uses spade connectors for attaching to the terminals on the switch but you can simply solder directly to the terminal if you would like.

Wires from the switches

  1. Cut 3 red wires, 3 black wires, and 3 uniquely colored wires to fit.
  2. Strip both ends of the wire and crimp a spade connector on one end of each wire.
  3. Attach the wires to the switches as seen in the image and mount them on the compartment on the chassis of the car. (this step is important for making the wires to fit)
  4. Trim the wires on the other end to the same length and crimp Female GPIO pins onto each wire.
  5. Place each switches corresponding wires into a 3-wide GPIO terminal.
  6. Mount the switches on the front of the car.

The wiring of each switch should resemble image 1 and the compartment should resemble image 2.

Wires from the shield

  1. Again, cut 3 red wires, 3 black wires, and 3 uniquely colored wires to fit.
  2. Strip both ends of the wire and crimp a Female GPIO pin onto one side of each wire.
  3. Place each set of 3 wires into a 3-wide GPIO terminal and plug it into the respective place. The uniquely colors ones will go into GPIO 1, 2, and 3. The red ones will plug into the positive rail and the black ones will plug into the ground rail.
  4. Trim the other sides of the wire to fit and crimp Male GPIO pins onto each wire.
  5. Match a uniquely colored wire with a red and black wire placing them in a 3-wide GPIO terminal.
  6. Plug each 3-wide Male GPIO terminals into their corresponding switches uniquely colored 3-wide Female GPIO terminal.

At the end of this step the car should look like image 3.

Congratulations! You should be finished with the building component of this project and now have your very own rat (or other animal) car!

Install the Software

With the car powered down it is time to upload the code. Plug into a computer the USB adapter that came with the Arduino Uno and open the Arduino IDE. Upload the code to the car. The file is attached here or open up a new program and copy the code below into it. If there is an error uploading, then unplug the GPIO pins 1 through 3 (your uniquely colored wires that handle the signal for the switches) and try again.

/*
Author: Max Spivey, Randolph-Macon College
Last Edit: 4/13/21
This program enables cars designed for rats to drive left, right, and straight in a collaboration project between Randolph-Macon College and University of Richmond. The code works as is and if the speed needs to adjusted scroll down to line 22 where the speeds for the motors are initialized.
*/
#include <Wire.h>
#include <Adafruit_MotorShield.h>
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);

// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *motor1 = AFMS.getMotor(1);
Adafruit_DCMotor *motor2 = AFMS.getMotor(2);
Adafruit_DCMotor *motor3 = AFMS.getMotor(3);
Adafruit_DCMotor *motor4 = AFMS.getMotor(4);

//Pin to keep track of which switch the driver activated
int activePin = 0;
//Constants for normal speed and no speed, use NORMAL_SPEED to change the speed at which the vehicle moves out of 250
int NORMAL_SPEED = 150;
int NO_SPEED = 0;

void setup() {
  //Set the pins for input mode and to use resistors. This causes the pins to automatically be high.
  //Therefore opposite behavior should be expected with the pins.
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  //This initializes the Adafruit Motor Shield
  AFMS.begin();  // create with the default frequency 1.6KHz
  // Set the speed to start, from 0 (off) to 255 (max speed)
  // This turns on the motors
  motor1->setSpeed(NORMAL_SPEED);
  motor2->setSpeed(NORMAL_SPEED);
  motor3->setSpeed(NORMAL_SPEED);
  motor4->setSpeed(NORMAL_SPEED);
  motor1->run(FORWARD);
  motor2->run(FORWARD);
  motor3->run(FORWARD);
  motor4->run(FORWARD);
  motor1->run(RELEASE);
  motor2->run(RELEASE);
  motor3->run(RELEASE);
  motor4->run(RELEASE);
}

void loop() {
  //Check the pins to see if they are active. 
  //We check to see if they are LOW due to INPUT_PULLUP having the pins automatically HIGH.
  if (digitalRead(1) == LOW)
  {
    activePin = 1;
  }
  else if (digitalRead(2) == LOW)
  {
    activePin = 2;
  }
  else if ( digitalRead(3) == LOW)
  {
    activePin = 3;
  }
  else
  {
    activePin = 0;
  }
  /* 
  Depending on what the activePin is, activate the case.
  case 0: Stop the car, no pins are active
  case 1: Pin 1 is active, turn right
  case 2: Pin 2 is active, move forward
  case 3: Pin 3 is active, turn left
  If two pins are activated then the last one to be activated will be the active pin.
  */
  switch (activePin) {
    case 0:
      motor1->run(RELEASE);
      motor2->run(RELEASE);
      motor3->run(RELEASE);
      motor4->run(RELEASE);
      break;
    case 1:
      motor1->run(BACKWARD);
      motor2->run(FORWARD);
      motor3->run(BACKWARD);
      motor4->run(FORWARD);
      break;
    case 2:
      motor1->run(FORWARD);
      motor2->run(FORWARD);
      motor3->run(FORWARD);
      motor4->run(FORWARD);
      break;
    case 3:
      motor1->run(FORWARD);
      motor2->run(BACKWARD);
      motor3->run(FORWARD);
      motor4->run(BACKWARD);
      break;
  }
 }

Downloads

Test the Car

test drive

Now you can fully test the car. From the perspective of the driver's seat the left lever should turn the car left, the middle lever should drive the car forward and the right lever should turn the car right. If you are experiencing issues with some of the switches then verify all of your wires are properly connected and that power is on.

Optional 3D Print

The original design of this vehicle accounts for staged training of the rats. Initially the rats will only be trained how to drive forward and then the left and right turn switches will be added once the rats exhibit an understanding of the drive forward switch. The purpose of the switch plugs is to prevent the rats from being distracted by the holes if you use this method of training.

Attached to this step is an .STL file for a plug to fill empty switch slots.

Downloads

Conclusion

Attached in this section are all of the original files from Inventor that were used for the 3D prints in case your project requires some adjustments. At this point the car should be finished and ready to go. It is important to regularly charge the batteries in order to have the car to function properly. Make sure any sharp edges are filed down and loose plastic is removed from the vehicle before animals use it. Also, do not leave any animals unsupervised in the car.

Thank you for reading and best of luck!