File size: 3,974 Bytes
0d9f1af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import React, { useState, useEffect } from "react";
import { Button } from "../components/ui/button";
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "../components/ui/card";
import { Alert, AlertDescription } from "../components/ui/alert";
import { Badge } from "../components/ui/badge";
import { CalibrationWizard } from "../components/CalibrationWizard";
import type { ConnectedRobot } from "../types";

interface CalibrateProps {
  selectedRobot: ConnectedRobot;
  onBack: () => void;
  onHome: () => void;
}

export function Calibrate({ selectedRobot, onBack, onHome }: CalibrateProps) {
  const [calibrationStarted, setCalibrationStarted] = useState(false);

  // Auto-start calibration when component mounts
  useEffect(() => {
    if (selectedRobot && selectedRobot.isConnected) {
      setCalibrationStarted(true);
    }
  }, [selectedRobot]);

  if (!selectedRobot) {
    return (
      <div className="container mx-auto px-4 py-8">
        <Alert variant="destructive">
          <AlertDescription>
            No robot selected. Please go back to setup.
          </AlertDescription>
        </Alert>
        <div className="mt-4">
          <Button onClick={onBack}>Back to Setup</Button>
        </div>
      </div>
    );
  }

  return (
    <div className="container mx-auto px-4 py-8 max-w-4xl">
      <div className="space-y-6">
        <div className="text-center space-y-2">
          <h1 className="text-3xl font-bold">Robot Calibration</h1>
          <p className="text-muted-foreground">
            Calibrating: {selectedRobot.robotId}
          </p>
        </div>

        <Card>
          <CardHeader>
            <div className="flex items-center justify-between">
              <div>
                <CardTitle className="text-xl">
                  {selectedRobot.robotId}
                </CardTitle>
                <CardDescription>{selectedRobot.name}</CardDescription>
              </div>
              <div className="flex items-center space-x-2">
                <Badge
                  variant={selectedRobot.isConnected ? "default" : "secondary"}
                >
                  {selectedRobot.isConnected ? "Connected" : "Disconnected"}
                </Badge>
                <Badge variant="outline">
                  {selectedRobot.robotType?.replace("_", " ")}
                </Badge>
              </div>
            </div>
          </CardHeader>
          <CardContent>
            {!selectedRobot.isConnected ? (
              <Alert variant="destructive">
                <AlertDescription>
                  Robot is not connected. Please check connection and try again.
                </AlertDescription>
              </Alert>
            ) : calibrationStarted ? (
              <CalibrationWizard
                robot={selectedRobot}
                onComplete={onHome}
                onCancel={onBack}
              />
            ) : (
              <div className="space-y-4">
                <div className="text-center py-8">
                  <div className="text-2xl mb-4">🛠️</div>
                  <h3 className="text-lg font-semibold mb-2">
                    Ready to Calibrate
                  </h3>
                  <p className="text-muted-foreground mb-4">
                    Make sure your robot arm is in a safe position and you have
                    a clear workspace.
                  </p>
                  <Button onClick={() => setCalibrationStarted(true)} size="lg">
                    Start Calibration
                  </Button>
                </div>
              </div>
            )}
          </CardContent>
        </Card>

        <div className="flex justify-center space-x-4">
          <Button variant="outline" onClick={onBack}>
            Back to Setup
          </Button>
          <Button variant="outline" onClick={onHome}>
            Back to Home
          </Button>
        </div>
      </div>
    </div>
  );
}