GithubHelp home page GithubHelp logo

platisd / smartcar_shield Goto Github PK

View Code? Open in Web Editor NEW
75.0 11.0 45.0 20.15 MB

A versatile and easy to use vehicle platform for hobby-grade projects

Home Page: http://plat.is/smartcar

License: MIT License

C++ 93.64% CMake 5.59% Shell 0.77%
smartcar-shield smartcar arduino l293d hc-sr04 gy-50 l3g4200d odometer gp2d120 gp2y0a02yk0f

smartcar_shield's Introduction

Smartcar shield

Tests Examples Documentation codecov CII Best Practices BCH compliance

A versatile and easy to use vehicle platform for hobby-grade projects

Description

This repository, includes everything necessary to set up a Smartcar platform. The Smartcar, is a vehicular educational platform, which enables the user to develop various robotic applications in an affordable, pedagogic and easy way. It is intended for persons with basic programming knowledge and little to no experience of electronics, mechanics or robotics. More experienced users, should also find this approach convenient, due to its open source nature, high level API and object oriented design.

Hardware

Despite the software being hardware-agnostic, historically, development has been based on specific hardware. Initially, the Smartcar shield was used on top of an Arduino, using cheap car kits. This setup will be referred to as shield or v1.

Since the winter of 2019, a new platform was developed from scratch, using the WiFi and Bluetooth enabled ESP32 as the vehicle's "brain". This setup will be referred to as platform or v2 and will be considered the default one from now on. It offers greater robustness and many more possibilities, as it offers out-of-the-box connectivity.

Platform

smartcar platform

The Smartcar platform is a complete hardware solution for your hobby-grade, connected vehicle project. It is comprised of the chassis, made out of printed circuit boards, stacked on each other and an ESP32 development board that drives the motors, controls the sensors and communicates with the world via WiFi and Bluetooth.

There are 4 motors with directional odometers which enable not only to determine how much the wheels have moved but also the direction they spin. It is equipped with a GY-50 gyroscope module (based on the L3G4200D sensor) to provide heading information and sockets to optionally connect 4 VL45L0X LIDAR sensors to provide distance measurements. It is powered up by 8 AA batteries and you can find the boards' source files in extras/eagle/smartcar_platform.

Shield

smartcar_shield

The Smartcar shield is an open hardware PCB, that is effortlessly stacked on top of an Arduino. It includes an L293D H-bridge chip, that drives the motors, screw terminals to connect the motors and a battery to them and a GY-50 gyroscope module (based on the L3G4200D sensor). In extras/eagle/smartcar_shield you can find the design files for the board, in a modifiable form, using free software. There are also the options, to order it as-is, from either USA or China based manufacturers.

The Smartcar shield, facilitates efficient cable management, helps to preserve space and is as small as possible, in order to keep the manufacturing price low. Additionally, the components necessary to assemble it, are widely available over the Internet. Furthermore, you can find 2D CAD drawings of the Smartcar chassis in various formats, at /extras/cad/2D which you can freely use in order to fabricate your own, e.g. with a milling machine or a laser cutter.

Emulator

SMCE is the digital twin of the Smartcar platform along with a cool and customisable 3D world for your rover to roam in.
The core concept is that you write Arduino code that runs on both the real hardware as well as the virtual environment. This way, the need to have exclusive and frequent access to the car can be either alleviated or drastically decreased. The emulator allows limiting the unavoidable engagement with the physical car, to the point a team of developers may develop their features on the emulator and only access the real hardware to verify them.

Software

The software, is the Smartcar shield Arduino library. It sports a high level API, meant to enable its users to perform tasks easily with relatively few lines of code. It intends to hide implementation details or low level hardware operations. The library, handles the various components (i.e. the vehicle and the various sensors) as objects, therefore enabling trivial control over the car's functions. The various operations exposed by the API, are thoroughly explained in API Documentation. You can find examples on how to use the library, in /examples.

The library is versatile and is independent from the shield or specific hardware. Particularly, its most important feature is that it supports multiple ways of steering and throttling with different types of motors. Moreover, it is possible to steer the vehicle by rotating the wheels on each side at a different speed, like a tank as well as by using a servo motor. Another option is to use a brushed DC motor for steering, a setup that is very common in cheap RC cars. Additionally, apart of the default brushed DC motors that are connected to the Smartcar shield, you can also use an electronic speed controller (ESC) in order to drive (throttle) the vehicle, using the very same library.

If the Smartcar shield library is installed through the Library Manager of Arduino IDE, as recommended, the user will receive a notification in their IDE, when new versions are released making updates particularly easy, without the need to use GitHub or git.

Reference platforms

Smartcar platform (default setup)

Smartcar shield

  • Smartcar chassis
  • Smartcar shield PCB
  • L293D H-bridge
  • GY-50 gyroscope module
  • Two odometers (speed encoders) ([1] and [2] will suit commercially available chassis. [3] require some slight modifications)
  • Male & female pin headers (optionally get stackable Arduino headers too)
  • Five 2-pin screw terminals
  • Pin jumper
  • DIP16 socket
  • 0.1uF capacitors (2)
  • 100uF capacitor
  • 9V or 12V battery pack (do not use a single 9V battery)

Supported sensors

  • Distance sensors
    • Ultrasonic
      • HC-SR04
      • SRF08
    • Infrared
      • SHARP GP2D120
      • SHARP GP2Y0A02
      • SHARP GP2Y0A21
  • Gyroscopes
    • GY-50 (L3G4200D)
  • Odometers
    • Directional (4+ pins)
    • Non-directional (3-pins)

How to get started

Dependencies

All dependencies should be downloaded automatically by the Arduino IDE's library manager.

Project documentation

License

MIT

smartcar_shield's People

Contributors

aerostun avatar per1234 avatar platisd avatar this-oliver avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smartcar_shield's Issues

Fix code smells detected by Sonarqube

Description

Sonarqube has detected some code smells and the report can be found here.
Not all of them need to be fixed (i.e. ignore the ones about the commented-out code).

Definition of Done

  • Fix the code smells
  • Find ways (if any) to avoid regressions (e.g. through clang-tidy or compiler warnings)

Refactor 11 lines occurring 2 times in DistanceCar.cpp

I've selected for refactoring 11 lines of code which are duplicated in 1 file(s) (1, 2). Addressing this will make our codebase more maintainable and improve Better Code Hub's Write Code Once guideline rating! πŸ‘

Here's the gist of this guideline:

  • Definition πŸ“–
    Do not copy code.
  • Why❓
    When code is copied, bugs need to be fixed in multiple places. This is both inefficient and a source of regression bugs.
  • How πŸ”§
    Avoid duplication by never copy/pasting blocks of code and reduce duplication by extracting shared code, either to a new unit or introduce a superclass if the language permits.

You can find more info about this guideline in Building Maintainable Software. πŸ“–


ℹ️ To know how many other refactoring candidates need addressing to get a guideline compliant, select some by clicking on the πŸ”² next to them. The risk profile below the candidates signals (βœ…) when it's enough! 🏁


Good luck and happy coding! :shipit: ✨ πŸ’―

Fix compilation of gMock failing on CI

Description

GMock compilation on CI seems to have started failing.
An easy fix is to remove the pedantic flag when GMock is being compiled. It shouldn't matter since it's an external library.

Definition of Done

  • All CI jobs are 🟒 again.

Use composition instead of inheritance for Odometer classes

Description

Currently DirectionalOdometer is extending DirectionlessOdometer so to utilize some common functionality. However, a DirectionalOdometer is not a DirectionlessOdometer. Both are Odometers that are using an Encoder.

Definition of Done

DirectionalOdometer is no more inheriting from a concrete class and there's little to no code duplication.

Remove ArduinoRuntime hack

Description

Static instantiation of the ArduinoRuntime in Smartcar.h so it can be used as a conditional statement in different class constructors should be removed, as well as the default argument.

It seems that library users are starting off by copying the examples anyway, so it won't be too cumbersome.

Definition of Done

  • Smartcar.h does not instantiate an ArduinoRuntime instance, that is left for the user to do.
  • Default runtime argument is removed from the constructors that use it.

Migrate CI to GitHub actions

Description

Currently we are using TravisCI for continuous integration. Travis CI downloads an IDE to compile the sketches which can be finicky as it has not been made with command line usage in mind.
Let's move to GitHub which is using arduino-cli instead that seems to be the new thing that should catch on.

Definition of Done

TravisCI functionality is migrated over to GitHub Actions.

Add support for MPU-6050

Would you be able to add support for the MPU-6050 board ( GY-521 gyroscope module ) in addition to the existing MPU-3050 (GY-50 gyroscope module)?

Cheers
Douglas

Refactor 6 lines occurring 2 times in SRF08.cpp

I've selected for refactoring 6 lines of code which are duplicated in 1 file(s) (1, 2). Addressing this will make our codebase more maintainable and improve Better Code Hub's Write Code Once guideline rating! πŸ‘

Here's the gist of this guideline:

  • Definition πŸ“–
    Do not copy code.
  • Why❓
    When code is copied, bugs need to be fixed in multiple places. This is both inefficient and a source of regression bugs.
  • How πŸ”§
    Avoid duplication by never copy/pasting blocks of code and reduce duplication by extracting shared code, either to a new unit or introduce a superclass if the language permits.

You can find more info about this guideline in Building Maintainable Software. πŸ“–


ℹ️ To know how many other refactoring candidates need addressing to get a guideline compliant, select some by clicking on the πŸ”² next to them. The risk profile below the candidates signals (βœ…) when it's enough! 🏁


Good luck and happy coding! :shipit: ✨ πŸ’―

getSpeed and GetDirection

As there are DCMotors::setSpeed and DCMotors::setAngle methods, would it be possible to have DCMotors::getSpeed and DCMotors::getAngle methods as well to enable the code to determine where the robot is heading?

Cheers
Douglas

Cruise control suffers from runaway due to temporary sensor failure

The cruise control functionality of the library can cause runaway as a result of a temporary sensor failure. As a consequence, the controlled rover moves in the direction opposite to the requested one at maximum speed.

The problem affects the cruise control functionality enabled using car.enableCruiseControl(). We observed it with this rover type.

The problem manifests when the rover is commanded to drive forward, but is still standing and the odometers temporarily report high moving speed due to signal transmission failure. The controller will then apply negative torque (meant for braking), which accelerates the rover backwards. As the rover accelerates backwards, the odometers correctly report increasing speed (the odometers report the absolute speed, not the direction), which is interpreted as the rover moving forward too fast. This results in more negative torque being applied, and a complete runaway with the rover racing backwards.

The following sketch can be used to demonstrate the problem.

#include <Smartcar.h>

Odometer encoderLeft(188), encoderRight(188);
Gyroscope gyro(22);
Car car;

const int encoderLeftPin = 2;
const int encoderRightPin = 3;
const float fSpeed = 0.3; //a ground speed (m/sec) for going forward
bool sw = false;

void setup() {
  Serial3.begin(9600);
  encoderLeft.attach(encoderLeftPin);
  encoderRight.attach(encoderRightPin);
  gyro.attach();
  delay(1500);
  gyro.begin(60);
  encoderLeft.begin();
  encoderRight.begin();
  car.begin(encoderLeft, encoderRight, gyro); //initialize the car using the encoders
  car.enableCruiseControl(); //using default PID values
  car.setAngle(0);
 // car.enableCruiseControl(12,5,17,30); //using custom values and control frequency
  car.setSpeed(fSpeed);
}

void loop() {
  car.updateMotors();
  handleInput();
}

int state = 0;

void handleInput() {
  int t = millis();
  if (t >= 1000 && state < 1) {
    car.setSpeed(fSpeed);
    state = 1;
  } else if (t >= 3000 && state < 2) {
    car.setSpeed(0);
    state = 2;
  }

}

The sketch uses the cruise control functionality, requesting to drive forward at 1 s after setup, and then stopping at 3 s. The correct behaviour with the sketch is the rover driving forward and then stopping.

We managed to trigger erroneous behaviour by using the rover with depleted batteries. With that setup, the rover will occasionally race backwards instead of moving forward. We observed incorrect behaviour once every 4 attempts or so, but this probability is greatly dependent on the state of the batteries. We also observed it by using an incomplete battery pack (6 1.5 V batteries instead of 8), giving the measured voltage 8.4 V dropping to 6.4 V under load (we could not measure voltage under load reliably due to how fast was changing). Connecting the Arduino board to USB power makes the problem go away completely.

We traced the problems to the odometers returning high speeds temporarily when the rover is standing or moving slowly. We don’t know what causes the incorrect readouts. We suspect that the voltage ripple from the motor controller is interpreted as signal edges from the odometers.

We believe that the cause of the incorrect readouts should be investigated, but the fundamental problem here is that the control turns a small disturbance (or input corruption) into a complete runaway. Using odometers that also report the direction of movement in addition to the speed would solve the problem. With the current odometers, the controller should be somehow constrained to avoid the runaway.

Be standard C++: get rid of VLAs

Description

Library uses VLAs hence is not C++ compliant, making it not compile on compliant compilers

Implementation

Replace by fixed-size buffers

Definition of Done

Library does not use VLAs and documentation reflects changes

Remove unintended Arduino dependencies from Runtime interface

Description

The Runtime interface is supposed to be a platform agnostic representation of the
runtime environment.
Instead of passing arbitrary numbers (which will only work for Arduino), we should
instead pass generic enums and let each implementation determine how these
enums should be interpreted.

Definition of Done

  • Platform specific dependencies are removed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.