-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from A2Technology/Arduino-A2-Working
Minor errors fixed
- Loading branch information
Showing
4 changed files
with
92 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
float vel(int select) | ||
long interval = 1000; //choose interval is 1 second (1000 milliseconds) | ||
long previousMillis = 0; | ||
long currentMillis = 0; | ||
|
||
long currentEncoder; | ||
long previousEncoder; | ||
|
||
float read_speed(int select) | ||
{ | ||
//read velocity of selected motor | ||
//return velocity in rad/s | ||
const int Encoder_1_round=30 000; //define number of pulses in one round of encoder | ||
switch (select) | ||
{ | ||
case 1: | ||
CurrentEncoder = Encoder_1.read(); | ||
currentEncoder = Encoder_1.read(); | ||
break; | ||
case 2: | ||
CurrentEncoder = Encoder_2.read(); | ||
currentEncoder = Encoder_2.read(); | ||
break; | ||
case 3: | ||
CurrentEncoder = Encoder_3.read(); | ||
currentEncoder = Encoder_3.read(); | ||
break; | ||
} | ||
|
||
float rot_speed; | ||
currentMillis = millis(); | ||
if (currentMillis - previousMillis > interval) | ||
{ | ||
previousMillis = currentMillis; | ||
|
||
rpm = (float)abs(((CurrentEncoder - previousEncoder) * 2 * PI / ENCODEROUTPUT)); | ||
Serial.println(rpm); | ||
previousEncoder = CurrentEncoder; | ||
|
||
return rpm; | ||
rot_speed = (float)abs(((currentEncoder - previousEncoder) * 2 * PI / Encoder_1_round)); | ||
previousEncoder = currentEncoder; | ||
return rot_speed; | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters