blob: 489112cdf9a1ac0e9e7e379625a7b1f92efec77c [file] [log] [blame]
Alex Perry554cec02019-03-23 20:15:12 -07001import {IN_TO_M, FT_TO_M} from './constants';
James Kuszmaul92ba0e52019-03-29 17:19:30 -07002import {CAMERA_POSES} from './camera_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
James Kuszmaul92ba0e52019-03-29 17:19:30 -07008function drawCamera(ctx : canvasRenderingContext2d, pose : {x : number, y : number, theta : number}) : void {
9 ctx.beginPath();
10 ctx.moveTo(pose.x, pose.y);
11 ctx.lineTo(pose.x + CAMERA_SCALE * Math.cos(pose.theta + Math.PI / 4.0),
12 pose.y + CAMERA_SCALE * Math.sin(pose.theta + Math.PI / 4.0));
13 ctx.lineTo(pose.x + CAMERA_SCALE * Math.cos(pose.theta - Math.PI / 4.0),
14 pose.y + CAMERA_SCALE * Math.sin(pose.theta - Math.PI / 4.0));
15 ctx.closePath();
16 ctx.stroke();
17}
18
19export function drawRobot(ctx : CanvasRenderingContext2D, x : number, y : number, theta : number, camera_colors : string[]) : void {
Alex Perry554cec02019-03-23 20:15:12 -070020 ctx.save();
21 ctx.translate(x, y);
22 ctx.rotate(theta);
23
24 ctx.fillStyle = 'blue';
25 ctx.fillRect(-ROBOT_LENGTH / 2, -ROBOT_WIDTH / 2, ROBOT_LENGTH, ROBOT_WIDTH);
26
James Kuszmaul92ba0e52019-03-29 17:19:30 -070027 ctx.beginPath();
28 ctx.strokeStyle = 'black';
Alex Perry554cec02019-03-23 20:15:12 -070029 ctx.moveTo(ROBOT_LENGTH / 2, -ROBOT_WIDTH/2);
30 ctx.lineTo(ROBOT_LENGTH / 2 + 0.1, 0);
31 ctx.lineTo(ROBOT_LENGTH / 2, ROBOT_WIDTH/2);
32 ctx.closePath();
33 ctx.stroke();
James Kuszmaul92ba0e52019-03-29 17:19:30 -070034 ctx.lineWidth = 3.0 * ctx.lineWidth;
35 for (let ii of [0, 1, 2, 3, 4]) {
36 ctx.strokeStyle = camera_colors[ii];
37 drawCamera(ctx, CAMERA_POSES[ii]);
38 }
Alex Perry554cec02019-03-23 20:15:12 -070039
40 ctx.restore();
41}