Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
John Luther Mascariñas
Published © GPL3+

Articulated Rover Using ArduPilot + Arduino

A 4-wheel articulated rover built to navigate underground mining terrain, using ArduPilot and Arduino Mega for precise control with encoders

AdvancedFull instructions provided7 days162
Articulated Rover Using ArduPilot + Arduino

Things used in this project

Hardware components

3DR ArduPilot 2.5
×1
Arduino Mega 2560
Arduino Mega 2560
×1
Infineon H-Bridge BTS7960
×1
JB37-520 Motor + Encoder
×1
3DR Telemetry
×1
3DR GPS + MAG
×1

Software apps and online services

Mission Planner
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Articulated Rover Chasis (Acrylic Laser Cutter)

Story

Read more

Schematics

Full Wiring Diagram in My Rover

Rover Wiring Diagram from ArduPilot to Arduino Mega.

Code

ArduPilottoArduino.ino

C/C++
Code for Arduino Mega in my Articulated Vehicle.
const int throttlePin = 42;  // ArduPilot Output 1
const int steeringPin = 43;  // ArduPilot Output 3

const int LPWM[4] = {6, 8, 10, 12};
const int RPWM[4] = {7, 9, 11, 13};
const int L_EN[4] = {44, 46, 48, 50};
const int R_EN[4] = {45, 47, 49, 51};

float speedScale = 0.0;

void setup() {
  Serial.begin(9600);

  for (int i = 0; i < 4; i++) {
    pinMode(LPWM[i], OUTPUT);
    pinMode(RPWM[i], OUTPUT);
    pinMode(L_EN[i], OUTPUT);
    pinMode(R_EN[i], OUTPUT);
    digitalWrite(L_EN[i], HIGH);
    digitalWrite(R_EN[i], HIGH);
  }

  pinMode(throttlePin, INPUT);
  pinMode(steeringPin, INPUT);
}

void loop() {
  int throttlePWM = pulseIn(throttlePin, HIGH, 25000);
  int steeringPWM = pulseIn(steeringPin, HIGH, 25000);

  Serial.print("Throttle PWM: ");
  Serial.print(throttlePWM);
  Serial.print(" | Steering PWM: ");
  Serial.println(steeringPWM);

  int throttle = map(throttlePWM, 1000, 2000, -255, 255) * speedScale;
  int steering = map(steeringPWM, 1000, 2000, -255, 255) * speedScale;

  int leftSpeed = throttle + steering;
  int rightSpeed = throttle - steering;

  leftSpeed = constrain(leftSpeed, -255, 255);
  rightSpeed = constrain(rightSpeed, -255, 255);

  driveMotor(0, leftSpeed);   // Front Left
  driveMotor(2, leftSpeed);   // Back Left
  driveMotor(1, rightSpeed);  // Front Right
  driveMotor(3, rightSpeed);  // Back Right

  delay(20);
}

void driveMotor(int index, int speed) {
  if (index == 3) speed = -speed; // Back Right fix

  if (speed >= 0) {
    digitalWrite(RPWM[index], LOW);  // Force LOW
    analogWrite(LPWM[index], speed);
  } else {
    digitalWrite(LPWM[index], LOW);  // Force LOW
    analogWrite(RPWM[index], -speed);
  }
}

Credits

John Luther Mascariñas
1 project • 0 followers
👋 HI, I'm John Luther an 4th year Electronics Engineering student from the Philippines who loves building real-world automation projects.
Contact

Comments

Please log in or sign up to comment.