# INSTRUCTION="Pick up the pan and put it in the basket."
# INSTRUCTION="Pick up the bowl and put it in the basket."
# INSTRUCTION="Pick up the red headset and put it in the bowl."
# INSTRUCTION="Pick up the bowl from basket."
# INSTRUCTION="Folding the towel and place it in the basket."
# INSTRUCTION="Task: Folding the towel and place it in the basket. What should the robot do next? One imperative sentence."
# INSTRUCTION="Folding the T-shirt and place it on the top-left, stack it neatly with the other T-shirts."
# INSTRUCTION="Pick one towel from the right stack. Spread it flat on the table. Fold it in half from top to bottom. Fold it diagonally in half. Neatly stack it with the folded towels in the upper-left corner."
# INSTRUCTION="Pick up the object on the table and put it into the bowl."
# INSTRUCTION="Folding the T-shirt and place it on the top-left, stack it neatly with the other T-shirts."
# INSTRUCTION="Pick up the pen and place it into the cup."
# INSTRUCTION="First, place the medium bowl inside the large one. Then, stack the small bowl on top."
# INSTRUCTION="stack the two smaller bowls on top of the largest bowl one by one."
# INSTRUCTION="stack the two larger bowls on top of the smallest bowl one by one."
# INSTRUCTION="insert the two flower on the table into the vase one by one"
# INSTRUCTION="place the cup on the coaster."
# INSTRUCTION="place the bowl on the coaster."
# INSTRUCTION="place the pen on the table into the pencil case."
# INSTRUCTION="Put the pens on the desk into the pen holder."
# INSTRUCTION="Put the banana on the desk into the bowl."
# INSTRUCTION="Put the pen on the desk into the bowl."
# INSTRUCTION="Put the orange bowl into the pink bowl."


# INSTRUCTION="Pick up the pen and put it into the white storage basket."
# INSTRUCTION="Take one towel a time from the right box, lay it flat, fold the towel and place it in the basket on the left."

# INSTRUCTION="Pick up the small ball and place it into the cup."
# INSTRUCTION="insert the pen on the table into the pen holder."
# INSTRUCTION="Put the yellow block into the blue bowl."
# INSTRUCTION="Pick up the dolls into the white storage basket."
INSTRUCTION="Put the dolls into the white storage basket."
# INSTRUCTION="Put the banana into the white storage basket."
# INSTRUCTION="Put the lemon into the bowl."
# INSTRUCTION="Task: Put the cherry into the blue bowl , then put the doll into the pink bowl. What should the robot do next? One imperative sentence."
# INSTRUCTION="Put the cherry into the blue bowl , then put the doll into the pink bowl."
# INSTRUCTION="Put the object into the cup."
# INSTRUCTION="Put the banana into the white storage basket."
# INSTRUCTION="Put the red marker into the white storage basket."
# INSTRUCTION="Pick up the yellow cube and put it into the bowl."
# INSTRUCTION="Put the lemon into the purple bin."
# INSTRUCTION="Put the bowl into the white storage basket."
# INSTRUCTION="Put the banana into the white storage basket."
# INSTRUCTION="Put bananas on the left plate, and the dolls on right plate."
# INSTRUCTION="Put dolls on the left plate, and the bananas on right plate."
# INSTRUCTION="Put the banana into the white storage basket."
# INSTRUCTION="Put the blue block into the white storage basket."
# INSTRUCTION="grab the red block and put it into the white storage basket."
# INSTRUCTION="place the banana on the table into the pencil case."
# INSTRUCTION="insert the one flower on the table into the vase."
# INSTRUCTION="Open the second drawer of the top-left cabinet. Put the desktop tape and wallet inside, then close the drawer."
# INSTRUCTION="Stamp the signature area on the paper."

# Novel instruction
# INSTRUCTION="Pick up the banana and put it into the pink plate."
# INSTRUCTION="Stamp the signature area on the paper."
# INSTRUCTION="Wipe the blackboard clean."


# Release Frequently Used Instructions.
# INSTRUCTION="Folding the towel and place it in the basket."
# INSTRUCTION="Pick one towel from the right stack. Spread it flat on the table. Fold it in half from top to bottom. Fold it diagonally in half. Neatly stack it with the folded towels in the upper-left corner."
INSTRUCTION="Put the dolls into the white storage basket."
# INSTRUCTION="Folding the T-shirt and place it on the top-left, stack it neatly with the other T-shirts."
# INSTRUCTION="Pick up one block at a time from the table, separating it from any block it is touching. Place each block into the container that already contains blocks of the same color. Repeat until all blocks have been sorted."
# INSTRUCTION="Pick up one object at a time. Find the hole with the matching color and the exact matching shape. Precisely align the object and fully insert it until it is completely seated. Repeat until all objects have been inserted."

# XFuse speed（需模型 enable_speed_change；范围见 config speed_min/speed_max）
SPEED=1.0

# 远端 absolute_pose chunk 执行频率（Hz）；对齐 absolute_pose_chunk_demo 默认 10
# 本地 zc 约 30fps；远端 settle 较严时用 10，避免 waypoint 间来不及到位
EXEC_FREQUENCY="${EXEC_FREQUENCY:-30}"

# ---------- NexBench 连接（也可用环境变量 NEX_* 覆盖）----------
# mock:
#   NEX_ENDPOINT=ws://127.0.0.1:8765
#   NEX_TASK_EVAL_ID=mock-eval-0001
# 真实后端:
#   NEX_USERNAME=... NEX_PASSWORD=... NEX_TASK_ID=...
NEX_ENDPOINT="${NEX_ENDPOINT:-ws://124.174.105.207:8222/control}"
NEX_FEEDBACK_ENDPOINT="${NEX_FEEDBACK_ENDPOINT:-}"
NEX_USERNAME="${NEX_USERNAME:-}"
NEX_PASSWORD="${NEX_PASSWORD:-}"
NEX_TASK_ID="${NEX_TASK_ID:-}"
NEX_TASK_EVAL_ID="${NEX_TASK_EVAL_ID:-}"
NEX_API_KEY="${NEX_API_KEY:-}"
# Policy server（与 server_test.sh 默认端口一致）
POLICY_URL="${POLICY_URL:-tcp://localhost:5562}"

# 松灵坐标系旋转对齐（与 DualTouchRobot 一致；远端 orientation_error≈π/2 时务必打开）
# APPLY_EEF_ROT_OBS=0 / APPLY_EEF_ROT_EXEC=0 可临时关闭做对比
APPLY_EEF_ROT_OBS="${APPLY_EEF_ROT_OBS:-0}"
APPLY_EEF_ROT_EXEC="${APPLY_EEF_ROT_EXEC:-0}"

CLIENT_ARGS=(
    --instruction "$INSTRUCTION"
    --robot_type "lumos_touch_dualarm"
    --steps 25
    --speed "$SPEED"
    --frequency "$EXEC_FREQUENCY"
    --url "$POLICY_URL"
    --endpoint "$NEX_ENDPOINT"
)

if [ -n "$NEX_FEEDBACK_ENDPOINT" ]; then
  CLIENT_ARGS+=(--feedback-endpoint "$NEX_FEEDBACK_ENDPOINT")
fi
if [ -n "$NEX_USERNAME" ]; then
  CLIENT_ARGS+=(--username "$NEX_USERNAME")
fi
if [ -n "$NEX_PASSWORD" ]; then
  CLIENT_ARGS+=(--password "$NEX_PASSWORD")
fi
if [ -n "$NEX_TASK_ID" ]; then
  CLIENT_ARGS+=(--task-id "$NEX_TASK_ID")
fi
if [ -n "$NEX_TASK_EVAL_ID" ]; then
  CLIENT_ARGS+=(--task-eval-id "$NEX_TASK_EVAL_ID")
fi
if [ -n "$NEX_API_KEY" ]; then
  CLIENT_ARGS+=(--api-key "$NEX_API_KEY")
fi
if [ "${APPLY_EEF_ROT_OBS}" = "1" ]; then
  CLIENT_ARGS+=(--apply-eef-rot-obs)
fi
if [ "${APPLY_EEF_ROT_EXEC}" = "1" ]; then
  CLIENT_ARGS+=(--apply-eef-rot-exec)
fi

# 透传额外 CLI 参数，例如: ./client_touch_nex.sh --steps 10
# 调试落盘默认开启 → nex_debug/run_<时间戳>/；关闭: --no-debug-dump
CLIENT_ARGS+=("$@")

# FluxWAM h40：跳过 chunk 前 6 步（对齐训练 action_indices），每轮执行 ~steps 步再重规划
# 整段 chunk 经 absolute_pose + exec_frequency 一次下发到远端
python transport_client_touch_nex.py "${CLIENT_ARGS[@]}"
