Skip to content

Commit c889fb4

Browse files
previavivace
andauthored
prepare v4.1 (#163)
- tf 2.7 - fix 4.1 bugs - Update wifi.py => changed approach: the daemons (hostapd, dhcpcd, wpa_supplicant) are started by systemd, wify.py is used to change config and verify connectivity in client mode. - add CONTRIBUTING.md (#162) Co-authored-by: previ <[email protected]> Co-authored-by: Antonio Vivace <[email protected]>
1 parent cb29665 commit c889fb4

13 files changed

+490
-118
lines changed

CONTRIBUTING.md

+336
Large diffs are not rendered by default.

api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
bot_config = Config.get()
2424
bot = CoderBot.get_instance(
2525
motor_trim_factor=float(bot_config.get("move_motor_trim", 1.0)),
26-
encoder=bool(bot_config.get("encoder"))
26+
hw_version=bot_config.get("hw_version")
2727
)
2828

2929
def get_serial():

camera.py

-13
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class Camera(object):
4949
# pylint: disable=too-many-public-methods
5050

5151
_instance = None
52-
_img_template = image.Image.load("static/media/coderdojo-logo.png")
5352

5453
@classmethod
5554
def get_instance(cls):
@@ -252,18 +251,6 @@ def find_line(self):
252251
self.set_image_cv(img)
253252
return coords
254253

255-
def find_signal(self):
256-
angle = None
257-
ts = time.time()
258-
img = self.get_image()
259-
signals = img.find_template(self._img_template)
260-
261-
logging.info("signal: %s", str(time.time() - ts))
262-
if signals:
263-
angle = signals[0].angle
264-
265-
return angle
266-
267254
def find_face(self):
268255
face_x = face_y = face_size = None
269256
img = self.get_image()

coderbot.cfg

+46-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,46 @@
1-
{"move_power_angle_3": "60", "cnn_default_model": "generic_fast_low", "prog_maxblocks": "-1", "camera_jpeg_quality": "5", "show_page_control": "true", "camera_framerate": "30", "prog_scrollbars": "true", "move_fw_speed": "100", "prog_level": "adv", "move_motor_trim": "1", "move_motor_mode": "dc", "cv_image_factor": "2", "move_power_angle_1": "45", "camera_path_object_size_min": "4000", "button_func": "none", "camera_color_object_size_min": "4000", "camera_jpeg_bitrate": "1000000", "move_fw_elapse": "1", "show_control_move_commands": "true", "camera_color_object_size_max": "160000", "show_page_prefs": "true", "camera_exposure_mode": "auto", "ctrl_tr_elapse": "-1", "show_page_program": "true", "move_tr_elapse": "0.5", "camera_path_object_size_max": "160000", "sound_shutter": "$shutter.wav", "ctrl_fw_elapse": "-1", "sound_stop": "$shutdown.wav", "ctrl_tr_speed": "80", "ctrl_fw_speed": "100", "move_tr_speed": "85", "move_power_angle_2": "60", "ctrl_hud_image": "", "load_at_start": "", "sound_start": "$startup.wav", "encoder": "True", "audio_volume_level": "100", "wifi_mode": "ap", "wifi_ssid": "coderbot", "wifi_psk": "coderbot", "packages_installed": ""}
1+
{
2+
"move_power_angle_3":"60",
3+
"cnn_default_model":"generic_fast_low",
4+
"prog_maxblocks":"-1",
5+
"camera_jpeg_quality":"5",
6+
"show_page_control":"true",
7+
"camera_framerate":"30",
8+
"prog_scrollbars":"true",
9+
"move_fw_speed":"100",
10+
"prog_level":"adv",
11+
"move_motor_trim":"1",
12+
"move_motor_mode":"dc",
13+
"cv_image_factor":"2",
14+
"move_power_angle_1":"45",
15+
"camera_path_object_size_min":"4000",
16+
"button_func":"none",
17+
"camera_color_object_size_min":"4000",
18+
"camera_jpeg_bitrate":"1000000",
19+
"move_fw_elapse":"1",
20+
"show_control_move_commands":"true",
21+
"camera_color_object_size_max":"160000",
22+
"show_page_prefs":"true",
23+
"camera_exposure_mode":"auto",
24+
"ctrl_tr_elapse":"-1",
25+
"show_page_program":"true",
26+
"move_tr_elapse":"0.5",
27+
"camera_path_object_size_max":"160000",
28+
"sound_shutter":"$shutter.wav",
29+
"ctrl_fw_elapse":"-1",
30+
"sound_stop":"$shutdown.wav",
31+
"ctrl_tr_speed":"80",
32+
"ctrl_fw_speed":"100",
33+
"move_tr_speed":"85",
34+
"move_power_angle_2":"60",
35+
"ctrl_hud_image":"",
36+
"load_at_start":"",
37+
"sound_start":"$startup.wav",
38+
"hw_version":"5",
39+
"audio_volume_level":"100",
40+
"wifi_mode":"ap",
41+
"wifi_ssid":"coderbot_CHANGEMEATFIRSTRUN",
42+
"wifi_psk":"coderbot",
43+
"packages_installed":"",
44+
"admin_password":"",
45+
"hardware_version":"5"
46+
}

coderbot.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class GPIO_CODERBOT_V_4():
5454
PIN_ENCODER_RIGHT_A = 15
5555
PIN_ENCODER_RIGHT_B = 12
5656

57+
HAS_ENCODER = False
58+
5759
class GPIO_CODERBOT_V_5():
5860
# motors
5961
PIN_MOTOR_ENABLE = None #22
@@ -82,29 +84,36 @@ class GPIO_CODERBOT_V_5():
8284
PIN_ENCODER_RIGHT_A = 24 #15
8385
PIN_ENCODER_RIGHT_B = 25 #12
8486

87+
HAS_ENCODER = True
88+
8589
# PWM
8690
PWM_FREQUENCY = 100 #Hz
8791
PWM_RANGE = 100 #0-100
8892

93+
HW_VERSIONS = {
94+
"4": GPIO_CODERBOT_V_4(),
95+
"5": GPIO_CODERBOT_V_5()
96+
}
97+
8998
class CoderBot(object):
9099

91100
# pylint: disable=too-many-instance-attributes
92101

93-
def __init__(self, motor_trim_factor=1.0, encoder=True):
102+
def __init__(self, motor_trim_factor=1.0, hw_version="5"):
94103
try:
95104
self._mpu = mpu.AccelGyroMag()
96105
logging.info("MPU available")
97106
except:
98107
logging.info("MPU not available")
99108

100-
self.GPIOS = GPIO_CODERBOT_V_5()
109+
self.GPIOS = HW_VERSIONS.get(hw_version, GPIO_CODERBOT_V_5())
101110
self._pin_out = [self.GPIOS.PIN_LEFT_FORWARD, self.GPIOS.PIN_RIGHT_FORWARD, self.GPIOS.PIN_LEFT_BACKWARD, self.GPIOS.PIN_RIGHT_BACKWARD, self.GPIOS.PIN_SERVO_1, self.GPIOS.PIN_SERVO_2]
102111
self.pi = pigpio.pi('localhost')
103112
self.pi.set_mode(self.GPIOS.PIN_PUSHBUTTON, pigpio.INPUT)
104113
self._cb = dict()
105114
self._cb_last_tick = dict()
106115
self._cb_elapse = dict()
107-
self._encoder = encoder
116+
self._encoder = self.GPIOS.HAS_ENCODER
108117
self._motor_trim_factor = motor_trim_factor
109118
self._twin_motors_enc = WheelsAxel(
110119
self.pi,
@@ -143,9 +152,9 @@ def exit(self):
143152
s.cancel()
144153

145154
@classmethod
146-
def get_instance(cls, motor_trim_factor=1.0, encoder=True, servo=False):
155+
def get_instance(cls, motor_trim_factor=1.0, hw_version="5", servo=False):
147156
if not cls.the_bot:
148-
cls.the_bot = CoderBot(motor_trim_factor=motor_trim_factor, encoder=encoder)
157+
cls.the_bot = CoderBot(motor_trim_factor=motor_trim_factor, hw_version=hw_version)
149158
return cls.the_bot
150159

151160
def move(self, speed=100, elapse=0, distance=0):

data/activities.json

-1
This file was deleted.

data/defaults/config.json

+44-36
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
11
{
2-
"move_power_angle_3": "60",
3-
"cnn_default_model": "fruit_025_128_1",
4-
"prog_maxblocks": "-1",
5-
"camera_jpeg_quality": "5",
6-
"show_page_control": "true",
7-
"camera_framerate": "30",
8-
"prog_scrollbars": "true",
9-
"move_fw_speed": "100",
10-
"prog_level": "adv",
11-
"move_motor_trim": "1",
12-
"move_motor_mode": "dc",
13-
"cv_image_factor": "2",
14-
"move_power_angle_1": "45",
15-
"camera_path_object_size_min": "4000",
16-
"button_func": "none",
17-
"camera_color_object_size_min": "4000",
18-
"camera_jpeg_bitrate": "1000000",
19-
"move_fw_elapse": "1",
20-
"show_control_move_commands": "true",
21-
"camera_color_object_size_max": "160000",
22-
"show_page_prefs": "true",
23-
"camera_exposure_mode": "auto",
24-
"ctrl_tr_elapse": "-1",
25-
"show_page_program": "true",
26-
"move_tr_elapse": "0.5",
27-
"camera_path_object_size_max": "160000",
28-
"sound_shutter": "$shutter.mp3",
29-
"ctrl_fw_elapse": "-1",
30-
"sound_stop": "$shutdown.mp3",
31-
"ctrl_tr_speed": "80",
32-
"ctrl_fw_speed": "100",
33-
"move_tr_speed": "85",
34-
"move_power_angle_2": "60",
35-
"ctrl_hud_image": "",
36-
"load_at_start": "",
37-
"sound_start": "$startup.mp3"
2+
"move_power_angle_3":"60",
3+
"cnn_default_model":"generic_fast_low",
4+
"prog_maxblocks":"-1",
5+
"camera_jpeg_quality":"5",
6+
"show_page_control":"true",
7+
"camera_framerate":"30",
8+
"prog_scrollbars":"true",
9+
"move_fw_speed":"100",
10+
"prog_level":"adv",
11+
"move_motor_trim":"1",
12+
"move_motor_mode":"dc",
13+
"cv_image_factor":"2",
14+
"move_power_angle_1":"45",
15+
"camera_path_object_size_min":"4000",
16+
"button_func":"none",
17+
"camera_color_object_size_min":"4000",
18+
"camera_jpeg_bitrate":"1000000",
19+
"move_fw_elapse":"1",
20+
"show_control_move_commands":"true",
21+
"camera_color_object_size_max":"160000",
22+
"show_page_prefs":"true",
23+
"camera_exposure_mode":"auto",
24+
"ctrl_tr_elapse":"-1",
25+
"show_page_program":"true",
26+
"move_tr_elapse":"0.5",
27+
"camera_path_object_size_max":"160000",
28+
"sound_shutter":"$shutter.wav",
29+
"ctrl_fw_elapse":"-1",
30+
"sound_stop":"$shutdown.wav",
31+
"ctrl_tr_speed":"80",
32+
"ctrl_fw_speed":"100",
33+
"move_tr_speed":"85",
34+
"move_power_angle_2":"60",
35+
"ctrl_hud_image":"",
36+
"load_at_start":"",
37+
"sound_start":"$startup.wav",
38+
"hw_version":"5",
39+
"audio_volume_level":"100",
40+
"wifi_mode":"ap",
41+
"wifi_ssid":"coderbot_CHANGEMEATFIRSTRUN",
42+
"wifi_psk":"coderbot",
43+
"packages_installed":"",
44+
"admin_password":"",
45+
"hardware_version": "5"
3846
}

main.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,24 @@ def remove_doreset_file():
460460
except OSError:
461461
pass
462462

463+
def align_wifi_config():
464+
if app.bot_config["wifi_ssid"] == "coderbot_CHANGEMEATFIRSTRUN":
465+
out = os.popen("sudo ./wifi.py getcfg --ssid").read()
466+
if "coderbot_" in out:
467+
app.bot_config["wifi_ssid"] = out.split()[0]
468+
Config.write(app.bot_config)
469+
app.bot_config = Config.get()
470+
463471
# Finally, get the server running
464472
def run_server():
465473
bot = None
466474
cam = None
467475
try:
468476
try:
469477
app.bot_config = Config.read()
478+
align_wifi_config()
470479
bot = CoderBot.get_instance(motor_trim_factor=float(app.bot_config.get('move_motor_trim', 1.0)),
471-
encoder=bool(app.bot_config.get('encoder')))
480+
hw_version=app.bot_config.get('hardware_version'))
472481
audio = Audio.get_instance()
473482
audio.say(app.bot_config.get("sound_start"))
474483

static/js/blockly/blocks.js

-21
Original file line numberDiff line numberDiff line change
@@ -572,27 +572,6 @@ Blockly.Python['coderbot_adv_findLine'] = function(block) {
572572
return [code, Blockly.Python.ORDER_ATOMIC];
573573
};
574574

575-
Blockly.Blocks['coderbot_adv_findSignal'] = {
576-
/**
577-
* Block for findSignal function.
578-
* @this Blockly.Block
579-
*/
580-
init: function() {
581-
this.setHelpUrl(Blockly.Msg.LOGIC_BOOLEAN_HELPURL);
582-
this.setColour(250);
583-
this.appendDummyInput()
584-
.appendField(Blockly.Msg.CODERBOT_SENSOR_FINDSIGNAL);
585-
this.setOutput(true, 'Number');
586-
this.setTooltip(Blockly.Msg.LOGIC_BOOLEAN_TOOLTIP);
587-
}
588-
};
589-
590-
Blockly.Python['coderbot_adv_findSignal'] = function(block) {
591-
// Boolean values true and false.
592-
var code = 'get_cam().find_signal()';
593-
return [code, Blockly.Python.ORDER_ATOMIC];
594-
};
595-
596575
Blockly.Blocks['coderbot_adv_findFace'] = {
597576
/**
598577
* Block for findSignal function.

static/media/coderdojo-logo.png

-3.84 KB
Binary file not shown.

0 commit comments

Comments
 (0)