Skip to content

Commit 9a8aa6b

Browse files
committed
Changes for CamJam Edukit 3 with LED's, button code and line follower. Removed camera references and all audio stuff
1 parent dc4abd8 commit 9a8aa6b

29 files changed

+281
-425
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,13 @@ static/blockly-tutorial
5858
.Trashes
5959
ehthumbs.db
6060
Thumbs.db
61+
62+
static/.DS_Store
63+
64+
static/.DS_Store
65+
66+
static/js/.DS_Store
67+
68+
static/css/.DS_Store
69+
70+
static/.DS_Store

awesomeinput.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import time
2+
import pigpio
3+
import logging
4+
5+
class Awesomeinput:
6+
"""
7+
ound trip time.
8+
"""
9+
10+
def __init__(self, pi, linesensorpin):
11+
"""
12+
The class is instantiated with the Pi to use and the
13+
gpios connected to the trigger and echo pins.
14+
"""
15+
self.pi = pi
16+
self._linesensorpin = linesensorpin
17+
pi.set_mode(self._linesensorpin, pigpio.INPUT)
18+
self._inited = True
19+
20+
def buttonInput(self, awesome_button):
21+
self.pi.set_mode(awesome_button, pigpio.INPUT)
22+
self.pi.set_pull_up_down(awesome_button, pigpio.PUD_UP)
23+
print "Button pin:" + str(awesome_button)
24+
print "Button reads: " + str(self.pi.read(awesome_button))
25+
if self.pi.read(awesome_button) == 1:
26+
return False
27+
else:
28+
return True
29+
30+
def lineSensor(self):
31+
if self._inited:
32+
if self.pi.read(self._linesensorpin) == 1:
33+
return False
34+
else:
35+
return True

awesomeoutput.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import time
2+
import pigpio
3+
import logging
4+
5+
class Awesomeoutput:
6+
"""
7+
ound trip time.
8+
"""
9+
10+
def __init__(self, pi):
11+
"""
12+
The class is instantiated with the Pi to use and the
13+
gpios connected to the trigger and echo pins.
14+
"""
15+
self.pi = pi
16+
17+
18+
def ledOutput(self, awesome_led, LED_State):
19+
self.pi.set_mode(awesome_led, pigpio.OUTPUT)
20+
self.pi.write(awesome_led, LED_State)

coderbot.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
import config
2424
import logging
2525
import sonar
26+
import awesomeoutput
27+
import awesomeinput
28+
2629

2730
PIN_MOTOR_ENABLE = 22
2831
PIN_LEFT_FORWARD = 8
@@ -34,27 +37,26 @@
3437
#PIN_SERVO_4 = 10
3538
PIN_SONAR_1_TRIGGER = 17
3639
PIN_SONAR_1_ECHO = 18
37-
#PIN_SONAR_2_TRIGGER = 18
38-
#PIN_SONAR_2_ECHO = 8
39-
#PIN_SONAR_3_TRIGGER = 18
40-
#PIN_SONAR_3_ECHO = 23
41-
#PIN_ENCODER_LEFT = 14
42-
#PIN_ENCODER_RIGHT = 15
4340

4441
PWM_FREQUENCY = 100 #Hz
4542
PWM_RANGE = 100 #0-100
4643

44+
PIN_LINE_SENSOR = 25
45+
46+
#OUTPUT_LED = 1
47+
#PIN_LED = 24
48+
4749
def coderbot_callback(gpio, level, tick):
4850
return CoderBot.get_instance().callback(gpio, level, tick)
4951

5052
class CoderBot:
51-
_pin_out = [PIN_MOTOR_ENABLE, PIN_LEFT_FORWARD, PIN_RIGHT_FORWARD, PIN_LEFT_BACKWARD, PIN_RIGHT_BACKWARD, PIN_SERVO_3, PIN_SERVO_4]
53+
_pin_out = [PIN_MOTOR_ENABLE, PIN_LEFT_FORWARD, PIN_RIGHT_FORWARD, PIN_LEFT_BACKWARD, PIN_RIGHT_BACKWARD]
5254

5355
def __init__(self, servo=False, motor_trim_factor=1.0):
5456
self.pi = pigpio.pi('localhost')
5557
self.pi.set_mode(PIN_PUSHBUTTON, pigpio.INPUT)
56-
self.pi.set_mode(PIN_ENCODER_LEFT, pigpio.INPUT)
57-
self.pi.set_mode(PIN_ENCODER_RIGHT, pigpio.INPUT)
58+
# self.pi.set_mode(PIN_ENCODER_LEFT, pigpio.INPUT)
59+
# self.pi.set_mode(PIN_ENCODER_RIGHT, pigpio.INPUT)
5860
self._cb = dict()
5961
self._cb_last_tick = dict()
6062
self._cb_elapse = dict()
@@ -65,17 +67,15 @@ def __init__(self, servo=False, motor_trim_factor=1.0):
6567
else:
6668
self.motor_control = self._dc_motor
6769
self._cb1 = self.pi.callback(PIN_PUSHBUTTON, pigpio.EITHER_EDGE, coderbot_callback)
68-
self._cb2 = self.pi.callback(PIN_ENCODER_LEFT, pigpio.RISING_EDGE, coderbot_callback)
69-
self._cb3 = self.pi.callback(PIN_ENCODER_RIGHT, pigpio.RISING_EDGE, coderbot_callback)
7070
for pin in self._pin_out:
7171
self.pi.set_PWM_frequency(pin, PWM_FREQUENCY)
7272
self.pi.set_PWM_range(pin, PWM_RANGE)
7373

7474
self.stop()
7575
self._is_moving = False
76-
self.sonar = [sonar.Sonar(self.pi, PIN_SONAR_1_TRIGGER, PIN_SONAR_1_ECHO),
77-
sonar.Sonar(self.pi, PIN_SONAR_2_TRIGGER, PIN_SONAR_2_ECHO),
78-
sonar.Sonar(self.pi, PIN_SONAR_3_TRIGGER, PIN_SONAR_3_ECHO)]
76+
self.sonar = [sonar.Sonar(self.pi, PIN_SONAR_1_TRIGGER, PIN_SONAR_1_ECHO)]
77+
self.awesomeoutput = awesomeoutput.Awesomeoutput(self.pi)
78+
self.awesomeinput = awesomeinput.Awesomeinput(self.pi, PIN_LINE_SENSOR)
7979
self._encoder_cur_left = 0
8080
self._encoder_cur_right = 0
8181
self._encoder_target_left = -1
@@ -84,8 +84,8 @@ def __init__(self, servo=False, motor_trim_factor=1.0):
8484

8585
def exit(self):
8686
self._cb1.cancel()
87-
self._cb2.cancel()
88-
self._cb3.cancel()
87+
# self._cb2.cancel()
88+
# self._cb3.cancel()
8989
for s in self.sonar:
9090
s.cancel()
9191

@@ -122,6 +122,15 @@ def servo4(self, angle):
122122
def get_sonar_distance(self, sonar_id=0):
123123
return self.sonar[sonar_id].get_distance()
124124

125+
def ledOutput(self, pin_led, output_led):
126+
self.awesomeoutput.ledOutput(pin_led, output_led)
127+
128+
def buttonInput(self, pin_button):
129+
return self.awesomeinput.buttonInput(pin_button)
130+
131+
def lineSensor(self):
132+
return self.awesomeinput.lineSensor()
133+
125134
def _dc_motor(self, speed_left=100, speed_right=100, elapse=-1, steps_left=-1, steps_right=-1 ):
126135
self._encoder_cur_left = 0
127136
self._encoder_cur_right = 0

data/program_face_find.data

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/program_find_code_test.data

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/program_find_color.data

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/program_find_text.data

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/program_hear_test.data

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/program_img_average_test.data

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/program_obstacle_avoidance.data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"dom_code": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"controls_whileUntil\" x=\"38\" y=\"95\"><field name=\"MODE\">WHILE</field><value name=\"BOOL\"><block type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></block></value><statement name=\"DO\"><block type=\"controls_if\"><mutation else=\"1\"></mutation><value name=\"IF0\"><block type=\"logic_compare\"><field name=\"OP\">LT</field><value name=\"A\"><block type=\"coderbot_sonar_get_distance\"><field name=\"SONAR\"></field></block></value><value name=\"B\"><block type=\"math_number\"><field name=\"NUM\">10</field></block></value></block></value><statement name=\"DO0\"><block type=\"coderbot_adv_move\"><field name=\"ACTION\">RIGHT</field><value name=\"SPEED\"><block type=\"math_number\"><field name=\"NUM\">100</field></block></value><value name=\"ELAPSE\"><block type=\"math_number\"><field name=\"NUM\">0.5</field></block></value></block></statement><statement name=\"ELSE\"><block type=\"coderbot_adv_move\"><field name=\"ACTION\">FORWARD</field><value name=\"SPEED\"><block type=\"math_number\"><field name=\"NUM\">100</field></block></value><value name=\"ELAPSE\"><block type=\"math_number\"><field name=\"NUM\">-1</field></block></value></block></statement></block></statement><next><block type=\"coderbot_adv_stop\"></block></next></block></xml>", "code": "while True:\n get_prog_eng().check_end()\n if get_bot().get_sonar_distance() < 10:\n get_bot().right(speed=100, elapse=0.5)\n else:\n get_bot().forward(speed=100, elapse=-1)\nget_bot().stop()\n", "name": "obstacle_avoidance"}
1+
{"dom_code": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"controls_whileUntil\" x=\"38\" y=\"95\"><field name=\"MODE\">WHILE</field><value name=\"BOOL\"><block type=\"logic_boolean\"><field name=\"BOOL\">TRUE</field></block></value><statement name=\"DO\"><block type=\"controls_if\"><mutation else=\"1\"></mutation><value name=\"IF0\"><block type=\"logic_compare\"><field name=\"OP\">LT</field><value name=\"A\"><block type=\"coderbot_sonar_get_distance\"><field name=\"SONAR\"></field></block></value><value name=\"B\"><block type=\"math_number\"><field name=\"NUM\">10</field></block></value></block></value><statement name=\"DO0\"><block type=\"coderbot_adv_move\"><field name=\"ACTION\">RIGHT</field><value name=\"SPEED\"><block type=\"math_number\"><field name=\"NUM\">100</field></block></value><value name=\"ELAPSE\"><block type=\"math_number\"><field name=\"NUM\">0.5</field></block></value></block></statement><statement name=\"ELSE\"><block type=\"coderbot_adv_move\"><field name=\"ACTION\">FORWARD</field><value name=\"SPEED\"><block type=\"math_number\"><field name=\"NUM\">100</field></block></value><value name=\"ELAPSE\"><block type=\"math_number\"><field name=\"NUM\">-1</field></block></value></block></statement></block></statement><next><block type=\"coderbot_adv_stop\"></block></next></block></xml>", "code": "while True:\n get_prog_eng().check_end()\n if get_bot().get_sonar_distance() < 10:\n get_bot().right(speed=100, elapse=0.5)\n else:\n get_bot().forward(speed=100, elapse=-1)\nget_bot().stop()\n", "name": "obstacle_avoidance"}

data/program_path_ahead.data

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/program_sound_rec_test.data

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/program_test_sound.data

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/program_test_speech_recog.data

Lines changed: 0 additions & 1 deletion
This file was deleted.

infrared.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import time
2+
import pigpio
3+
import logging
4+
5+
#
6+
# Infrared Sensor from CamJam Edukit3
7+
#
8+
# Pin 1 - 5V
9+
# Pin 2 - Ground
10+
# Pin 3 - gpio (here P1-8, gpio 14, TXD is used)
11+
#
12+
# The internal gpio pull-up is enabled so that the sensor
13+
# normally reads high. It reads low when a magnet is close.
14+
#
15+
16+
INFRARED=14
17+
18+
pi = pigpio.pi() # connect to local Pi
19+
20+
pi.set_mode(HALL, pigpio.INPUT)
21+
pi.set_pull_up_down(HALL, pigpio.PUD_UP)
22+
23+
start = time.time()
24+
25+
while (time.time() - start) < 60:
26+
print("Hall = {}".format(pi.read(HALL)))
27+
time.sleep(0.2)
28+
29+
pi.stop()

0 commit comments

Comments
 (0)