Skip to content
2 changes: 1 addition & 1 deletion Ashrumachan/Tasks.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
5th October 2019
5th october 2019
Mapping code using encoders
2 changes: 1 addition & 1 deletion Ashrumachan/mapping_encoder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define enc_21 3
#define enc_22 5

volatile int enc1_val = 0;
volatile int enc1_val = 0
volatile int enc2_val = 0;
int x_counter,x_motion,y_counter,y_motion;
void setup() {
Expand Down
51 changes: 19 additions & 32 deletions Ashrumachan/shorter_path.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

int d_1, d_2, d_3, d_4;
int s1, s2, s3, s4;
int count = 0, sf = 1, w = 0;
int x_val, y_val, x_motion, y_motion;
int count = 0, sf = 1, w = 0,angle;
int x_val, y_val, x_motion, y_motion,x,y;
volatile int c = 0;
volatile int c1 = 0;
int x, y, arr[8][2] = {{0, 0}, {10, 0}, {10, 8}, {12, 8}, {12, 12}, {10, 12}, {10, 20}, {20, 20}};
int x_counter=0, y_counter=0,x_count,y_count, arr[4][2] = {{0, 0}, {10, 8}, {12, 8}, {20, 20}};
void motion(int x_val, int y_val);
void setup() {
pinMode(a, INPUT);
Expand Down Expand Up @@ -40,42 +40,29 @@ void setup() {

void loop()
{
Serial.print(c);
Serial.print(" ");
Serial.print(c1);
Serial.println(" ");
x = c / 100;
y = c1 / 100;

if (count % 2 == 0)
{
if (x == 12)
{
do {
motion (-200, 0);
}
while (x != arr[count][0]);
x_count= c / 100;
x_counter = x_counter+x_count;
y_count= c1 / 100;
y_counter = y_counter+y_count;

}
else {
do {
motion (200, 0);
}
while (x != arr[count][0]);
}
count++;
}
else
for (int i = 1; i <= 3; i++)
{
do {
motion (0, 200);
while (x_counter != arr[i][0] && y_counter != arr[i][1])
{
x_val = arr[i][0] - x_counter;
y_val = arr[i][1] - y_counter;
angle = atan(y_val, x_val);
x_motion = map((90 - angle), -90, 90, -255, 255);
y_motion = map(angle, -90, 90, -255, 255);
motion(x_motion, y_motion);
}
while (y != arr[count][1]);
count++;
c=0;
c1=0;
}
}



void func() {

int s = digitalRead(a);
Expand Down
41 changes: 23 additions & 18 deletions Ashrumachan/task2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ volatile int enc2_val = 0;
int x_counter, x_motion, y_counter, y_motion, X_motion, Y_motion, x_val, y_val, arr[2][2] = {{0, 0}, {10, 10}};
int d_1, d_2, d_3, d_4;
int s1, s2, s3, s4;
int count = 0, sf = 1, w = 0;
int count = 0, sf = 1, w = 0,angle;
void setup() {
pinMode(enc_11, INPUT);
digitalWrite(enc_11, HIGH);
Expand All @@ -28,19 +28,25 @@ void setup() {

void loop()
{
Serial.print(enc1_val);
Serial.print(" ");
Serial.print(enc2_val);
Serial.print(" ");
x_counter = enc1_val / 100;
y_counter = enc2_val / 100;

x_val = arr[1][0] - arr[0][0];
y_val = arr[1][1] - arr[0][1];
x_motion = map(x_motion, -x_val, x_val, 0, 255);
y_motion = map(y_motion, -y_val, y_val, 0, 255);
motion(x_motion, y_motion);

while (x_counter != arr[1][0] && y_counter != arr[1][1])
{
x_val = arr[1][0] - x_counter;
y_val = arr[1][1] - y_counter;
angle = atan(y_val, x_val);

if(angle==45){
x_motion =255;
y_motion =255;
}
else
{
x_motion = map((90 - angle), -90, 90, -255, 255);
y_motion = map(angle, -90, 90, -255, 255);
}
motion(x_motion, y_motion);
}
}


Expand Down Expand Up @@ -68,14 +74,13 @@ void func1() {
}
void motion(int x_motion, int y_motion)
{
X_motion = x_motion ;
Y_motion = y_motion ;


sf = 1;
s1 = sf * (0.1768 * X_motion + 0.1768 * Y_motion + 0.25 * w);
s2 = sf * (0.1768 * X_motion + 0.1768 * Y_motion + 0.25 * w);
s3 = sf * (-0.1768 * X_motion - 0.1768 * Y_motion + 0.25 * w);
s4 = sf * (-0.1768 * X_motion - 0.1768 * Y_motion + 0.25 * w);
s1 = sf * (0.1768 * x_motion + 0.1768 * y_motion + 0.25 * w);
s2 = sf * (0.1768 * x_motion + 0.1768 * y_motion + 0.25 * w);
s3 = sf * (-0.1768 * x_motion - 0.1768 * y_motion + 0.25 * w);
s4 = sf * (-0.1768 * x_motion - 0.1768 * y_motion + 0.25 * w);
d_1 = (s1 > 0 ? 1 : 0);
d_2 = (s2 > 0 ? 1 : 0);
d_3 = (s3 > 0 ? 1 : 0);
Expand Down