Skip to content

Commit 0328fe3

Browse files
author
coderbot
committed
-
1 parent 413491b commit 0328fe3

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

camera.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ def path_ahead(self):
261261
#dw_x = 260 + obstacle.coordinates()[0] - (obstacle.width()/2)
262262
#dw_y = 160 + obstacle.coordinates()[1] - (obstacle.height()/2)
263263
#img.drawRectangle(dw_x, dw_y, obstacle.width(), obstacle.height(), color=(255,0,0))
264-
x, y = img.transform((obstacle.center[0], obstacle.bottom))
264+
coords = img.transform([(obstacle.center[0], obstacle.bottom)])
265+
x = coords[0][0]
266+
y = coords[0][1]
265267
coordY = 60 - ((y * 48) / 100)
266268
logging.info("coordY: " + str(coordY))
267269
#print obstacle.coordinates()[1]+(obstacle.height()/2)
@@ -287,7 +289,7 @@ def find_color(self, s_color):
287289
self._image_lock.release()
288290
bw = img.filter_color(color)
289291
#self.save_image(bw.to_jpeg())
290-
objects = bw.find_blobs(minsize=20, maxsize=1000)
292+
objects = bw.find_blobs(minsize=20, maxsize=8000)
291293
logging.debug("objects: " + str(objects))
292294
dist = -1
293295
angle = 180
@@ -308,6 +310,6 @@ def find_color(self, s_color):
308310
return [dist, angle]
309311

310312
def sleep(self, elapse):
311-
logging.debug("sleep: " + elapse)
313+
logging.debug("sleep: " + str(elapse))
312314
time.sleep(elapse)
313315

coderbot.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"move_tr_speed": "75", "move_fw_elapse": "1.5", "show_page_program": "true", "load_at_start": "", "move_tr_elapse": "90", "sound_start": "$startup.mp3", "sound_stop": "$shutdown.mp3", "camera_exposure_mode": "auto", "prog_move_motion": "yes", "show_control_move_commands": "true", "prog_level": "adv", "prog_scrollbars": "true", "ctrl_fw_speed": "100", "move_fw_speed": "100", "show_page_control": "true", "sound_shutter": "$shutter.mp3", "show_page_prefs": "true", "prog_maxblocks": "-1", "ctrl_hud_image": "", "button_func": "none", "move_motor_mode": "servo", "ctrl_fw_elapse": "-1", "ctrl_tr_elapse": "-1", "move_power_angle_2": "20", "move_power_angle_3": "20", "ctrl_tr_speed": "80", "move_power_angle_1": "15"}
1+
{"move_tr_speed": "70", "move_fw_elapse": "1.5", "show_page_program": "true", "load_at_start": "", "move_tr_elapse": "1", "sound_start": "$startup.mp3", "sound_stop": "$shutdown.mp3", "camera_exposure_mode": "auto", "ctrl_tr_speed": "80", "show_control_move_commands": "true", "prog_level": "adv", "prog_scrollbars": "true", "ctrl_fw_speed": "100", "move_fw_speed": "100", "show_page_control": "true", "sound_shutter": "$shutter.mp3", "show_page_prefs": "true", "prog_maxblocks": "-1", "ctrl_hud_image": "", "button_func": "none", "move_motor_mode": "servo", "ctrl_fw_elapse": "-1", "ctrl_tr_elapse": "-1", "move_power_angle_2": "20", "move_power_angle_3": "20", "move_power_angle_1": "15"}

data/program_cerca rosso.data

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"dom_code": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"controls_whileUntil\" id=\"1\" inline=\"false\" x=\"81\" y=\"-48\"><field name=\"MODE\">WHILE</field><value name=\"BOOL\"><block type=\"logic_boolean\" id=\"2\"><field name=\"BOOL\">TRUE</field></block></value><statement name=\"DO\"><block type=\"variables_set\" id=\"3\" inline=\"true\"><field name=\"VAR\">rosso_d_a</field><value name=\"VALUE\"><block type=\"coderbot_adv_findColor\" id=\"4\" inline=\"true\"><field name=\"RETVAL\">BOTH</field><value name=\"COLOR\"><block type=\"colour_picker\" id=\"5\"><field name=\"COLOUR\">#ff0000</field></block></value></block></value><next><block type=\"variables_set\" id=\"6\" inline=\"true\"><field name=\"VAR\">rosso_dist</field><value name=\"VALUE\"><block type=\"math_round\" id=\"7\" inline=\"false\"><field name=\"OP\">ROUND</field><value name=\"NUM\"><block type=\"lists_getIndex\" id=\"8\" inline=\"true\"><mutation statement=\"false\" at=\"false\"></mutation><field name=\"MODE\">GET</field><field name=\"WHERE\">FIRST</field><value name=\"VALUE\"><block type=\"variables_get\" id=\"9\"><field name=\"VAR\">rosso_d_a</field></block></value></block></value></block></value><next><block type=\"variables_set\" id=\"10\" inline=\"true\"><field name=\"VAR\">rosso_angolo</field><value name=\"VALUE\"><block type=\"math_round\" id=\"11\" inline=\"false\"><field name=\"OP\">ROUND</field><value name=\"NUM\"><block type=\"lists_getIndex\" id=\"12\" inline=\"true\"><mutation statement=\"false\" at=\"false\"></mutation><field name=\"MODE\">GET</field><field name=\"WHERE\">LAST</field><value name=\"VALUE\"><block type=\"variables_get\" id=\"13\"><field name=\"VAR\">rosso_d_a</field></block></value></block></value></block></value><next><block type=\"controls_if\" id=\"14\" inline=\"false\"><mutation else=\"1\"></mutation><value name=\"IF0\"><block type=\"logic_compare\" id=\"15\" inline=\"true\"><field name=\"OP\">GT</field><value name=\"A\"><block type=\"variables_get\" id=\"16\"><field name=\"VAR\">rosso_dist</field></block></value><value name=\"B\"><block type=\"math_number\" id=\"17\"><field name=\"NUM\">0</field></block></value></block></value><statement name=\"DO0\"><block type=\"text_print\" id=\"18\" inline=\"false\"><value name=\"TEXT\"><block type=\"text_join\" id=\"19\" inline=\"false\"><mutation items=\"4\"></mutation><value name=\"ADD0\"><block type=\"text\" id=\"20\"><field name=\"TEXT\">rosso: distanza: </field></block></value><value name=\"ADD1\"><block type=\"variables_get\" id=\"21\"><field name=\"VAR\">rosso_dist</field></block></value><value name=\"ADD2\"><block type=\"text\" id=\"22\"><field name=\"TEXT\"> angolo:</field></block></value><value name=\"ADD3\"><block type=\"variables_get\" id=\"23\"><field name=\"VAR\">rosso_angolo</field></block></value></block></value><next><block type=\"controls_if\" id=\"24\" inline=\"false\"><mutation else=\"1\"></mutation><value name=\"IF0\"><block type=\"logic_compare\" id=\"25\" inline=\"true\"><field name=\"OP\">GT</field><value name=\"A\"><block type=\"variables_get\" id=\"26\"><field name=\"VAR\">rosso_angolo</field></block></value><value name=\"B\"><block type=\"math_number\" id=\"27\"><field name=\"NUM\">-20</field></block></value></block></value><statement name=\"DO0\"><block type=\"coderbot_adv_move\" id=\"28\" inline=\"true\"><field name=\"ACTION\">RIGHT</field><value name=\"SPEED\"><block type=\"math_number\" id=\"29\"><field name=\"NUM\">50</field></block></value><value name=\"ELAPSE\"><block type=\"math_number\" id=\"30\"><field name=\"NUM\">0.1</field></block></value></block></statement><statement name=\"ELSE\"><block type=\"coderbot_adv_move\" id=\"31\" inline=\"true\"><field name=\"ACTION\">FORWARD</field><value name=\"SPEED\"><block type=\"math_number\" id=\"32\"><field name=\"NUM\">100</field></block></value><value name=\"ELAPSE\"><block type=\"math_number\" id=\"33\"><field name=\"NUM\">0.2</field></block></value></block></statement></block></next></block></statement><statement name=\"ELSE\"><block type=\"text_print\" id=\"34\" inline=\"false\"><value name=\"TEXT\"><block type=\"text\" id=\"35\"><field name=\"TEXT\">cerco rosso</field></block></value><next><block type=\"coderbot_adv_move\" id=\"36\" inline=\"true\"><field name=\"ACTION\">FORWARD</field><value name=\"SPEED\"><block type=\"math_number\" id=\"37\"><field name=\"NUM\">100</field></block></value><value name=\"ELAPSE\"><block type=\"math_number\" id=\"38\"><field name=\"NUM\">0.2</field></block></value></block></next></block></statement></block></next></block></next></block></next></block></statement></block></xml>", "code": "import math\n\nrosso_d_a = None\nrosso_dist = None\nrosso_angolo = None\n\n\nwhile True:\n get_prog_eng().check_end()\n rosso_d_a = get_cam().find_color('#ff0000')\n rosso_dist = round(rosso_d_a[0])\n rosso_angolo = round(rosso_d_a[-1])\n if rosso_dist > 0:\n get_cam().set_text(''.join([str(temp_value) for temp_value in ['rosso: distanza: ', rosso_dist, ' angolo:', rosso_angolo]]))\n if rosso_angolo > -20:\n get_bot().right(speed=50, elapse=0.1)\n else:\n get_bot().forward(speed=100, elapse=0.2)\n else:\n get_cam().set_text('cerco rosso')\n get_bot().forward(speed=100, elapse=0.2)\n", "name": "cerca rosso"}

data/program_find_red.data

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"dom_code": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"controls_whileUntil\" id=\"1\" inline=\"false\" x=\"11\" y=\"111\"><field name=\"MODE\">WHILE</field><value name=\"BOOL\"><block type=\"logic_boolean\" id=\"2\"><field name=\"BOOL\">TRUE</field></block></value><statement name=\"DO\"><block type=\"variables_set\" id=\"3\" inline=\"true\"><field name=\"VAR\">red_dist_angle</field><value name=\"VALUE\"><block type=\"coderbot_adv_findColor\" id=\"4\" inline=\"true\"><field name=\"RETVAL\">BOTH</field><value name=\"COLOR\"><block type=\"colour_picker\" id=\"5\"><field name=\"COLOUR\">#ff0000</field></block></value></block></value><next><block type=\"variables_set\" id=\"6\" inline=\"true\"><field name=\"VAR\">red_dist</field><value name=\"VALUE\"><block type=\"math_round\" id=\"7\" inline=\"false\"><field name=\"OP\">ROUND</field><value name=\"NUM\"><block type=\"lists_getIndex\" id=\"8\" inline=\"true\"><mutation statement=\"false\" at=\"false\"></mutation><field name=\"MODE\">GET</field><field name=\"WHERE\">FIRST</field><value name=\"VALUE\"><block type=\"variables_get\" id=\"9\"><field name=\"VAR\">red_dist_angle</field></block></value></block></value></block></value><next><block type=\"variables_set\" id=\"10\" inline=\"true\"><field name=\"VAR\">red_angle</field><value name=\"VALUE\"><block type=\"math_round\" id=\"11\" inline=\"false\"><field name=\"OP\">ROUND</field><value name=\"NUM\"><block type=\"lists_getIndex\" id=\"12\" inline=\"true\"><mutation statement=\"false\" at=\"false\"></mutation><field name=\"MODE\">GET</field><field name=\"WHERE\">LAST</field><value name=\"VALUE\"><block type=\"variables_get\" id=\"13\"><field name=\"VAR\">red_dist_angle</field></block></value></block></value></block></value><next><block type=\"controls_if\" id=\"14\" inline=\"false\"><mutation else=\"1\"></mutation><value name=\"IF0\"><block type=\"logic_compare\" id=\"15\" inline=\"true\"><field name=\"OP\">GTE</field><value name=\"A\"><block type=\"variables_get\" id=\"16\"><field name=\"VAR\">red_dist</field></block></value><value name=\"B\"><block type=\"math_number\" id=\"17\"><field name=\"NUM\">0</field></block></value></block></value><statement name=\"DO0\"><block type=\"text_print\" id=\"18\" inline=\"false\"><value name=\"TEXT\"><block type=\"text_join\" id=\"19\" inline=\"false\"><mutation items=\"5\"></mutation><value name=\"ADD0\"><block type=\"text\" id=\"20\"><field name=\"TEXT\">red: </field></block></value><value name=\"ADD1\"><block type=\"variables_get\" id=\"21\"><field name=\"VAR\">red_dist</field></block></value><value name=\"ADD2\"><block type=\"text\" id=\"22\"><field name=\"TEXT\">cm, </field></block></value><value name=\"ADD3\"><block type=\"variables_get\" id=\"23\"><field name=\"VAR\">red_angle</field></block></value><value name=\"ADD4\"><block type=\"text\" id=\"24\"><field name=\"TEXT\">o</field></block></value></block></value><next><block type=\"controls_if\" id=\"25\" inline=\"false\"><mutation elseif=\"2\"></mutation><value name=\"IF0\"><block type=\"logic_compare\" id=\"26\" inline=\"true\"><field name=\"OP\">GTE</field><value name=\"A\"><block type=\"variables_get\" id=\"27\"><field name=\"VAR\">red_angle</field></block></value><value name=\"B\"><block type=\"math_number\" id=\"28\"><field name=\"NUM\">10</field></block></value></block></value><statement name=\"DO0\"><block type=\"coderbot_adv_move\" id=\"29\" inline=\"true\"><field name=\"ACTION\">RIGHT</field><value name=\"SPEED\"><block type=\"math_number\" id=\"30\"><field name=\"NUM\">15</field></block></value><value name=\"ELAPSE\"><block type=\"math_number\" id=\"31\"><field name=\"NUM\">0.1</field></block></value></block></statement><value name=\"IF1\"><block type=\"logic_compare\" id=\"32\" inline=\"true\"><field name=\"OP\">LTE</field><value name=\"A\"><block type=\"variables_get\" id=\"33\"><field name=\"VAR\">red_angle</field></block></value><value name=\"B\"><block type=\"math_number\" id=\"34\"><field name=\"NUM\">-10</field></block></value></block></value><statement name=\"DO1\"><block type=\"coderbot_adv_move\" id=\"35\" inline=\"true\"><field name=\"ACTION\">LEFT</field><value name=\"SPEED\"><block type=\"math_number\" id=\"36\"><field name=\"NUM\">15</field></block></value><value name=\"ELAPSE\"><block type=\"math_number\" id=\"37\"><field name=\"NUM\">0.1</field></block></value></block></statement><value name=\"IF2\"><block type=\"logic_compare\" id=\"38\" inline=\"true\"><field name=\"OP\">GTE</field><value name=\"A\"><block type=\"variables_get\" id=\"39\"><field name=\"VAR\">red_dist</field></block></value><value name=\"B\"><block type=\"math_number\" id=\"40\"><field name=\"NUM\">20</field></block></value></block></value><statement name=\"DO2\"><block type=\"coderbot_adv_move\" id=\"41\" inline=\"true\"><field name=\"ACTION\">FORWARD</field><value name=\"SPEED\"><block type=\"math_number\" id=\"42\"><field name=\"NUM\">100</field></block></value><value name=\"ELAPSE\"><block type=\"math_number\" id=\"43\"><field name=\"NUM\">0.2</field></block></value></block></statement></block></next></block></statement><statement name=\"ELSE\"><block type=\"text_print\" id=\"44\" inline=\"false\"><value name=\"TEXT\"><block type=\"text\" id=\"45\"><field name=\"TEXT\">looking for red</field></block></value></block></statement></block></next></block></next></block></next></block></statement></block></xml>", "code": "import math\n\nred_dist_angle = None\nred_dist = None\nred_angle = None\n\n\nwhile True:\n get_prog_eng().check_end()\n red_dist_angle = get_cam().find_color('#ff0000')\n red_dist = round(red_dist_angle[0])\n red_angle = round(red_dist_angle[-1])\n if red_dist >= 0:\n get_cam().set_text(''.join([str(temp_value) for temp_value in ['red: ', red_dist, 'cm, ', red_angle, 'o']]))\n if red_angle >= 10:\n get_bot().right(speed=15, elapse=0.1)\n elif red_angle <= -10:\n get_bot().left(speed=15, elapse=0.1)\n elif red_dist >= 20:\n get_bot().forward(speed=100, elapse=0.2)\n else:\n get_cam().set_text('looking for red')\n", "name": "find_red"}

data/program_path_ahead.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_repeat_ext\" id=\"66\" inline=\"true\" x=\"1\" y=\"90\"><value name=\"TIMES\"><block type=\"math_number\" id=\"67\"><field name=\"NUM\">100</field></block></value><statement name=\"DO\"><block type=\"text_print\" id=\"90\" inline=\"false\"><value name=\"TEXT\"><block type=\"coderbot_adv_pathAhead\" id=\"76\"></block></value></block></statement></block></xml>", "code": "for count in range(100):\n get_prog_eng().check_end()\n print(get_cam().path_ahead())\n", "name": "path_ahead"}
1+
{"dom_code": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"controls_whileUntil\" id=\"22\" inline=\"false\" x=\"31\" y=\"32\"><field name=\"MODE\">WHILE</field><value name=\"BOOL\"><block type=\"logic_boolean\" id=\"30\"><field name=\"BOOL\">TRUE</field></block></value><statement name=\"DO\"><block type=\"variables_set\" id=\"33\" inline=\"true\"><field name=\"VAR\">path_ahead</field><value name=\"VALUE\"><block type=\"coderbot_adv_pathAhead\" id=\"40\"></block></value><next><block type=\"text_print\" id=\"65\" inline=\"false\"><value name=\"TEXT\"><block type=\"text_join\" id=\"97\" inline=\"false\"><mutation items=\"2\"></mutation><value name=\"ADD0\"><block type=\"text\" id=\"81\"><field name=\"TEXT\">path ahead: </field></block></value><value name=\"ADD1\"><block type=\"variables_get\" id=\"98\"><field name=\"VAR\">path_ahead</field></block></value></block></value><next><block type=\"controls_if\" id=\"12\" inline=\"false\"><mutation else=\"1\"></mutation><value name=\"IF0\"><block type=\"variables_get\" id=\"45\"><field name=\"VAR\">path_ahead</field></block></value><statement name=\"DO0\"><block type=\"coderbot_adv_move\" id=\"117\" inline=\"true\"><field name=\"ACTION\">FORWARD</field><value name=\"SPEED\"><block type=\"math_number\" id=\"118\"><field name=\"NUM\">100</field></block></value><value name=\"ELAPSE\"><block type=\"math_number\" id=\"119\"><field name=\"NUM\">-1</field></block></value></block></statement><statement name=\"ELSE\"><block type=\"coderbot_adv_move\" id=\"120\" inline=\"true\"><field name=\"ACTION\">RIGHT</field><value name=\"SPEED\"><block type=\"math_number\" id=\"121\"><field name=\"NUM\">20</field></block></value><value name=\"ELAPSE\"><block type=\"math_number\" id=\"122\"><field name=\"NUM\">-1</field></block></value></block></statement></block></next></block></next></block></statement></block></xml>", "code": "path_ahead = None\n\n\nwhile True:\n get_prog_eng().check_end()\n path_ahead = get_cam().path_ahead()\n get_cam().set_text(str('path ahead: ') + str(path_ahead))\n if path_ahead:\n get_bot().forward(speed=100, elapse=-1)\n else:\n get_bot().right(speed=20, elapse=-1)\n", "name": "path_ahead"}

0 commit comments

Comments
 (0)