Skip to content

Commit 3a9de27

Browse files
author
coderbot
committed
-
1 parent 74ef0ea commit 3a9de27

File tree

13 files changed

+64
-32
lines changed

13 files changed

+64
-32
lines changed

camera.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from viz import camera, streamer, image, blob
1212
import config
1313

14-
CAMERA_REFRESH_INTERVAL=0.01
14+
CAMERA_REFRESH_INTERVAL=0.1
1515
MAX_IMAGE_AGE = 0.0
1616
PHOTO_PATH = "./photos"
1717
PHOTO_PREFIX = "DSC"
@@ -208,7 +208,7 @@ def find_signal(self):
208208
return angle
209209

210210
def find_face(self):
211-
faceX, faceY, faceS = None
211+
faceX = faceY = faceS = None
212212
self._image_lock.acquire()
213213
img = self.get_image(0)
214214
ts = time.time()
@@ -218,13 +218,13 @@ def find_face(self):
218218
print faces
219219
if len(faces):
220220
# Get the largest face, face is a rectangle
221-
bigFace = faces[0]
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
221+
x, y, w, h = faces[0]
222+
centerX = x + (w/2)
223+
faceX = ((centerX * 100) / 160) - 50 #center = 0
224+
centerY = y + (h/2)
225+
faceY = 50 - (centerY * 100) / 120 #center = 0
226+
size = h
227+
faceS = (size * 100) / 120
228228
return [faceX, faceY, faceS]
229229

230230
def path_ahead(self):

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": "100", "move_power_angle_3": "100", "ctrl_tr_speed": "80", "move_power_angle_1": "60"}
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", "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": "100", "move_power_angle_3": "100", "move_power_angle_1": "60"}

coderbot.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _servo_motor(self, speed_left=100, speed_right=100, elapse=-1):
112112

113113
def _servo_motor_control(self, pin, speed):
114114
self._is_moving = True
115-
speed = ((speed + 100) * 50 / 200) + 50
115+
speed = ((speed + 100) * 50 / 200) + 52
116116

117117
self.pi.set_PWM_range(pin, 1000)
118118
self.pi.set_PWM_frequency(pin, 50)
@@ -158,5 +158,11 @@ def callback(self, gpio, level, tick):
158158
def halt(self):
159159
os.system ('sudo halt')
160160

161+
def restart(self):
162+
os.system ('sudo /etc/init.d/coderbot stop && sudo pkill -9 dbus && sudo /etc/init.d/coderbot start')
163+
164+
def reboot(self):
165+
os.system ('sudo reboot')
166+
161167

162168

data/program_face_finder.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=\"17\" inline=\"false\" x=\"68\" y=\"146\"><field name=\"MODE\">WHILE</field><value name=\"BOOL\"><block type=\"logic_boolean\" id=\"25\"><field name=\"BOOL\">TRUE</field></block></value><statement name=\"DO\"><block type=\"variables_set\" id=\"125\" inline=\"true\"><field name=\"VAR\">face_x</field><value name=\"VALUE\"><block type=\"coderbot_adv_findFace\" id=\"50\"></block></value><next><block type=\"text_print\" id=\"258\" inline=\"false\"><value name=\"TEXT\"><block type=\"text\" id=\"242\"><field name=\"TEXT\">looking for a face</field></block></value><next><block type=\"controls_if\" id=\"182\" inline=\"false\"><value name=\"IF0\"><block type=\"variables_get\" id=\"191\"><field name=\"VAR\">face_x</field></block></value><statement name=\"DO0\"><block type=\"text_print\" id=\"141\" inline=\"false\"><value name=\"TEXT\"><block type=\"text_join\" id=\"66\" inline=\"false\"><mutation items=\"2\"></mutation><value name=\"ADD0\"><block type=\"text\" id=\"82\"><field name=\"TEXT\">found face at: </field></block></value><value name=\"ADD1\"><block type=\"variables_get\" id=\"146\"><field name=\"VAR\">face_x</field></block></value></block></value></block></statement></block></next></block></next></block></statement></block></xml>", "code": "face_x = None\n\n\nwhile True:\n get_prog_eng().check_end()\n face_x = get_cam().find_face()\n get_cam().set_text('looking for a face')\n if face_x:\n get_cam().set_text(str('found face at: ') + str(face_x))\n", "name": "face_finder"}
1+
{"dom_code": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"><block type=\"controls_whileUntil\" id=\"42\" inline=\"false\" x=\"11\" y=\"111\"><field name=\"MODE\">WHILE</field><value name=\"BOOL\"><block type=\"logic_boolean\" id=\"43\"><field name=\"BOOL\">TRUE</field></block></value><statement name=\"DO\"><block type=\"variables_set\" id=\"44\" inline=\"true\"><field name=\"VAR\">face_x_y_size</field><value name=\"VALUE\"><block type=\"coderbot_adv_findFace\" id=\"45\"><field name=\"RETVAL\">ALL</field></block></value><next><block type=\"variables_set\" id=\"46\" inline=\"true\"><field name=\"VAR\">face_x</field><value name=\"VALUE\"><block type=\"lists_getIndex\" id=\"47\" inline=\"true\"><mutation statement=\"false\" at=\"true\"></mutation><field name=\"MODE\">GET</field><field name=\"WHERE\">FROM_START</field><value name=\"VALUE\"><block type=\"variables_get\" id=\"48\"><field name=\"VAR\">face_x_y_size</field></block></value><value name=\"AT\"><block type=\"math_number\" id=\"49\"><field name=\"NUM\">1</field></block></value></block></value><next><block type=\"controls_if\" id=\"50\" inline=\"false\"><mutation else=\"1\"></mutation><value name=\"IF0\"><block type=\"variables_get\" id=\"51\"><field name=\"VAR\">face_x</field></block></value><statement name=\"DO0\"><block type=\"variables_set\" id=\"52\" inline=\"true\"><field name=\"VAR\">face_y</field><value name=\"VALUE\"><block type=\"lists_getIndex\" id=\"53\" inline=\"true\"><mutation statement=\"false\" at=\"true\"></mutation><field name=\"MODE\">GET</field><field name=\"WHERE\">FROM_START</field><value name=\"VALUE\"><block type=\"variables_get\" id=\"54\"><field name=\"VAR\">face_x_y_size</field></block></value><value name=\"AT\"><block type=\"math_number\" id=\"55\"><field name=\"NUM\">2</field></block></value></block></value><next><block type=\"variables_set\" id=\"56\" inline=\"true\"><field name=\"VAR\">face_size</field><value name=\"VALUE\"><block type=\"lists_getIndex\" id=\"57\" inline=\"true\"><mutation statement=\"false\" at=\"true\"></mutation><field name=\"MODE\">GET</field><field name=\"WHERE\">FROM_START</field><value name=\"VALUE\"><block type=\"variables_get\" id=\"58\"><field name=\"VAR\">face_x_y_size</field></block></value><value name=\"AT\"><block type=\"math_number\" id=\"59\"><field name=\"NUM\">3</field></block></value></block></value><next><block type=\"text_print\" id=\"60\" inline=\"false\"><value name=\"TEXT\"><block type=\"text_join\" id=\"61\" inline=\"false\"><mutation items=\"7\"></mutation><value name=\"ADD0\"><block type=\"text\" id=\"62\"><field name=\"TEXT\">face at </field></block></value><value name=\"ADD1\"><block type=\"variables_get\" id=\"63\"><field name=\"VAR\">face_x</field></block></value><value name=\"ADD2\"><block type=\"text\" id=\"64\"><field name=\"TEXT\">x, </field></block></value><value name=\"ADD3\"><block type=\"variables_get\" id=\"65\"><field name=\"VAR\">face_y</field></block></value><value name=\"ADD4\"><block type=\"text\" id=\"66\"><field name=\"TEXT\">y, </field></block></value><value name=\"ADD5\"><block type=\"variables_get\" id=\"67\"><field name=\"VAR\">face_size</field></block></value><value name=\"ADD6\"><block type=\"text\" id=\"68\"><field name=\"TEXT\"> size</field></block></value></block></value></block></next></block></next></block></statement><statement name=\"ELSE\"><block type=\"text_print\" id=\"69\" inline=\"false\"><value name=\"TEXT\"><block type=\"text\" id=\"70\"><field name=\"TEXT\">looking for face</field></block></value></block></statement></block></next></block></next></block></statement></block></xml>", "code": "face_x_y_size = None\nface_x = None\nface_y = None\nface_size = None\n\n\nwhile True:\n get_prog_eng().check_end()\n face_x_y_size = get_cam().find_face()\n face_x = face_x_y_size[0]\n if face_x:\n face_y = face_x_y_size[1]\n face_size = face_x_y_size[2]\n get_cam().set_text(''.join([str(temp_value) for temp_value in ['face at ', face_x, 'x, ', face_y, 'y, ', face_size, ' size']]))\n else:\n get_cam().set_text('looking for face')\n", "name": "face_finder"}

data/program_servo test.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=\"coderbot_adv_motor\" id=\"118\" inline=\"true\" x=\"48\" y=\"52\"><value name=\"SPEED_LEFT\"><block type=\"math_number\" id=\"119\"><field name=\"NUM\">10</field></block></value><value name=\"SPEED_RIGHT\"><block type=\"math_number\" id=\"120\"><field name=\"NUM\">30</field></block></value><value name=\"ELAPSE\"><block type=\"math_number\" id=\"121\"><field name=\"NUM\">1</field></block></value></block></xml>", "code": "get_bot().motor_control(speed_left=10, speed_right=30, elapse=1)\n", "name": "servo test"}

main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ def handle_bot():
101101
logging.info("shutting down")
102102
bot.say(app.bot_config.get("sound_stop"))
103103
bot.halt()
104+
elif cmd == "restart":
105+
logging.info("restarting bot")
106+
bot.restart()
107+
elif cmd == "reboot":
108+
logging.info("rebooting")
109+
bot.reboot()
104110

105111
return "ok"
106112

static/js/blockly/blocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ Blockly.Blocks['coderbot_adv_findFace'] = {
645645
this.setHelpUrl(Blockly.Msg.LOGIC_BOOLEAN_HELPURL);
646646
this.setColour(290);
647647
this.appendDummyInput()
648-
.appendField(Blockly.Msg.CODERBOT_SENSOR_FINDFACE_FIND)
648+
.appendField(Blockly.Msg.CODERBOT_SENSOR_FINDFACE)
649649
.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')
650650
this.setInputsInline(true);
651651
this.setOutput(true, ['Number', 'Array']);

static/js/blockly/bot_en.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +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)";
44+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_X = "x coord";
45+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_Y = "y coord";
46+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_SIZE = "size";
47+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_ALL = "x, y, size (as list)";
4848
Blockly.Msg.CODERBOT_SENSOR_FINDLOGO = "find logo";

static/js/blockly/bot_it.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +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)";
44+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_X = "x (ascissa)";
45+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_Y = "y (ordinata)";
46+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_SIZE = "dimensione";
47+
Blockly.Msg.CODERBOT_SENSOR_FINDFACE_ALL = "x, y, dimensione (come lista)";
4848
Blockly.Msg.CODERBOT_SENSOR_FINDLOGO = "trova logo";

static/js/coderbot.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,11 @@ CoderBot.prototype.say = function(h) {
7070
CoderBot.prototype.halt = function(h) {
7171
this.command('halt', h);
7272
}
73+
74+
CoderBot.prototype.restart = function(h) {
75+
this.command('restart', h);
76+
}
77+
78+
CoderBot.prototype.reboot = function(h) {
79+
this.command('reboot', h);
80+
}

static/js/control.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ $(document).on( "pagecreate", '#page-control', function( event ) {
8787
$('#b_photos').on("click", function (){
8888
$.mobile.pageContainer.pagecontainer('change', '#page-photos');
8989
});
90-
$('#b_halt').on("click", function (){
91-
if(confirm("Shutdown CoderBot?")){
92-
bot.halt();
93-
}
94-
});
9590
$( ".photopopup" ).on({
9691
popupbeforeposition: function() {
9792
var maxHeight = $( window ).height() - 60 + "px";
@@ -121,7 +116,21 @@ $(document).on( "pagecreate", '#page-preferences', function( event ) {
121116
}
122117
return false;
123118
});
124-
119+
$('#b_halt').on("click", function (){
120+
if(confirm("Shutdown CoderBot?")){
121+
bot.halt();
122+
}
123+
});
124+
$('#b_restart').on("click", function (){
125+
if(confirm("Restart CoderBot?")){
126+
bot.restart();
127+
}
128+
});
129+
$('#b_reboot').on("click", function (){
130+
if(confirm("Reboot CoderBot?")){
131+
bot.reboot();
132+
}
133+
});
125134
});
126135

127136
$(document).on( "pageshow", '#page-photos', function( event ) {

templates/config.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ <h1>CoderBot</h1>
1717
<li><a href="#t_button" data-ajax="true">{% trans %}Button{% endtrans %}</a></li>
1818
<li><a href="#t_ui" data-ajax="true">{% trans %}User Interface{% endtrans %}</a></li>
1919
<li><a href="#t_wifi" data-ajax="true">{% trans %}WiFi{% endtrans %}</a></li>
20+
<li><a href="#t_halt" data-ajax="true">{% trans %}Restart, Halt{% endtrans %}</a></li>
2021
</ul>
2122
</div>
2223
<div id="t_control" class="ui-body-d ui-content">
@@ -136,13 +137,17 @@ <h1>CoderBot</h1>
136137
</fieldset>
137138
</div>
138139
<div id="t_wifi" class="ui-body-d ui-content">
139-
<a href="#popup-wifi" data-rel="popup" id="b_wifi_access_mode" class="ui-btn ui-shadow ui-corner-all ui-btn-a ui-mini">{% trans %}WiFi Client access mode{% endtrans %}</a>
140-
</div>
140+
<a href="#popup-wifi" data-rel="popup" id="b_wifi_access_mode" class="ui-btn ui-shadow ui-corner-all ui-btn-a ui-mini">{% trans %}WiFi Client access mode{% endtrans %}</a>
141141
<div class="ui-grid-a">
142142
<div class="ui-block-a"><a href="#" data-rel="close" class="ui-btn ui-shadow ui-corner-all ui-btn-b ui-mini">{% trans %}Cancel{% endtrans %}</a></div>
143143
<div class="ui-block-b"><button type="submit" id="b_config_save" data-rel="close" class="ui-btn ui-shadow ui-corner-all ui-btn-a ui-mini">{% trans %}Save{% endtrans %}</button></div>
144144
</div>
145145
</div>
146+
<div id="t_halt" class="ui-body-d ui-content">
147+
<button id="b_halt" class="ui-btn ui-btn-inline ui-shadow ui-corner-all ui-btn-icon-left ui-icon-power" type="button">{% trans %}Halt{% endtrans %}</button>
148+
<button id="b_restart" class="ui-btn ui-btn-inline ui-shadow ui-corner-all ui-btn-icon-left ui-icon-refresh" type="button">{% trans %}Restart{% endtrans %}</button>
149+
<button id="b_reboot" class="ui-btn ui-btn-inline ui-shadow ui-corner-all ui-btn-icon-left ui-icon-alert" type="button">{% trans %}Reboot{% endtrans %}</button>
150+
</div>
146151
</form>
147152
</div>
148153
<div data-role="popup" id="popup-wifi" data-history="false" data-theme="a" class="ui-corner-all" data-dismissible="false" data-position-to="window">

templates/control.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ <h1>CoderBot</h1>
1515
{%if config.ctrl_counter%}<div class="" style="position:fixed;left:32px;top:80px;">
1616
<button id="b_counter" class="ui-btn ui-btn-inline ui-btn-traslucent" type="button">0</button>
1717
</div>{%endif%}
18-
{%if config.show_page_prefs%}<div class="" style="position:fixed;right:32px;top:80px;">
19-
<button id="b_halt" class="ui-btn ui-btn-inline ui-icon-power ui-btn-icon-top ui-btn-traslucent" type="button">{% trans %}Halt{% endtrans %}</button>
20-
</div>{%endif%}
2118
<div class="ui-grid-b" style="position:fixed; width:100%;bottom:0px;">
2219
<div class="ui-block-a" id="ui_control_left">
2320
{% if config.show_control_move_commands%}<fieldset class="ui-grid-solo">

0 commit comments

Comments
 (0)