Gemini Robotics ER モデルは、タスクを計画し、空間について推論できます。目標を達成するためにどのようなアクションを実行し、どのオブジェクトを移動すべきかを推論します。このページでは、カスタム ロボット API を介してピック アンド プレースを駆動し、アイテムをボウルに入れるタスクをオーケストレートする例を示します。
実行可能な完全なコードについては、ロボティクス クックブックをご覧ください。
カスタム ロボット API を使用する
この例では、カスタム ロボット API を使用したタスク オーケストレーションを示します。このサンプルでは、ピッキングと配置のオペレーション用に設計されたモック API を紹介します。青いブロックを拾ってオレンジ色のボウルに入れるタスクです。

この例では、次のモックロボット API とツールの定義を使用します。
Python
from google import genai
from google.genai import types
client = genai.Client()
def move(x, y, high):
print(f"Mock Robot: Moving to coordinates: {x}, {y}, {'high above table' if high else 'down at table level'}")
def setGripperState(opened):
print(f"Mock Robot: {'Opening gripper' if opened else 'Closing gripper'}")
robot_origin_y = 300
robot_origin_x = 500
move_declaration = types.FunctionDeclaration(
name="move",
description="Moves the arm to the given coordinates.",
parameters=types.Schema(
type=types.Type.OBJECT,
properties={
"x": types.Schema(type=types.Type.INTEGER, description="X coordinate relative to the origin"),
"y": types.Schema(type=types.Type.INTEGER, description="Y coordinate relative to the origin"),
"high": types.Schema(type=types.Type.BOOLEAN, description="Set to True to lift the robot arm above the scene. Set to False to place the gripper on the surface."),
},
required=["x", "y", "high"],
),
)
set_gripper_state_declaration = types.FunctionDeclaration(
name="setGripperState",
description="Opens or closes the robot's gripper.",
parameters=types.Schema(
type=types.Type.OBJECT,
properties={
"opened": types.Schema(type=types.Type.BOOLEAN, description="True opens the gripper, False closes the gripper."),
},
required=["opened"],
),
)
robot_tools = types.Tool(function_declarations=[move_declaration, set_gripper_state_declaration])
次の例では、プロンプトと画像をツール定義とともにモデルに送信します。次に、エージェント ループを実行します。モデルのレスポンスごとに、リクエストされた関数呼び出し(move、setGripperState)を実行し、結果をモデルに返します。モデルが関数の呼び出しを停止するか、ステップの上限に達するまで、この処理を繰り返します。
Python
with open("robot-api-example.png", "rb") as f:
img_bytes = f.read()
prompt = (
"You are a robotic arm with six degrees-of-freedom. "
f"The origin point for calculating the moves is at normalized point y={robot_origin_y}, x={robot_origin_x}. "
"Use this as the new (0,0) for calculating moves, allowing x and y to be negative.\n\n"
"Find the blue block and the orange bowl. Calculate their coordinates relative to the origin.\n"
"Perform a pick and place operation where you pick up the blue block and place it into the orange bowl. "
"Call the appropriate sequence of functions to complete this operation."
)
contents = [
types.Content(role="user", parts=[
types.Part.from_bytes(data=img_bytes, mime_type="image/png"),
types.Part(text=prompt),
])
]
print("\n--- Executing Orchestrated Plan ---")
max_steps = 15 # Safety limit to prevent infinite loops
step_count = 0
# The Agentic Loop
while step_count < max_steps:
step_count += 1
response = client.models.generate_content(
model="gemini-robotics-er-2-preview",
contents=contents,
config=types.GenerateContentConfig(
tools=[robot_tools],
thinking_config=types.ThinkingConfig(thinking_level="low"),
),
)
# Add model response to conversation history
contents.append(response.candidates[0].content)
# Check for function calls
function_calls = [part for part in response.candidates[0].content.parts if part.function_call]
if not function_calls:
# Model is done calling functions
print("Sequence complete.")
print(f"Model Summary: {response.text}")
break
# Execute function calls and collect results
function_response_parts = []
for part in function_calls:
fc = part.function_call
if fc.name == "move":
move(**fc.args)
elif fc.name == "setGripperState":
setGripperState(**fc.args)
function_response_parts.append(
types.Part.from_function_response(
name=fc.name,
response={"status": "success"},
)
)
# Send function results back to model
contents.append(types.Content(role="user", parts=function_response_parts))
プロンプトとモックロボット API に基づくモデルの出力例を次に示します。出力には、モデルが順序付けたロボット関数呼び出しの出力が含まれます。
--- Executing Orchestrated Plan ---
Mock Robot: Opening gripper
Mock Robot: Moving to coordinates: 160, 440, high above table
Mock Robot: Moving to coordinates: 160, 440, down at table level
Mock Robot: Closing gripper
Mock Robot: Moving to coordinates: 160, 440, high above table
Mock Robot: Moving to coordinates: -250, 60, high above table
Mock Robot: Moving to coordinates: -250, 60, down at table level
Mock Robot: Opening gripper
Mock Robot: Moving to coordinates: -250, 60, high above table
Sequence complete.
Model Summary: I have completed the task of picking up the blue block and placing it into the orange bowl.
次のステップ
- ストリーミングを使用したロボット工学 - 関数呼び出しを使用したリアルタイム ストリーミング(Gemini Robotics ER 2 のみ)。
- 動画の理解 - 動画からタスクの進捗状況を追跡します(ER 2 のみ)。
- 空間推論 - ポインティング、トラッキング、境界ボックスの例。