Skip to content

Commit 8b3b6e8

Browse files
Add files via upload
1 parent 01fa2ff commit 8b3b6e8

File tree

2 files changed

+294
-0
lines changed

2 files changed

+294
-0
lines changed

Diff for: classmoto.ino

+202
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
#include <Servo.h>
2+
Servo m;
3+
Servo u;
4+
Servo d;
5+
int i,t,c,b;
6+
int x=0;
7+
int y=0;
8+
int j;
9+
void setup()
10+
{
11+
Serial.begin(9600);
12+
m.attach(9);
13+
u.attach(5);
14+
d.attach(11);
15+
pinMode(6,INPUT);
16+
pinMode(7,INPUT);
17+
18+
m.write(90);
19+
delay(100);
20+
u.write(0);
21+
delay(100);
22+
d.write(45);
23+
delay(4000);
24+
c=90;
25+
t=0;
26+
b=45;
27+
start();
28+
}
29+
30+
31+
32+
void start ()
33+
{
34+
delay(1500); // up movement
35+
for(i=c;i>=15;i--)
36+
{
37+
m.write(i);
38+
delay(10);
39+
c=10;
40+
}
41+
delay(1000);
42+
t=45;
43+
u.write(t);
44+
delay(1000);
45+
46+
for(i=b;i>=0;i--)
47+
{
48+
d.write(i);
49+
delay(10);
50+
b=0;
51+
}
52+
53+
delay(1500);
54+
55+
u.write(0);
56+
delay(1500);
57+
for(i=c;i<=90;i++) //down movement
58+
{
59+
m.write(i);
60+
delay(10);
61+
c=90;
62+
}
63+
delay(1000);
64+
t=0;
65+
66+
digitalWrite(2,LOW);
67+
digitalWrite(4,HIGH);
68+
delay(1500);
69+
70+
digitalWrite(2,LOW);
71+
digitalWrite(4,LOW);
72+
delay(1000);
73+
74+
}
75+
76+
77+
class move
78+
{
79+
public:
80+
81+
void color(int n)
82+
{
83+
delay(1500);
84+
digitalWrite(2,HIGH);//close grip
85+
digitalWrite(4,LOW);
86+
delay(1500);
87+
for(i=90;i>=15;i--) //up movement of centre and top motor
88+
{
89+
m.write(i);
90+
delay(10);
91+
92+
}
93+
delay(1500);
94+
for(j=0;j<=45;j++) //up movement of centre and top motor
95+
{
96+
u.write(j);
97+
delay(10);
98+
99+
}
100+
delay(1500);
101+
for(i=0;i<=n;i++) //bottom motor
102+
{
103+
d.write(i);
104+
delay(10);
105+
106+
}
107+
delay(1500);
108+
109+
for(j=45;j>=0;j--) //down movement of centre and top
110+
{
111+
u.write(j);
112+
delay(10);
113+
}
114+
delay(1500);
115+
for(i=15;i<=90;i++) //down movement of centre and top
116+
{
117+
m.write(i);
118+
delay(10);
119+
120+
121+
}
122+
delay(1500);
123+
digitalWrite(2,LOW);
124+
digitalWrite(4,HIGH);
125+
delay(1500);
126+
127+
digitalWrite(2,LOW);
128+
digitalWrite(4,LOW);
129+
delay(1000);
130+
131+
delay(1500);
132+
133+
for(i=90;i>=15;i--) //up movement of centre and top
134+
{
135+
m.write(i);
136+
delay(10);
137+
}
138+
delay(1500);
139+
for(j=0;j<=45;j++) //up movement of centre and top
140+
{
141+
u.write(j);
142+
delay(10);
143+
}
144+
delay(1500);
145+
for(i=n;i>=0;i--) // move down to 0
146+
{
147+
d.write(i);
148+
delay(10);
149+
150+
}
151+
delay(1500);
152+
for(j=45;j>=0;j--) //down
153+
{
154+
u.write(j);
155+
delay(10);
156+
157+
}
158+
delay(1500);
159+
for(i=15;i<=90;i++) //down
160+
{
161+
m.write(i);
162+
delay(10);
163+
164+
}
165+
166+
167+
168+
}
169+
};
170+
void loop()
171+
{
172+
173+
x=digitalRead(6);
174+
y=digitalRead(7);
175+
if((x==HIGH)&&(y==LOW))
176+
{
177+
move b;
178+
b.color(90);
179+
}
180+
else if((x==LOW)&&(y==HIGH))
181+
{
182+
183+
move g;
184+
g.color(135);
185+
}
186+
187+
else if((x==HIGH)&&(y==HIGH))
188+
{
189+
move r;
190+
r.color(180);
191+
}
192+
else
193+
{
194+
}
195+
196+
197+
x=LOW;
198+
y=LOW;
199+
}
200+
201+
202+

Diff for: colordetect.py

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import RPi.GPIO as GPIO
2+
pin=11
3+
pin1=13
4+
GPIO.setmode(GPIO.BOARD)
5+
GPIO.setwarnings(False)
6+
GPIO.setup(pin,GPIO.OUT)
7+
GPIO.setup(pin1,GPIO.OUT)
8+
9+
a=0
10+
import cv2
11+
import numpy as np
12+
import time
13+
cap = cv2.VideoCapture(0)
14+
while True:
15+
cr=0
16+
cb=0
17+
cg=0
18+
ret,im = cap.read()
19+
20+
#frame=cv2.imread('1.2.jpg',1)
21+
hsv = cv2.cvtColor(im,cv2.COLOR_BGR2HSV)
22+
#lower mask red
23+
'''lower_red = np.array([0,50,50])
24+
upper_red = np.array([20,255,255])
25+
mask0 = cv2.inRange(hsv, lower_red ,upper_red)
26+
27+
#upper mask red
28+
lower_red = np.array([170,50,50])
29+
upper_red = np.array([180,255,255])
30+
mask1 = cv2.inRange(hsv, lower_red ,upper_red)
31+
mask=mask0+mask1'''
32+
#yellow
33+
lowyellow=np.array([20,50,100],dtype=np.uint8)
34+
highyellow=np.array([42,255,255],dtype=np.uint8)
35+
mask = cv2.inRange(hsv, lowyellow,highyellow)
36+
#blue
37+
lowblue=np.array([110,130,50],dtype=np.uint8)
38+
highblue=np.array([130,255,255],dtype=np.uint8)
39+
maskb = cv2.inRange(hsv, lowblue,highblue)
40+
#green
41+
lowgreen=np.array([44,54,63],dtype=np.uint8)
42+
highgreen=np.array([90,255,255],dtype=np.uint8)
43+
maskg = cv2.inRange(hsv, lowgreen,highgreen)
44+
45+
cv2.imshow('mask red',mask)
46+
#cv2.imshow('mask blue',maskb)
47+
#cv2.imshow('mask green',maskg)
48+
cr=cv2.countNonZero(mask)
49+
cb=cv2.countNonZero(maskb)
50+
cg=cv2.countNonZero(maskg)
51+
if(cb>4000):
52+
print 'blue'
53+
GPIO.output(pin,GPIO.HIGH)
54+
GPIO.output(pin1,GPIO.LOW)
55+
time.sleep(1)
56+
GPIO.output(pin,GPIO.LOW)
57+
GPIO.output(pin1,GPIO.LOW)
58+
elif(cg>4000):
59+
print 'green'
60+
GPIO.output(pin,GPIO.LOW)
61+
GPIO.output(pin1,GPIO.HIGH)
62+
time.sleep(1)
63+
GPIO.output(pin,GPIO.LOW)
64+
GPIO.output(pin1,GPIO.LOW)
65+
elif(cr>8000):
66+
print 'yellow'
67+
GPIO.output(pin,GPIO.HIGH)
68+
GPIO.output(pin1,GPIO.HIGH)
69+
time.sleep(1)
70+
GPIO.output(pin,GPIO.LOW)
71+
GPIO.output(pin1,GPIO.LOW)
72+
GPIO.output(pin,GPIO.LOW)
73+
GPIO.output(pin1,GPIO.LOW)
74+
75+
#print ('red=',cr)
76+
#print ('blue',cb)
77+
#print ('green',cg)
78+
if cv2.waitKey(1) & 0xff==ord('q'):
79+
80+
break
81+
82+
83+
84+
85+
86+
87+
88+
#cv2.waitKey()
89+
cap.release()
90+
cv2.destroyAllWindows()
91+
92+

0 commit comments

Comments
 (0)