Skip to content

Commit 6e9f4f0

Browse files
author
coderbot
committed
Merge branch 'develop' of https://github.com/CoderBotOrg/coderbot into develop
2 parents 1ff4c4b + 73c3c3a commit 6e9f4f0

File tree

10 files changed

+33
-19
lines changed

10 files changed

+33
-19
lines changed

camera.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def find_signal(self):
208208
return angle
209209

210210
def find_face(self):
211-
faceX = None
211+
faceX, faceY, faceS = None
212212
self._image_lock.acquire()
213213
img = self.get_image(0)
214214
ts = time.time()
@@ -219,10 +219,13 @@ def find_face(self):
219219
if len(faces):
220220
# Get the largest face, face is a rectangle
221221
bigFace = faces[0]
222-
center = bigFace[0]+(bigFace[2]/2)
223-
faceX = (center * 100) / 160
224-
225-
return faceX
222+
centerX = (bigFace[0] + bigFace[2])/2
223+
faceX = (centerX * 100) / 160
224+
centerY = (bigFace[1] + bigFace[3])/2
225+
faceY = (centerY * 100) / 120
226+
size = bigFace[2] - bigFace[0]
227+
faceS = (size * 100) / 160
228+
return [faceX, faceY, faceS]
226229

227230
def path_ahead(self):
228231
#print "path ahead"
@@ -300,8 +303,6 @@ def find_color(self, s_color):
300303
dist = math.sqrt(math.pow(12 + (68 * (120 - y) / 100),2) + (math.pow((x-80)*60/160,2)))
301304
angle = math.atan2(x - 80, 120 - y) * 180 / math.pi
302305
logging.info("object found, dist: " + str(dist) + " angle: " + str(angle))
303-
#img.drawText("object found, dist: " + str(dist) + " angle: " + str(angle), 0, 0, fontsize=32 )
304-
#self.save_image(self._camera.get_image_jpeg())
305306
#self.save_image(img.to_jpeg())
306307
#print "object: " + str(time.time() - ts)
307308
return [dist, angle]

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": "1", "sound_start": "$startup.mp3", "sound_stop": "$shutdown.mp3", "camera_exposure_mode": "auto", "prog_video_rec": "true", "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": "dc", "ctrl_fw_elapse": "-1", "ctrl_tr_elapse": "-1", "move_power_angle_2": "80", "move_power_angle_3": "80", "ctrl_tr_speed": "80", "move_power_angle_1": "70"}
1+
{"move_tr_speed": "75", "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", "prog_video_rec": "true", "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": "dc", "ctrl_fw_elapse": "-1", "ctrl_tr_elapse": "-1", "move_power_angle_2": "100", "move_power_angle_3": "100", "ctrl_tr_speed": "80", "move_power_angle_1": "60"}

data/program_egg_catcher.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\" id=\"5\" inline=\"false\" x=\"40\" y=\"19\"><field name=\"MODE\">WHILE</field><value name=\"BOOL\"><block type=\"logic_boolean\" id=\"6\"><field name=\"BOOL\">TRUE</field></block></value><statement name=\"DO\"><block type=\"variables_set\" id=\"7\" inline=\"true\"><field name=\"VAR\">egg_dist_angle</field><value name=\"VALUE\"><block type=\"coderbot_adv_findColor\" id=\"8\" inline=\"true\"><field name=\"RETVAL\">BOTH</field><value name=\"COLOR\"><block type=\"colour_picker\" id=\"9\"><field name=\"COLOUR\">#cc0000</field></block></value></block></value><next><block type=\"variables_set\" id=\"10\" inline=\"true\"><field name=\"VAR\">egg_dist</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\">FIRST</field><value name=\"VALUE\"><block type=\"variables_get\" id=\"13\"><field name=\"VAR\">egg_dist_angle</field></block></value></block></value></block></value><next><block type=\"variables_set\" id=\"14\" inline=\"true\"><field name=\"VAR\">egg_angle</field><value name=\"VALUE\"><block type=\"math_round\" id=\"15\" inline=\"false\"><field name=\"OP\">ROUND</field><value name=\"NUM\"><block type=\"lists_getIndex\" id=\"16\" 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=\"17\"><field name=\"VAR\">egg_dist_angle</field></block></value></block></value></block></value><next><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\">dist: </field></block></value><value name=\"ADD1\"><block type=\"variables_get\" id=\"21\"><field name=\"VAR\">egg_dist</field></block></value><value name=\"ADD2\"><block type=\"text\" id=\"22\"><field name=\"TEXT\"> angle: </field></block></value><value name=\"ADD3\"><block type=\"variables_get\" id=\"23\"><field name=\"VAR\">egg_angle</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\">GTE</field><value name=\"A\"><block type=\"variables_get\" id=\"26\"><field name=\"VAR\">egg_dist</field></block></value><value name=\"B\"><block type=\"math_number\" id=\"27\"><field name=\"NUM\">0</field></block></value></block></value><statement name=\"DO0\"><block type=\"coderbot_motion_turn\" id=\"28\" inline=\"true\"><value name=\"ANGLE\"><block type=\"variables_get\" id=\"29\"><field name=\"VAR\">egg_angle</field></block></value><next><block type=\"coderbot_motion_move\" id=\"30\" inline=\"true\"><value name=\"DIST\"><block type=\"variables_get\" id=\"31\"><field name=\"VAR\">egg_dist</field></block></value></block></next></block></statement><next><block type=\"coderbot_sleep\" id=\"34\" inline=\"false\"><value name=\"ELAPSE\"><block type=\"math_number\" id=\"35\"><field name=\"NUM\">1.0</field></block></value></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>", "code": "import math\n\negg_dist_angle = None\negg_dist = None\negg_angle = None\n\n\nwhile True:\n get_prog_eng().check_end()\n egg_dist_angle = get_cam().find_color('#cc0000')\n egg_dist = round(egg_dist_angle[0])\n egg_angle = round(egg_dist_angle[-1])\n get_cam().set_text(''.join([str(temp_value) for temp_value in ['dist: ', egg_dist, ' angle: ', egg_angle]]))\n if egg_dist >= 0:\n get_motion().turn(angle=egg_angle)\n get_motion().move(dist=egg_dist)\n else:\n pass\n get_cam().sleep(1)\n", "name": "egg_catcher"}
1+
{"dom_code": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"controls_whileUntil\" id=\"1\" inline=\"false\" x=\"132\" y=\"-400\"><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=\"text_print\" id=\"45\" inline=\"false\"><value name=\"TEXT\"><block type=\"text\" id=\"61\"><field name=\"TEXT\">looking for eggs</field></block></value><next><block type=\"variables_set\" id=\"3\" inline=\"true\"><field name=\"VAR\">egg_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\">egg_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\">egg_dist_angle</field></block></value></block></value></block></value><next><block type=\"variables_set\" id=\"10\" inline=\"true\"><field name=\"VAR\">egg_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\">egg_dist_angle</field></block></value></block></value></block></value><next><block type=\"controls_if\" id=\"20\" inline=\"false\"><mutation else=\"1\"></mutation><value name=\"IF0\"><block type=\"logic_compare\" id=\"21\" inline=\"true\"><field name=\"OP\">GTE</field><value name=\"A\"><block type=\"variables_get\" id=\"22\"><field name=\"VAR\">egg_dist</field></block></value><value name=\"B\"><block type=\"math_number\" id=\"23\"><field name=\"NUM\">0</field></block></value></block></value><statement name=\"DO0\"><block type=\"text_print\" id=\"14\" inline=\"false\"><value name=\"TEXT\"><block type=\"text_join\" id=\"15\" inline=\"false\"><mutation items=\"5\"></mutation><value name=\"ADD0\"><block type=\"text\" id=\"16\"><field name=\"TEXT\">egg found at </field></block></value><value name=\"ADD1\"><block type=\"variables_get\" id=\"17\"><field name=\"VAR\">egg_dist</field></block></value><value name=\"ADD2\"><block type=\"text\" id=\"18\"><field name=\"TEXT\"> cm, </field></block></value><value name=\"ADD3\"><block type=\"variables_get\" id=\"19\"><field name=\"VAR\">egg_angle</field></block></value><value name=\"ADD4\"><block type=\"text\" id=\"85\"><field name=\"TEXT\"> angle</field></block></value></block></value><next><block type=\"coderbot_motion_turn\" id=\"24\" inline=\"true\"><value name=\"ANGLE\"><block type=\"variables_get\" id=\"25\"><field name=\"VAR\">egg_angle</field></block></value><next><block type=\"coderbot_motion_move\" id=\"26\" inline=\"true\"><value name=\"DIST\"><block type=\"variables_get\" id=\"27\"><field name=\"VAR\">egg_dist</field></block></value></block></next></block></next></block></statement><statement name=\"ELSE\"><block type=\"coderbot_motion_turn\" id=\"28\" inline=\"true\"><value name=\"ANGLE\"><block type=\"math_number\" id=\"29\"><field name=\"NUM\">30</field></block></value></block></statement></block></next></block></next></block></next></block></next></block></statement></block></xml>", "code": "import math\n\negg_dist_angle = None\negg_dist = None\negg_angle = None\n\n\nwhile True:\n get_prog_eng().check_end()\n get_cam().set_text('looking for eggs')\n egg_dist_angle = get_cam().find_color('#ff0000')\n egg_dist = round(egg_dist_angle[0])\n egg_angle = round(egg_dist_angle[-1])\n if egg_dist >= 0:\n get_cam().set_text(''.join([str(temp_value) for temp_value in ['egg found at ', egg_dist, ' cm, ', egg_angle, ' angle']]))\n get_motion().turn(angle=egg_angle)\n get_motion().move(dist=egg_dist)\n else:\n get_motion().turn(angle=30)\n", "name": "egg_catcher"}

data/program_egg_catcher_2.data

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

data/program_test_motion_flow.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=\"coderbot_motion_turn\" id=\"52\" inline=\"true\" x=\"229\" y=\"82\"><value name=\"ANGLE\"><block type=\"math_number\" id=\"53\"><field name=\"NUM\">12</field></block></value><next><block type=\"coderbot_motion_move\" id=\"32\" inline=\"true\"><value name=\"DIST\"><block type=\"math_number\" id=\"33\"><field name=\"NUM\">55</field></block></value></block></next></block></xml>", "code": "get_motion().turn(angle=12)\nget_motion().move(dist=55)\n", "name": "test_motion_flow"}
1+
{"dom_code": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"coderbot_motion_move\" id=\"1\" inline=\"true\" x=\"185\" y=\"52\"><value name=\"DIST\"><block type=\"math_number\" id=\"2\"><field name=\"NUM\">70</field></block></value></block></xml>", "code": "get_motion().move(dist=70)\n", "name": "test_motion_flow"}

motion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def move(self, dist):
5858
self.delta_angle = 0.0
5959
self.target_dist = dist
6060
self.target_angle = 0.0
61+
self.delta_power = 0.0
6162
self.loop_move()
6263

6364
def turn(self, angle):
@@ -207,9 +208,8 @@ def bot_turn(self, target_angle, delta_angle):
207208

208209
def bot_move(self, target_dist, delta_dist, delta_angle):
209210
base_power = 100 * (target_dist/abs(target_dist))
210-
logging.info("base power" + str(base_power))
211211
self.delta_power += (delta_angle * 0.01)
212-
logging.info( "delta power: " + str(self.delta_power))
212+
logging.info("base power: " + str(base_power) + " delta power: " + str(self.delta_power) + " delta_dist: " + str(delta_dist) + " target_dist: " + str(target_dist))
213213
if abs(delta_dist) < abs(target_dist):
214214
self.bot.motor_control(min(max(base_power-self.delta_power,-100),100), min(max(base_power+self.delta_power,-100),100), -1)
215215
else:

static/js/blockly/.blocks.js.swo

20 KB
Binary file not shown.

static/js/blockly/blocks.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -638,28 +638,34 @@ Blockly.Python['coderbot_adv_findSignal'] = function(block) {
638638

639639
Blockly.Blocks['coderbot_adv_findFace'] = {
640640
/**
641-
* Block for findFace function.
641+
* Block for findSignal function.
642642
* @this Blockly.Block
643643
*/
644644
init: function() {
645645
this.setHelpUrl(Blockly.Msg.LOGIC_BOOLEAN_HELPURL);
646646
this.setColour(290);
647647
this.appendDummyInput()
648-
.appendField(Blockly.Msg.CODERBOT_SENSOR_FINDFACE);
649-
this.setOutput(true, 'Number');
648+
.appendField(Blockly.Msg.CODERBOT_SENSOR_FINDFACE_FIND)
649+
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.CODERBOT_SENSOR_FINDFACE_X, 'X'], [Blockly.Msg.CODERBOT_SENSOR_FINDFACE_Y, 'Y'],[Blockly.Msg.CODERBOT_SENSOR_FINDFACE_SIZE, 'SIZE'],[Blockly.Msg.CODERBOT_SENSOR_FINDFACE_ALL,'ALL']]), 'RETVAL')
650+
this.setInputsInline(true);
651+
this.setOutput(true, ['Number', 'Array']);
650652
this.setTooltip(Blockly.Msg.LOGIC_BOOLEAN_TOOLTIP);
651653
}
652654
};
653655

654656
Blockly.JavaScript['coderbot_adv_findFace'] = function(block) {
655657
// Boolean values true and false.
656-
var code = 'get_cam().find_face()';
658+
var retval = block.getFieldValue('RETVAL');
659+
var ret_code = {'X': '[0]', 'Y': '[1]', 'SIZE': '[2]', 'ALL': ''}[retval];
660+
var code = 'get_cam().find_face()' + ret_code + ';';
657661
return [code, Blockly.Python.ORDER_ATOMIC];
658662
};
659663

660664
Blockly.Python['coderbot_adv_findFace'] = function(block) {
661665
// Boolean values true and false.
662-
var code = 'get_cam().find_face()';
666+
var retval = block.getFieldValue('RETVAL');
667+
var ret_code = {'X': '[0]', 'Y': '[1]', 'SIZE': '[2]', 'ALL': ''}[retval];
668+
var code = 'get_cam().find_face()' + ret_code;
663669
return [code, Blockly.Python.ORDER_ATOMIC];
664670
};
665671

@@ -702,7 +708,6 @@ Blockly.Blocks['coderbot_adv_findColor'] = {
702708
.appendField(Blockly.Msg.CODERBOT_SENSOR_FINDCOLOR_FIND)
703709
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.CODERBOT_SENSOR_FINDCOLOR_DIST, 'DIST'], [Blockly.Msg.CODERBOT_SENSOR_FINDCOLOR_ANGLE, 'ANGLE'],[Blockly.Msg.CODERBOT_SENSOR_FINDCOLOR_BOTH,'BOTH']]), 'RETVAL')
704710
.appendField(Blockly.Msg.CODERBOT_SENSOR_FINDCOLOR_COLOR);
705-
//.appendField(new Blockly.FieldColour('#ff0000'), 'COLOR');
706711
this.appendValueInput('COLOR')
707712
.setCheck('Colour');
708713
this.setInputsInline(true);

static/js/blockly/bot_en.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ Blockly.Msg.CODERBOT_SENSOR_FINDCOLOR_COLOR = "from color";
4141
Blockly.Msg.CODERBOT_SENSOR_FINDCOLOR_DIST = "distance";
4242
Blockly.Msg.CODERBOT_SENSOR_FINDCOLOR_ANGLE = "angle";
4343
Blockly.Msg.CODERBOT_SENSOR_FINDCOLOR_BOTH = "both";
44+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_X = "face x";
45+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_Y = "face y";
46+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_SIZE = "face size";
47+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_ALL = "all (as list)";
4448
Blockly.Msg.CODERBOT_SENSOR_FINDLOGO = "find logo";

static/js/blockly/bot_it.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ Blockly.Msg.CODERBOT_SENSOR_FINDCOLOR_COLOR = "da colore";
4141
Blockly.Msg.CODERBOT_SENSOR_FINDCOLOR_DIST = "distanza";
4242
Blockly.Msg.CODERBOT_SENSOR_FINDCOLOR_ANGLE = "angolo";
4343
Blockly.Msg.CODERBOT_SENSOR_FINDCOLOR_BOTH = "entrambi";
44+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_X = "ascissa (x)";
45+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_Y = "ordinata (y)";
46+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_SIZE = "dimensione faccia";
47+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_ALL = "tutto (come lista)";
4448
Blockly.Msg.CODERBOT_SENSOR_FINDLOGO = "trova logo";

0 commit comments

Comments
 (0)