Posts

Flow Chart

Image
Flow Chart: Self Drifting Cars Self Drifting Cars Flow Chart  Self Drifting Cars Flow Chart as shown in figure above, start with analog infrared sensor to detect distance in front direction of the cars, accelerometer received acceleration of the cars, ultrasonic sensor received distance between the cars and the wall to calculate offset angle by using PID controller to steering car direction and to avoid collision from the wall, then we can limit speed of the cars by using HAL-sensor with PID controller then send command to steering and speeding the cars and then the cars send back about current data to raspberry pi

Self drifting main project code

Image
Main Project Code Flow chart for Main project Code: #include <Wire.h> #include <Servo.h> #include <TimerThree.h> //For Steering #define mins 45 //degree #define maxs 120 //degree #define center 83 //degree #define half_steer 37 //Maximum speed for turn steering 10ms //Speed Sensors #define speed_r 2 #define speed_l 3 #define length_4pulse 8 //80 millimeter 8 centimeter #define speed_mins 0 #define speed_maxs 100 //For Motor Drive #define InA_PIN 5 //Yellow #define InB_PIN 6 //Blue #define PWM_PIN 4 //Green //INA 1 INB 0 clockwise FORWARD //INA 0 INB 1 counterclockwise REVERSE //Ultrasonic //ADDRESS #define Front_Left 112//0x70//0xE0 #define Front_Right 114//0x72//0xE4 #define Back_Left 116//0x74//0xE8 #define Back_Right 118//0x76//0xEC #define CMD 0x00 #define RANGE_CMD 0x02 #define RANGE_SET 0x18 #define Read_inch 0x50 #define Read_cen 0x51 #define Read_micro_sec 0x52 #define Read_pointer 0x02 #define ultrasonic_mins 6 //CMPS03 Compass Module #defi

Hot Lapse

Image
Hot Lapse Code Flow chart for Hot Lapse Challenge Code: #include <Wire.h> #include <Servo.h> //For Steering #define mins 45 //degree #define maxs 120 //degree #define center 83 //degree #define half_steer 37 //Maximum speed for turn steering 10ms //For Motor Drive #define InA_PIN 5 //Yellow #define InB_PIN 6 //Blue #define PWM_PIN 4 //Green //INA 1 INB 0 clockwise FORWARD //INA 0 INB 1 counterclockwise REVERSE //For Ultrasonic //ADDRESS #define Front_Left 112//0x70//0xE0 #define Front_Right 114//0x72//0xE4 #define Back_Left 116//0x74//0xE8 #define Back_Right 118//0x76//0xEC #define CMD 0x00 #define RANGE_CMD 0x02 #define RANGE_SET 0x18 #define Read_inch 0x50 #define Read_cen 0x51 #define Read_micro_sec 0x52 #define Read_pointer 0x02 //Sharp Infrared sensors #define Front_sensor A6 #define Rear_sensor A7 //PID Control #define p_value 6 #define i_value 0 //0.5 #define d_value 0 //4 Servo myservo; int angle = center; float error = 0; float error_p = 0; flo

ET-MMA7331L (3-Axis Analog Output Accelerometer)

Image
ET-MMA7331L ET-MMA7331L This sensor can give an output for accelerometer in 3-axis (X, Y, Z) with analog output. You can set g-force to measure as 4g or 12g and you can convert output from voltage to g unit by using this equation. for Voffset is VDD/2 (VDD is power source voltage) and for sensitivity please use the value from this following table. Table 1: Sensitivity and g-select After you get Vout by using ADC then you can calculate back to get g-value for each channel (X, Y, Z) Important: Voltage tolerant of this module is 3.6V, if you work on a 5V MCU please be careful Sample Code: //Accelerometer #define X_OUT A8 #define Y_OUT A9 #define Z_OUT A10 #define Voffset 337 // 3.3/2 = 1.65v -> 1.65*1023/5 = 337.59 #define sensitivity 63 // 0.308 -> 0.308*1023/5 = 63.0168 float x_value = 0; float y_value = 0; float z_value = 0; void setup() { //Accelerometer Initial pinMode(X_OUT, INPUT); pinMode(Y_OUT, INPUT); pinMode(Z_OUT, INPUT);

Complete Track Build

Image
Complete Track Track for autonomous driving Leg Design Material: Future board Tape

HAL Sensors for speed measurement

Image
HAL Sensors Uni- and Bipolar Hall IC Switches for Magnetic Field Applications TLE 4905L This hall sensor is an open collector sensor, So how to get the output from this sensor is you need to add a resistor RL 1.2k ohm as a circuit below. Application Circuit from Datasheet Signal capture from oscilloscope Sample Code: #include <TimerThree.h> //Speed Sensors #define speed_r 2 #define speed_l 3 #define length_4pulse 80 //millimeter volatile int speed_pulse = 0; volatile float current_speed = 0; void setup() { // put your setup code here, to run once: Serial.begin(115200); //Speed Detect pinMode(speed_r, INPUT); pinMode(speed_l, INPUT); attachInterrupt(digitalPinToInterrupt(speed_r), speed_count, RISING); Timer3.initialize(100000); // initialize timer3, and set a 1/10 second period Timer3.attachInterrupt(speed_calculate); } void loop() { // put your main code here, to run repeatedly: //Correct Data Serial.println("----&q

Change I2C Address SRF10

Change I2C Address of SRF10 Address Long Flash Short flashes Decimal Hex 224 E0 1 0 226 E2 1 1 228 E4 1 2 230 E6 1 3 232 E8 1 4 234 EA 1 5 236 EC 1 6 238 EE 1 7 240 F0 1 8 242 F2 1 9 244 F4 1 10 246 F6 1 11 248 F8 1 12 250 FA 1 13 252 FC 1 14 254 FE 1 15 Address Table For SRF10 can set ID for I2C up to 16 address as a table upper, So this post is about how to set ID for every SRF10. First, you need to have an only one SRF10 connect to I2C bus then use to the following code. Change Address Code: #include <Wire.h> #define ADDRESS byte(0x72) //defines address #define NEW_ADDRESS byte(0xEC) //defines address #define CMD byte(0x00) void setup() { // put your setup code here, to run once: Wire.begin(); //conects I2C Serial.begin(115200); } void loop() { // put your main code here, to run repeatedly: delay(5000); Serial.println("Begin"); Wire.beginTransmission(ADDRESS); Wire.write(CMD); Wire.write(byte(0xA0)); Wire.end