-
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.
- Loading branch information
1 parent
0ca9713
commit 70ea131
Showing
5 changed files
with
103 additions
and
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef DEAD_RECKONING_H | ||
#define DEAD_RECKONING_H | ||
|
||
#include <Arduino.h> | ||
|
||
extern float disp_r_wheel; | ||
extern float disp_l_wheel; | ||
extern int count_R_prev; | ||
extern int count_L_prev; | ||
extern float x; | ||
extern float y; | ||
extern float theta; | ||
extern float meter_per_ticks; | ||
extern float orientation_angle; | ||
extern float disp_body; | ||
|
||
extern int count_R; | ||
extern int count_L; | ||
extern const int channel_R; | ||
extern const int channel_L; | ||
extern int Right_motor_speed; | ||
extern int Left_motor_speed; | ||
|
||
void calculate_traveling(); | ||
|
||
#endif |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// http://www-personal.umich.edu/~johannb/position.htm book link | ||
|
||
#include <Arduino.h> | ||
#include "dead_Reckoning.h" | ||
#include "EncoderControl.h" | ||
//Fixed values | ||
#define WHEEL_DIAMETER 0.0335 | ||
#define PULSES_PER_REVOLUTION 4096.0 | ||
#define AXLE_LENGTH 0.067 | ||
#define PI 3.1416 | ||
|
||
// New Variables | ||
float disp_r_wheel = 0; | ||
float disp_l_wheel = 0; | ||
int count_R_prev = 0; | ||
int count_L_prev = 0; | ||
float x = 0; | ||
float y = 0; | ||
float theta = 0; | ||
float meter_per_ticks = PI * WHEEL_DIAMETER / PULSES_PER_REVOLUTION; | ||
float orientation_angle , disp_body; | ||
|
||
// Old Variables | ||
int count_R = 0; //For Encoders | ||
int count_L = 0; | ||
|
||
void calculate_traveling(){ | ||
|
||
count_L_prev = count_L; | ||
count_R_prev = count_R; | ||
count_L = cummulativePos0(); | ||
count_R = cummulativePos1(); | ||
disp_l_wheel = (float)count_L_prev * meter_per_ticks; // geting distance in meters each wheel has traveled | ||
disp_r_wheel = (float)count_R_prev * meter_per_ticks; | ||
|
||
if (count_L_prev == count_R_prev) | ||
{ // The Straight line condition -> book reference Where am i ? | ||
x += disp_l_wheel * cos(theta); | ||
y += disp_l_wheel * sin(theta); | ||
} | ||
else // for circular arc equations change | ||
{ orientation_angle = (disp_r_wheel - disp_l_wheel)/AXLE_LENGTH; | ||
disp_body = (disp_r_wheel + disp_l_wheel) / 2.0; | ||
x += (disp_body/orientation_angle) * (sin(orientation_angle + theta) - sin(theta)); | ||
y -= (disp_body/orientation_angle) * (cos(orientation_angle + theta) - cos(theta)); | ||
theta += orientation_angle; | ||
|
||
|
||
while(theta > PI) | ||
theta -= (2.0*PI); | ||
while(theta < -PI) | ||
theta += (2.0*PI); | ||
} | ||
} | ||
|
||
|
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