Lecture Assignment 3: Added Inertia and Friction to SystemOverview: In this assignment we add friction and then inertia to the motor system. We gather experimental data and use this to update the simulation parameters so the simulation matches the experimental results.
/* * MAE 156A - Interrupt Function for Measuring No-Load Speed * Motor: Pololu Motor 3260 * Spec No-Load Speed: 5600 RPM * * September 29th, 2016 * */ #define motor_pwm 3 //define PWM pin number for motor pwm #define motor_dir 12 //define digital pin number for motor direction int encA = 2; //define Encoder A channel pin int encAnow = LOW; //define current state of Encoder A int encAprev = LOW; //define previous state of Encoder A unsigned long t, count; //interrupt timing and counting variables void setup() { Serial.begin(115200); //serial output transmission rate (bps) pinMode(encA, INPUT); //Encoder A on motor encoder // Using the interrupt on Digital Pin #2 attachInterrupt(digitalPinToInterrupt(encA),encoder,CHANGE); pinMode(motor_dir, OUTPUT); //define Pin 12 for motor direction (HIGH or LOW) digitalWrite(motor_dir, HIGH); //set motor direction analogWrite(motor_pwm, 255); //set motor speed in duty cycle (0-255) } void loop() { Serial.print(micros()); //time base for speed data Serial.print(","); //data separator character Serial.println(count); //counts for position and velocity calculation } void encoder() { //interrupt handler code encAnow = digitalRead(encA); //read the current state of Encoder A // Check if Encoder A is transitioning from 'LOW' to 'HIGH' State if ((encAprev == LOW) && (encAnow == HIGH)) { count++; //increase the number of Encoder A count } encAprev = encAnow; //set the previous Encoder A reading as same as the current reading } |