blob: 6329fb391626225500c3697f6140af7d35b07e3e [file] [log] [blame]
James Kuszmaul92ba0e52019-03-29 17:19:30 -07001import {CAMERA_POSES} from './camera_constants';
Alex Perry5b895622019-04-06 14:27:55 -07002import {FT_TO_M, IN_TO_M} from './constants';
Alex Perry554cec02019-03-23 20:15:12 -07003
4const ROBOT_WIDTH = 25 * IN_TO_M;
5const ROBOT_LENGTH = 31 * IN_TO_M;
James Kuszmaul92ba0e52019-03-29 17:19:30 -07006const CAMERA_SCALE = 0.3;
Alex Perry554cec02019-03-23 20:15:12 -07007
Alex Perry5b895622019-04-06 14:27:55 -07008function drawCamera(
9 ctx: CanvasRenderingContext2D,
10 pose: {x: number, y: number, theta: number}): void {
James Kuszmaul92ba0e52019-03-29 17:19:30 -070011 ctx.beginPath();
12 ctx.moveTo(pose.x, pose.y);
Alex Perry5b895622019-04-06 14:27:55 -070013 ctx.lineTo(
14 pose.x + CAMERA_SCALE * Math.cos(pose.theta + Math.PI / 4.0),
15 pose.y + CAMERA_SCALE * Math.sin(pose.theta + Math.PI / 4.0));
16 ctx.lineTo(
17 pose.x + CAMERA_SCALE * Math.cos(pose.theta - Math.PI / 4.0),
18 pose.y + CAMERA_SCALE * Math.sin(pose.theta - Math.PI / 4.0));
James Kuszmaul92ba0e52019-03-29 17:19:30 -070019 ctx.closePath();
20 ctx.stroke();
21}
22
Alex Perry5b895622019-04-06 14:27:55 -070023export function drawRobot(
24 ctx: CanvasRenderingContext2D, x: number, y: number, theta: number,
25 camera_colors: string[]): void {
Alex Perry554cec02019-03-23 20:15:12 -070026 ctx.save();
27 ctx.translate(x, y);
28 ctx.rotate(theta);
29
30 ctx.fillStyle = 'blue';
31 ctx.fillRect(-ROBOT_LENGTH / 2, -ROBOT_WIDTH / 2, ROBOT_LENGTH, ROBOT_WIDTH);
32
James Kuszmaul92ba0e52019-03-29 17:19:30 -070033 ctx.beginPath();
34 ctx.strokeStyle = 'black';
Alex Perry5b895622019-04-06 14:27:55 -070035 ctx.moveTo(ROBOT_LENGTH / 2, -ROBOT_WIDTH / 2);
Alex Perry554cec02019-03-23 20:15:12 -070036 ctx.lineTo(ROBOT_LENGTH / 2 + 0.1, 0);
Alex Perry5b895622019-04-06 14:27:55 -070037 ctx.lineTo(ROBOT_LENGTH / 2, ROBOT_WIDTH / 2);
Alex Perry554cec02019-03-23 20:15:12 -070038 ctx.closePath();
39 ctx.stroke();
James Kuszmaul92ba0e52019-03-29 17:19:30 -070040 ctx.lineWidth = 3.0 * ctx.lineWidth;
41 for (let ii of [0, 1, 2, 3, 4]) {
42 ctx.strokeStyle = camera_colors[ii];
43 drawCamera(ctx, CAMERA_POSES[ii]);
44 }
Alex Perry554cec02019-03-23 20:15:12 -070045
46 ctx.restore();
47}