Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Infineon Team
Published

Autonomous Driving Car

Curious about autonomous driving, AI and neural networks? Build your own autonomous driving car and get your hands on these topics!

IntermediateFull instructions provided8 hours6,998
Autonomous Driving Car

Things used in this project

Hardware components

Boot Kit XMC1100 (Arduino shield compatible)
Infineon Boot Kit XMC1100 (Arduino shield compatible)
×1
DC Motor Control Shield with BTN8982TA
Infineon DC Motor Control Shield with BTN8982TA
×1
Reely Onroad-Chassis 1:10
×1
Reely 1:10 Wheels
×1
Brushed Motor Carson Modellsport Cup
×1
Savöx Standard-Servo SC-0254MG Digital-Servo
×1
LiPo 7.4 V 5000 mA
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Camera Module
Raspberry Pi Camera Module
×1
SanDisk Extreme 32 GB microSDHC
×1
batterie connector
×1

Software apps and online services

donkey car

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
3D Printer (generic)
3D Printer (generic)
double extruder
Multitool, Screwdriver
Multitool, Screwdriver
Crimp Tool, Heavy-Duty
Crimp Tool, Heavy-Duty

Story

Read more

Custom parts and enclosures

20180706_Basisplatte_1

Baseplate

20180323_Magnet_roll_Cage_IFX

roll cage - also a good handle to pick it up

20180323_Cameramount_M2

camera mount

Schematics

System block diagram

Code

XMC1100 code

C/C++
This code runs on the XMC1100 Boot Kit.
It emulates the PWM shield used in the donkey car project and is therefore a plug and play solution.
The Raspberry Pi sends throttle and steering data via I2C. The XMC takes care of setting these values via PWM (servo) and motor control signals (BTN8982 Motor Shield).
#include <IfxMotorControlShield.h>


// servo pin
int servo = 8;

// variables for servo control
int pwm;
int Servo_pos = 0;
int Servo_pos_aktuell;

// serial communication
String inString = "";
int neg;

//variables for motor control 
int speedvalue = 0;
int speedvalue_aktuell;
int speedflag = false;


void servoMove(int servo, int Servo_pos){
  pwm = (Servo_pos) + 1500;
  digitalWrite(servo, HIGH);
  delayMicroseconds(pwm);
  digitalWrite(servo, LOW);
}

//i2c communication
int on1;
int off1;

int on0;
int off0;

int r;        //register
int x;        //value

int received;

#include <Wire.h>

void setup() {
//communications
  Wire.begin(64);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent);  // register event
  Wire.onRequest(requestEvent);  // register event
  Serial.begin(115200);          // start serial for output
  delay(10);
//servo
 pinMode(servo, OUTPUT);
 servoMove(servo, Servo_pos);

//motor   
 if(ifxMcsBiDirectionalMotor.begin())
    Serial.println("Init Fail!");
  Serial.println("Initialising speed");
  ifxMcsBiDirectionalMotor.setBiDirectionalSpeed(speedvalue);
  Serial.println("Starting motor");
  ifxMcsBiDirectionalMotor.start();

  
  Serial.println("Setup Done");
}

void loop() {
    
if(received == 0) {
  Serial.println("fail!");
}
  
//servo
  if(abs(Servo_pos_aktuell - Servo_pos)<200){
  servoMove(servo, Servo_pos);   
  }
Servo_pos_aktuell = Servo_pos; 

//motor
 if(abs(speedvalue_aktuell - speedvalue)<200){
 ifxMcsBiDirectionalMotor.setBiDirectionalSpeed(speedvalue*0.4);
    //if speed was set to 0, the motor has to be restarted!
      if(!ifxMcsBiDirectionalMotor.getRunning())
        ifxMcsBiDirectionalMotor.start();   
  }
speedvalue_aktuell = speedvalue; 
 
  delay(50);
 
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
  Wire.write(0x01); // respond with 0x01 as expected by master
  Serial.println("0x01");
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
  if(howMany == 2){
  received = true;
  }
  else{
    received = false;
  }
     
// read
  while (1 < Wire.available()) { // loop through first of two bytes
      r = Wire.read();           // receive register byte
  }
      x = Wire.read();           // receive Value byte as an integer


//process
  switch (r) {  
    case 8:
      off0 = x;
      speedflag = true;
      break;
    case 9:
      if (speedflag == true) {
      off0 = off0+(x<<8);
      speedvalue = off0-255;
      speedflag = false;
      }   
      break;
    case 12:
      off1 = x;
      break;
    case 13:
      off1 = off1+(x<<8);
      Servo_pos = off1-600;
      break;   
 }
}

Credits

Infineon Team

Infineon Team

92 projects • 140 followers

Comments