Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/embedded/11 #43

Open
wants to merge 4 commits into
base: embedded
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
[[PCB fabrication @16]]
[[Robot mechanical design @13]]
[[robot movement algorithm @19]]
[[Test hardware components @11]]
[[Test-hardware-components@11]]
14 changes: 14 additions & 0 deletions Graduation-Project-Documentation/Embedded/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
> ## ***This is a documentation for issue #11***
> `Testing hardware components using arduino ide`

## 1. Testing the 3 Motors using cytrons 1 channel.
- We provide speed and direction control of the 2 motors using 2 cytrons 1 channel, the third motor is used for the lifting mechanism so we only need direction control.

## 2. Getting encoders readings.
- By comparing the two sets of pulses out of the encoder we can determine the direction of the motor.
- Depending on the direction we count rising edges of the pulses by interrupt to evaluate revolution per minite.
- `RPM = ( counts / encoder resolution )*60`
- Finally, we display the readings of counts, RPM and Motor direction on a serial monitor every 1 sec.



66 changes: 66 additions & 0 deletions Test-hardware-components/Arduino-test-code/Arduino-test-code.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#define motor1_dir PA0
#define motor2_dir PA2
#define motor1_pwm PA1
#define motor2_pwm PA3

#define motor1_encoder_int1 PA5
#define motor1_encoder_int2 PA6

int countA = 0, countB = 0;
int currentStateCLK;
int previousStateCLK;

String encdir ="";
float last_time = 0, current_time = 0;
float RPM = 0;

void setup() {

// pinMode(motor1_dir, OUTPUT);
// pinMode(motor1_pwm, OUTPUT);
pinMode(motor1_encoder_int1,INPUT);
pinMode(motor1_encoder_int2,INPUT);
attachInterrupt(digitalPinToInterrupt(motor1_encoder_int1), fucnA,RISING);

Serial.begin(9600);
}

void fucnA(){

currentStateCLK = digitalRead(motor1_encoder_int1);

// If the inputDT state is different than the inputCLK state then
// the encoder is rotating clockwise
if (digitalRead(motor1_encoder_int2) != currentStateCLK) {
countA ++;
encdir ="CW";


} else {
// Encoder is rotating counterclockwise
countA --;
encdir ="CCW";

}

}

void loop() {

//analogWrite(motor1_pwm, 255);
//digitalWrite(motor1_dir,HIGH);
current_time = millis();
if ((current_time-last_time)>1000){
RPM = (countA/230)*60;
last_time = current_time;
Serial.print("countA = ");
Serial.println(countA);
Serial.print("Dir: ");
Serial.println(encdir);
Serial.print("RPM: ");
Serial.println(RPM);
countA = 0;

}

}
14 changes: 14 additions & 0 deletions Test-hardware-components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
> ## ***This is a documentation for issue #11***
> `Testing hardware components using arduino ide`

## 1. Testing the 3 Motors using cytrons 1 channel.
- We provide speed and direction control of the 2 motors using 2 cytrons 1 channel, the third motor is used for the lifting mechanism so we only need direction control.

## 2. Getting encoders readings.
- By comparing the two sets of pulses out of the encoder we can determine the direction of the motor.
- Depending on the direction we count rising edges of the pulses by interrupt to evaluate revolution per minite.
- `RPM = ( counts / encoder resolution )*60`
- Finally, we display the readings of counts, RPM and Motor direction on a serial monitor every 1 sec.