Skip to content

Enables autonomous driving of a 2 or 4 wheel car with an Arduino and a Adafruit Motor Shield V2. To avoid obstacles a HC-SR04 Ultrasonic sensor mounted on a SG90 Servo continuously scans the area. Manual control is by a GUI implemented with a Bluetooth HC-05 Module and the BlueDisplay library.

License

Notifications You must be signed in to change notification settings

ArminJo/Arduino-RobotCar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enables autonomous driving of a 2 or 4 wheel car controlled by an Arduino.

Badge License: GPLv3     Badge Version     Badge Commits since latest     Badge Build Status     Badge Hit Counter

Stand With Ukraine

Available as RobotCarBlueDisplay example of the Arduino library PWMMotorControl.
Requires the Arduino library BlueDisplay.

If you find this program useful, please give it a star.

🌎 Google Translate


Features

  • Obstacles avoidance by a HC-SR04 ultrasonic sensor mounted on a SG90 Servo which continuously scans the environment.
  • To overcome the drawbacks of ultrasonic sensors, an additional Sharp 430/1080/20150/100550 (GP2Y0A21YK0F) IR or VL53L1X TOF (TimeOfFlight) sensor can be mounted to the servo.
  • Manual control implemented by a GUI using a Bluetooth HC-05 Module and the BlueDisplay library.

Just overwrite the function doUserCollisionAvoiding() to test your own skill. You may also overwrite the function fillAndShowForwardDistancesInfo(), if you use your own scanning method.

Installation

  • Install BlueDisplay library with Tools > Manage Libraries... or Ctrl+Shift+I. Use "BlueDisplay" as filter string.
  • Install PWMMotorControl library with Tools > Manage Libraries... or Ctrl+Shift+I. Use "PWMMotorControl" as filter string.
  • Open the example RobotCarBlueDisplay, available at File > Examples > Examples from Custom Libraries / PWMMotorControl.

Other examples of PWMMotorControl like SmartCarFollower will also run on this robot car.


Pictures

4WD car with IR receiver and Bluetooth module and 4 AA rechargeable batteries. Instructable
4 wheel car Instructable
4 wheel car like the 2 WD car right, but with servo mounted head up. 2 wheel car with encoders, 2 Li-ion batteries, Adafruit Motor Shield V2, Bluetooth connection, and servo mounted head down.
4 wheel car 2 wheel car
Encoder fork sensor Servo mounted head down
Encoder fork sensor Servo mounting
VIN sensing with motor shield Red car with Sharp GP2Y0A21YK distance sensor
VIN sensing Red car with Sharp GP2Y0A21YK distance sensor
Youtube video of MecanumWheelCar demo Youtube video of mecanum car controlled by the accelerator sensors of the tablet
MecanumWheelCar Demo Arduino Mecanum Wheel Car Sensor Drive Demo

SCREENSHOTS

Start page Test page
Start page Test page
Sensor drive page Sensor drive page for mecanum car
Sensor drive page Sensor drive page for mecanum car

Automatic control page with detected wall at right Automatic control page

  • Cyan bars are distances above 1 meter.
  • Green bars are distances above double distance of one ride per scan (default 40 cm).
  • Red bars are distanced below the distance of one ride per scan (default 20 cm) -> collision during next "scan and ride" cycle if obstacle is ahead.
  • Yellow bars are the values between the 2 thresholds (default 20 cm to 40 cm).
  • The tiny white bars are the distances computed by the doWallDetection() function. They overlay the green (assumed timeout) values.
  • The tiny black bar is the rotation chosen by doCollisionAvoiding() function.

Wall detection

Ultrasonic distance measurement has a problem with walls. You can only detect a wall if the angle of the wall relative to sensor axis is approximately between 70 and 110 degree. For other angels the reflected ultrasonic beam cannot reach the receiver which leads to unrealistic great distances.
The implemented wall detection function doWallDetection() takes samples every 18 degrees and if it gets 2 adjacent short distances below DISTANCE_MAX_FOR_WALL_DETECTION_CM, it assumes a wall determined by these 2 samples. The (invalid) values 18 degrees right and left of these samples are then extrapolated by computeNeigbourValue().


Compile options / macros for this software

To customize the software to different car configurations, there are some compile options / macros available.
Modify them by enabling / disabling them, or change the values if applicable.

Compile options for the used PWMMotorControl library like USE_ENCODER_MOTOR_CONTROL are described here.

Name Default value Description
CAR_HAS_VIN_VOLTAGE_DIVIDER undefined VIN/11 at A2, e.g. 1 MΩ to VIN, 100 kΩ to ground. Required to show and monitor (for undervoltage) VIN voltage.
VIN_VOLTAGE_CORRECTION undefined or 0.8 for Uno Voltage to be subtracted from VIN voltage for voltage monitoring. E.g. if there is a series diode between Li-ion and VIN as on the Uno boards, set it to 0.8.
CAR_HAS_US_DISTANCE_SENSOR disabled A HC-SR04 ultrasonic distance sensor is mounted (default for most China smart cars).
US_SENSOR_SUPPORTS_1_PIN_MODE disabled Use modified HC-SR04 modules or HY-SRF05 ones.
Modify HC-SR04 by connecting 10 kΩ between echo and trigger and then use only trigger pin.
CAR_HAS_IR_DISTANCE_SENSOR disabled Use Sharp GP2Y0A21YK / 1080 IR distance sensor.
CAR_HAS_TOF_DISTANCE_SENSOR disabled Use VL53L1X TimeOfFlight distance sensor.
CAR_HAS_DISTANCE_SERVO disabled Distance sensor is mounted on a pan servo (default for most China smart cars).
DISTANCE_SERVO_IS_MOUNTED_HEAD_DOWN disabled Distance.h
CAR_HAS_PAN_SERVO disabled Enables the pan slider for the PanServo at the PAN_SERVO_PIN pin.
CAR_HAS_TILT_SERVO disabled Enables the tilt slider for the TiltServo at the TILT_SERVO_PIN pin.
CAR_HAS_CAMERA disabled Enables the Camera button for the CAMERA_SUPPLY_CONTROL_PIN pin.
CAR_HAS_LASER disabled Enables the Laser button for the LASER_OUT_PIN / LED_BUILTIN pin.
ENABLE_RTTTL_FOR_CAR undefined Plays melody after initial timeout has reached. Enables the Melody button, which plays a random melody.
MONITOR_VIN_VOLTAGE disabled Shows VIN voltage and monitors it for undervoltage. VIN/11 at A2, 1 MΩ to VIN, 100 kΩ to ground.
ENABLE_EEPROM_STORAGE disabled Activates the buttons to store compensation values. Normally they are stored after calibration.

Changing include (*.h) files with Arduino IDE

First, use Sketch > Show Sketch Folder (Ctrl+K).
If you have not yet saved the example as your own sketch, then you are instantly in the right library folder.
Otherwise you have to navigate to the parallel libraries folder and select the library you want to access.
In both cases the library source and include files are located in the libraries src directory.
The modification must be renewed for each new library version!

Modifying compile options / macros with PlatformIO

If you are using PlatformIO, you can define the macros in the platformio.ini file with build_flags = -D MACRO_NAME or build_flags = -D MACRO_NAME=macroValue.

Modifying compile options / macros with Sloeber IDE

If you are using Sloeber as your IDE, you can easily define global symbols with Properties > Arduino > CompileOptions.
Sloeber settings

About

Enables autonomous driving of a 2 or 4 wheel car with an Arduino and a Adafruit Motor Shield V2. To avoid obstacles a HC-SR04 Ultrasonic sensor mounted on a SG90 Servo continuously scans the area. Manual control is by a GUI implemented with a Bluetooth HC-05 Module and the BlueDisplay library.

Topics

Resources

License

Stars

Watchers

Forks