Robot Dokümantasyonu/Rehberler
Hedefe Git ve Konuş
Bu rehberde robotu bir hedefe gönderip, hedefe vardığında kısa bir mesajı sesli okutmayı göreceksiniz. Örnek, curl kullanan bir bash betiğidir.
Gereksinimler:
- Robota erişimi olan bir API anahtarı ve robotun ID'si (bkz. Başlangıç)
- Bilgisayarınızda curl ve jq kurulu olmalı
- Önceden tanımlanmış bir hedef (örnekteki UID'yi kendi hedefinize göre değiştirin)
- Robot masa servisi modunda olmalı. Betiğin beklediği
AtTheServicedurumu yalnızca masa servisi ve manuel modda vardır
#!/usr/bin/env bash
set -euo pipefail
# Configuration
ROBOT_ID="${ROBOT_ID:?Set ROBOT_ID to the robot ID}"
API_KEY="${API_KEY:?Set API_KEY to your API key}"
ROBOT_URL="${ROBOT_URL:-https://robots.saharobotik.com/api/v1/${ROBOT_ID}/robot}"
TARGET_NAME=${TARGET_NAME:-target_01}
TARGET_UID=${TARGET_UID:-site_floor_${TARGET_NAME}}
command -v jq >/dev/null 2>&1 || { echo "jq is required (sudo apt install jq)"; exit 1; }
echo "=================================================="
echo "Robot goes to target and speaks"
echo "=================================================="
echo "[1/3] Sending task to go to target: ${TARGET_NAME} (${TARGET_UID})"
create_task_resp=$(curl -sS -X POST "${ROBOT_URL}/tasks" \
-H "x-api-key: ${API_KEY}" \
-H 'Content-Type: application/json' \
-d "{\
\"type\": \"TABLE_SERVICE\",\
\"target_uid\": \"${TARGET_UID}\",\
\"activate\": true,\
\"payload\": [true, false, false, false]\
}")
success=$(echo "$create_task_resp" | jq -r '.success // empty')
message=$(echo "$create_task_resp" | jq -r '.message // empty')
if [ "$success" != "true" ]; then
echo "✗ Failed to create task: ${message}"
exit 1
fi
echo "✓ ${message}"
echo
echo "[2/3] Waiting until the robot reaches the target (state: AtTheService)"
echo "(Press Ctrl+C to abort)"
while :; do
status_resp=$(curl -sS -H "x-api-key: ${API_KEY}" "${ROBOT_URL}/status")
state_label=$(echo "$status_resp" | jq -r '.state_label // empty')
echo " - state_label: ${state_label}"
if [ "$state_label" = "AtTheService" ]; then
break
fi
sleep 2
done
echo
echo "[3/3] Speaking via UI API"
speech_resp=$(curl -sS -X POST "${ROBOT_URL}/ui/speech" \
-H "x-api-key: ${API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"lang": "en",
"text": "Hello world! I have reached the target."
}')
speech_ok=$(echo "$speech_resp" | jq -r '.success // empty')
if [ "$speech_ok" = "true" ]; then
echo "✓ Speech sent successfully"
else
echo "✗ Speech failed: $(echo "$speech_resp" | jq -r '.message // .')"
fi
echo
echo "=================================================="
echo "All done!"
echo "=================================================="Notlar:
- ROBOT_ID ve API_KEY zorunludur. ROBOT_URL, TARGET_NAME ve TARGET_UID değerlerini ortam değişkenleriyle değiştirebilirsiniz.
- Betik, konuşma komutunu göndermeden önce state_label değerinin AtTheService olmasını bekler.