James Kuszmaul | dac091f | 2022-03-22 09:35:06 -0700 | [diff] [blame] | 1 | import {ByteBuffer} from 'flatbuffers'; |
James Kuszmaul | b84c091 | 2022-04-13 19:44:52 -0700 | [diff] [blame] | 2 | import {Connection} from '../../aos/network/www/proxy'; |
| 3 | import {Status as DrivetrainStatus} from '../../frc971/control_loops/drivetrain/drivetrain_status_generated'; |
| 4 | import {LocalizerDebug, RejectionReason, ImageMatchDebug} from '../control_loops/drivetrain/localizer_debug_generated'; |
Maxwell Henderson | 3424299 | 2024-01-07 12:39:11 -0800 | [diff] [blame^] | 5 | import {Status as SuperstructureStatus} from '../control_loops/superstructure/superstructure_status_generated' |
| 6 | import {FlywheelControllerStatus} from '../../frc971/control_loops/flywheel/flywheel_controller_status_generated' |
James Kuszmaul | b84c091 | 2022-04-13 19:44:52 -0700 | [diff] [blame] | 7 | import {ImageMatchResult} from '../vision/sift/sift_generated'; |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 8 | |
Alex Perry | 2124ae8 | 2020-03-07 14:19:06 -0800 | [diff] [blame] | 9 | import {FIELD_LENGTH, FIELD_WIDTH, FT_TO_M, IN_TO_M} from './constants'; |
| 10 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 11 | // (0,0) is field center, +X is toward red DS |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 12 | const FIELD_SIDE_Y = FIELD_WIDTH / 2; |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 13 | const FIELD_EDGE_X = FIELD_LENGTH / 2; |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 14 | |
| 15 | const DS_WIDTH = 69 * IN_TO_M; |
| 16 | const DS_ANGLE = 20 * Math.PI / 180; |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 17 | const DS_END_X = FIELD_EDGE_X - DS_WIDTH * Math.sin(DS_ANGLE); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 18 | const DS_INSIDE_Y = FIELD_SIDE_Y - DS_WIDTH * Math.cos(DS_ANGLE); |
| 19 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 20 | const TRENCH_X = 108 * IN_TO_M; |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 21 | const TRENCH_WIDTH = 55.5 * IN_TO_M; |
| 22 | const TRENCH_INSIDE = FIELD_SIDE_Y - TRENCH_WIDTH; |
| 23 | |
| 24 | const SPINNER_LENGTH = 30 * IN_TO_M; |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 25 | const SPINNER_TOP_X = 374.59 * IN_TO_M - FIELD_EDGE_X; |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 26 | const SPINNER_BOTTOM_X = SPINNER_TOP_X - SPINNER_LENGTH; |
| 27 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 28 | const SHIELD_BOTTOM_X = -116 * IN_TO_M; |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 29 | const SHIELD_BOTTOM_Y = 43.75 * IN_TO_M; |
| 30 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 31 | const SHIELD_TOP_X = 116 * IN_TO_M; |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 32 | const SHIELD_TOP_Y = -43.75 * IN_TO_M; |
| 33 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 34 | const SHIELD_RIGHT_X = -51.06 * IN_TO_M; |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 35 | const SHIELD_RIGHT_Y = -112.88 * IN_TO_M; |
| 36 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 37 | const SHIELD_LEFT_X = 51.06 * IN_TO_M; |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 38 | const SHIELD_LEFT_Y = 112.88 * IN_TO_M; |
| 39 | |
| 40 | const SHIELD_CENTER_TOP_X = (SHIELD_TOP_X + SHIELD_LEFT_X) / 2 |
| 41 | const SHIELD_CENTER_TOP_Y = (SHIELD_TOP_Y + SHIELD_LEFT_Y) / 2 |
| 42 | |
| 43 | const SHIELD_CENTER_BOTTOM_X = (SHIELD_BOTTOM_X + SHIELD_RIGHT_X) / 2 |
| 44 | const SHIELD_CENTER_BOTTOM_Y = (SHIELD_BOTTOM_Y + SHIELD_RIGHT_Y) / 2 |
| 45 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 46 | const INITIATION_X = FIELD_EDGE_X - 120 * IN_TO_M; |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 47 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 48 | const TARGET_ZONE_TIP_X = FIELD_EDGE_X - 30 * IN_TO_M; |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 49 | const TARGET_ZONE_WIDTH = 48 * IN_TO_M; |
| 50 | const LOADING_ZONE_WIDTH = 60 * IN_TO_M; |
| 51 | |
Austin Schuh | b863f93 | 2021-10-23 23:29:09 -0700 | [diff] [blame] | 52 | const ROBOT_WIDTH = 34 * IN_TO_M; |
| 53 | const ROBOT_LENGTH = 36 * IN_TO_M; |
Alex Perry | 2124ae8 | 2020-03-07 14:19:06 -0800 | [diff] [blame] | 54 | |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 55 | const PI_COLORS = ['#ff00ff', '#ffff00', '#000000', '#00ffff', '#ffa500']; |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 56 | |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 57 | export class FieldHandler { |
| 58 | private canvas = document.createElement('canvas'); |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 59 | private imageMatchResult = new Map<string, ImageMatchResult>(); |
Philipp Schrader | a227d04 | 2020-11-14 17:33:52 -0800 | [diff] [blame] | 60 | private drivetrainStatus: DrivetrainStatus|null = null; |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 61 | private superstructureStatus: SuperstructureStatus|null = null; |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 62 | |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 63 | // Image information indexed by timestamp (seconds since the epoch), so that |
| 64 | // we can stop displaying images after a certain amount of time. |
| 65 | private localizerImageMatches = new Map<number, LocalizerDebug>(); |
Austin Schuh | 146c0bc | 2021-11-07 22:33:28 -0800 | [diff] [blame] | 66 | private outerTarget: HTMLElement = |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 67 | (document.getElementById('outer_target') as HTMLElement); |
Austin Schuh | 146c0bc | 2021-11-07 22:33:28 -0800 | [diff] [blame] | 68 | private innerTarget: HTMLElement = |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 69 | (document.getElementById('inner_target') as HTMLElement); |
| 70 | private x: HTMLElement = (document.getElementById('x') as HTMLElement); |
| 71 | private y: HTMLElement = (document.getElementById('y') as HTMLElement); |
| 72 | private theta: HTMLElement = |
| 73 | (document.getElementById('theta') as HTMLElement); |
| 74 | private shotDistance: HTMLElement = |
| 75 | (document.getElementById('shot_distance') as HTMLElement); |
| 76 | private finisher: HTMLElement = |
| 77 | (document.getElementById('finisher') as HTMLElement); |
| 78 | private leftAccelerator: HTMLElement = |
| 79 | (document.getElementById('left_accelerator') as HTMLElement); |
| 80 | private rightAccelerator: HTMLElement = |
| 81 | (document.getElementById('right_accelerator') as HTMLElement); |
| 82 | private innerPort: HTMLElement = |
| 83 | (document.getElementById('inner_port') as HTMLElement); |
| 84 | private hood: HTMLElement = (document.getElementById('hood') as HTMLElement); |
| 85 | private turret: HTMLElement = |
| 86 | (document.getElementById('turret') as HTMLElement); |
Austin Schuh | 146c0bc | 2021-11-07 22:33:28 -0800 | [diff] [blame] | 87 | private ballsShot: HTMLElement = |
| 88 | (document.getElementById('balls_shot') as HTMLElement); |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 89 | private intake: HTMLElement = |
| 90 | (document.getElementById('intake') as HTMLElement); |
| 91 | private imagesAcceptedCounter: HTMLElement = |
| 92 | (document.getElementById('images_accepted') as HTMLElement); |
| 93 | private imagesRejectedCounter: HTMLElement = |
| 94 | (document.getElementById('images_rejected') as HTMLElement); |
| 95 | private rejectionReasonCells: HTMLElement[] = []; |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 96 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 97 | constructor(private readonly connection: Connection) { |
Austin Schuh | 840132b | 2021-10-17 17:40:14 -0700 | [diff] [blame] | 98 | (document.getElementById('field') as HTMLElement).appendChild(this.canvas); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 99 | |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 100 | for (const value in RejectionReason) { |
| 101 | // Typescript generates an iterator that produces both numbers and |
| 102 | // strings... don't do anything on the string iterations. |
| 103 | if (isNaN(Number(value))) { |
| 104 | continue; |
| 105 | } |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 106 | const row = document.createElement('div'); |
| 107 | const nameCell = document.createElement('div'); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 108 | nameCell.innerHTML = RejectionReason[value]; |
| 109 | row.appendChild(nameCell); |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 110 | const valueCell = document.createElement('div'); |
| 111 | valueCell.innerHTML = 'NA'; |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 112 | this.rejectionReasonCells.push(valueCell); |
| 113 | row.appendChild(valueCell); |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 114 | document.getElementById('vision_readouts').appendChild(row); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 115 | } |
| 116 | |
James Kuszmaul | 286b80c | 2021-10-23 21:56:33 -0700 | [diff] [blame] | 117 | for (let ii = 0; ii < PI_COLORS.length; ++ii) { |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 118 | const legendEntry = document.createElement('div'); |
James Kuszmaul | 286b80c | 2021-10-23 21:56:33 -0700 | [diff] [blame] | 119 | legendEntry.style.color = PI_COLORS[ii]; |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 120 | legendEntry.innerHTML = 'PI' + (ii + 1).toString() |
| 121 | document.getElementById('legend').appendChild(legendEntry); |
James Kuszmaul | 286b80c | 2021-10-23 21:56:33 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 124 | this.connection.addConfigHandler(() => { |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 125 | // Go through and register handlers for both all the individual pis as |
| 126 | // well as the local pi. Depending on the node that we are running on, |
| 127 | // different subsets of these will be available. |
James Kuszmaul | 286b80c | 2021-10-23 21:56:33 -0700 | [diff] [blame] | 128 | for (const prefix of ['', '/pi1', '/pi2', '/pi3', '/pi4', '/pi5']) { |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 129 | this.connection.addHandler( |
James Kuszmaul | 286b80c | 2021-10-23 21:56:33 -0700 | [diff] [blame] | 130 | prefix + '/camera', ImageMatchResult.getFullyQualifiedName(), |
| 131 | (res) => { |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 132 | this.handleImageMatchResult(prefix, res); |
| 133 | }); |
| 134 | } |
James Kuszmaul | 527038a | 2020-12-21 23:40:44 -0800 | [diff] [blame] | 135 | this.connection.addHandler( |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 136 | '/drivetrain', LocalizerDebug.getFullyQualifiedName(), (data) => { |
| 137 | this.handleLocalizerDebug(data); |
| 138 | }); |
| 139 | this.connection.addHandler( |
James Kuszmaul | 527038a | 2020-12-21 23:40:44 -0800 | [diff] [blame] | 140 | '/drivetrain', DrivetrainStatus.getFullyQualifiedName(), (data) => { |
| 141 | this.handleDrivetrainStatus(data); |
| 142 | }); |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 143 | this.connection.addHandler( |
| 144 | '/superstructure', SuperstructureStatus.getFullyQualifiedName(), |
| 145 | (data) => { |
| 146 | this.handleSuperstructureStatus(data); |
| 147 | }); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 148 | }); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 149 | } |
| 150 | |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 151 | private handleImageMatchResult(prefix: string, data: Uint8Array): void { |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 152 | const fbBuffer = new ByteBuffer(data); |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 153 | this.imageMatchResult.set( |
James Kuszmaul | dac091f | 2022-03-22 09:35:06 -0700 | [diff] [blame] | 154 | prefix, ImageMatchResult.getRootAsImageMatchResult(fbBuffer)); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 155 | } |
| 156 | |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 157 | private handleLocalizerDebug(data: Uint8Array): void { |
| 158 | const now = Date.now() / 1000.0; |
| 159 | |
| 160 | const fbBuffer = new ByteBuffer(data); |
| 161 | this.localizerImageMatches.set( |
James Kuszmaul | dac091f | 2022-03-22 09:35:06 -0700 | [diff] [blame] | 162 | now, LocalizerDebug.getRootAsLocalizerDebug(fbBuffer)); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 163 | |
| 164 | const debug = this.localizerImageMatches.get(now); |
| 165 | |
| 166 | if (debug.statistics()) { |
| 167 | this.imagesAcceptedCounter.innerHTML = |
| 168 | debug.statistics().totalAccepted().toString(); |
| 169 | this.imagesRejectedCounter.innerHTML = |
| 170 | (debug.statistics().totalCandidates() - |
| 171 | debug.statistics().totalAccepted()) |
| 172 | .toString(); |
| 173 | if (debug.statistics().rejectionReasonCountLength() == |
| 174 | this.rejectionReasonCells.length) { |
| 175 | for (let ii = 0; ii < debug.statistics().rejectionReasonCountLength(); |
| 176 | ++ii) { |
| 177 | this.rejectionReasonCells[ii].innerHTML = |
| 178 | debug.statistics().rejectionReasonCount(ii).toString(); |
| 179 | } |
| 180 | } else { |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 181 | console.error('Unexpected number of rejection reasons in counter.'); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 182 | } |
| 183 | this.imagesRejectedCounter.innerHTML = |
| 184 | (debug.statistics().totalCandidates() - |
| 185 | debug.statistics().totalAccepted()) |
| 186 | .toString(); |
| 187 | } |
| 188 | } |
| 189 | |
Alex Perry | 2124ae8 | 2020-03-07 14:19:06 -0800 | [diff] [blame] | 190 | private handleDrivetrainStatus(data: Uint8Array): void { |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 191 | const fbBuffer = new ByteBuffer(data); |
James Kuszmaul | dac091f | 2022-03-22 09:35:06 -0700 | [diff] [blame] | 192 | this.drivetrainStatus = DrivetrainStatus.getRootAsStatus(fbBuffer); |
Alex Perry | 2124ae8 | 2020-03-07 14:19:06 -0800 | [diff] [blame] | 193 | } |
| 194 | |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 195 | private handleSuperstructureStatus(data: Uint8Array): void { |
| 196 | const fbBuffer = new ByteBuffer(data); |
James Kuszmaul | dac091f | 2022-03-22 09:35:06 -0700 | [diff] [blame] | 197 | this.superstructureStatus = SuperstructureStatus.getRootAsStatus(fbBuffer); |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 200 | drawField(): void { |
| 201 | const MY_COLOR = 'red'; |
| 202 | const OTHER_COLOR = 'blue'; |
| 203 | const ctx = this.canvas.getContext('2d'); |
| 204 | // draw perimiter |
| 205 | ctx.beginPath(); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 206 | ctx.moveTo(FIELD_EDGE_X, DS_INSIDE_Y); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 207 | ctx.lineTo(DS_END_X, FIELD_SIDE_Y); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 208 | ctx.lineTo(-DS_END_X, FIELD_SIDE_Y); |
| 209 | ctx.lineTo(-FIELD_EDGE_X, DS_INSIDE_Y); |
| 210 | ctx.lineTo(-FIELD_EDGE_X, -DS_INSIDE_Y); |
| 211 | ctx.lineTo(-DS_END_X, -FIELD_SIDE_Y); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 212 | ctx.lineTo(DS_END_X, -FIELD_SIDE_Y); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 213 | ctx.lineTo(FIELD_EDGE_X, -DS_INSIDE_Y); |
| 214 | ctx.lineTo(FIELD_EDGE_X, DS_INSIDE_Y); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 215 | ctx.stroke(); |
| 216 | |
| 217 | // draw shield generator |
| 218 | ctx.beginPath(); |
| 219 | ctx.moveTo(SHIELD_BOTTOM_X, SHIELD_BOTTOM_Y); |
| 220 | ctx.lineTo(SHIELD_RIGHT_X, SHIELD_RIGHT_Y); |
| 221 | ctx.lineTo(SHIELD_TOP_X, SHIELD_TOP_Y); |
| 222 | ctx.lineTo(SHIELD_LEFT_X, SHIELD_LEFT_Y); |
| 223 | ctx.lineTo(SHIELD_BOTTOM_X, SHIELD_BOTTOM_Y); |
| 224 | ctx.moveTo(SHIELD_CENTER_TOP_X, SHIELD_CENTER_TOP_Y); |
| 225 | ctx.lineTo(SHIELD_CENTER_BOTTOM_X, SHIELD_CENTER_BOTTOM_Y); |
| 226 | ctx.stroke(); |
| 227 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 228 | this.drawHalfField(ctx, 'red'); |
| 229 | ctx.rotate(Math.PI); |
| 230 | this.drawHalfField(ctx, 'blue'); |
| 231 | ctx.rotate(Math.PI); |
| 232 | } |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 233 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 234 | drawHalfField(ctx, color: string): void { |
| 235 | // trenches |
| 236 | ctx.strokeStyle = color; |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 237 | ctx.beginPath(); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 238 | ctx.moveTo(TRENCH_X, FIELD_SIDE_Y); |
| 239 | ctx.lineTo(TRENCH_X, TRENCH_INSIDE); |
| 240 | ctx.lineTo(-TRENCH_X, TRENCH_INSIDE); |
| 241 | ctx.lineTo(-TRENCH_X, FIELD_SIDE_Y); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 242 | ctx.stroke(); |
| 243 | |
| 244 | ctx.strokeStyle = 'black'; |
| 245 | ctx.beginPath(); |
| 246 | ctx.moveTo(SPINNER_TOP_X, FIELD_SIDE_Y); |
| 247 | ctx.lineTo(SPINNER_TOP_X, TRENCH_INSIDE); |
| 248 | ctx.lineTo(SPINNER_BOTTOM_X, TRENCH_INSIDE); |
| 249 | ctx.lineTo(SPINNER_BOTTOM_X, FIELD_SIDE_Y); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 250 | ctx.stroke(); |
| 251 | |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 252 | ctx.beginPath(); |
| 253 | ctx.moveTo(INITIATION_X, FIELD_SIDE_Y); |
| 254 | ctx.lineTo(INITIATION_X, -FIELD_SIDE_Y); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 255 | ctx.stroke(); |
| 256 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 257 | // target/loading |
| 258 | ctx.strokeStyle = color; |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 259 | ctx.beginPath(); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 260 | ctx.moveTo(FIELD_EDGE_X, DS_INSIDE_Y); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 261 | ctx.lineTo(TARGET_ZONE_TIP_X, DS_INSIDE_Y - 0.5 * TARGET_ZONE_WIDTH); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 262 | ctx.lineTo(FIELD_EDGE_X, DS_INSIDE_Y - TARGET_ZONE_WIDTH); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 263 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 264 | ctx.moveTo(-FIELD_EDGE_X, DS_INSIDE_Y); |
| 265 | ctx.lineTo(-TARGET_ZONE_TIP_X, DS_INSIDE_Y - 0.5 * LOADING_ZONE_WIDTH); |
| 266 | ctx.lineTo(-FIELD_EDGE_X, DS_INSIDE_Y - LOADING_ZONE_WIDTH); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 267 | ctx.stroke(); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 268 | } |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 269 | |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 270 | drawCamera( |
| 271 | x: number, y: number, theta: number, color: string = 'blue', |
| 272 | extendLines: boolean = true): void { |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 273 | const ctx = this.canvas.getContext('2d'); |
| 274 | ctx.save(); |
| 275 | ctx.translate(x, y); |
| 276 | ctx.rotate(theta); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 277 | ctx.strokeStyle = color; |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 278 | ctx.beginPath(); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 279 | ctx.moveTo(0.5, 0.5); |
| 280 | ctx.lineTo(0, 0); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 281 | if (extendLines) { |
| 282 | ctx.lineTo(100.0, 0); |
| 283 | ctx.lineTo(0, 0); |
| 284 | } |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 285 | ctx.lineTo(0.5, -0.5); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 286 | ctx.stroke(); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 287 | ctx.beginPath(); |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 288 | ctx.arc(0, 0, 0.25, -Math.PI / 4, Math.PI / 4); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 289 | ctx.stroke(); |
| 290 | ctx.restore(); |
| 291 | } |
| 292 | |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 293 | drawRobot( |
| 294 | x: number, y: number, theta: number, turret: number|null, |
| 295 | color: string = 'blue', dashed: boolean = false, |
| 296 | extendLines: boolean = true): void { |
Alex Perry | 2124ae8 | 2020-03-07 14:19:06 -0800 | [diff] [blame] | 297 | const ctx = this.canvas.getContext('2d'); |
| 298 | ctx.save(); |
| 299 | ctx.translate(x, y); |
| 300 | ctx.rotate(theta); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 301 | ctx.strokeStyle = color; |
| 302 | if (dashed) { |
| 303 | ctx.setLineDash([0.05, 0.05]); |
| 304 | } else { |
| 305 | // Empty array = solid line. |
| 306 | ctx.setLineDash([]); |
| 307 | } |
Alex Perry | 2124ae8 | 2020-03-07 14:19:06 -0800 | [diff] [blame] | 308 | ctx.rect(-ROBOT_LENGTH / 2, -ROBOT_WIDTH / 2, ROBOT_LENGTH, ROBOT_WIDTH); |
| 309 | ctx.stroke(); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 310 | |
| 311 | // Draw line indicating which direction is forwards on the robot. |
| 312 | ctx.beginPath(); |
| 313 | ctx.moveTo(0, 0); |
| 314 | if (extendLines) { |
| 315 | ctx.lineTo(1000.0, 0); |
| 316 | } else { |
| 317 | ctx.lineTo(ROBOT_LENGTH / 2.0, 0); |
| 318 | } |
| 319 | ctx.stroke(); |
| 320 | |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 321 | if (turret) { |
| 322 | ctx.save(); |
| 323 | ctx.rotate(turret + Math.PI); |
| 324 | const turretRadius = ROBOT_WIDTH / 4.0; |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 325 | ctx.strokeStyle = 'red'; |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 326 | // Draw circle for turret. |
| 327 | ctx.beginPath(); |
| 328 | ctx.arc(0, 0, turretRadius, 0, 2.0 * Math.PI); |
| 329 | ctx.stroke(); |
| 330 | // Draw line in circle to show forwards. |
| 331 | ctx.beginPath(); |
| 332 | ctx.moveTo(0, 0); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 333 | if (extendLines) { |
| 334 | ctx.lineTo(1000.0, 0); |
| 335 | } else { |
| 336 | ctx.lineTo(turretRadius, 0); |
| 337 | } |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 338 | ctx.stroke(); |
| 339 | ctx.restore(); |
| 340 | } |
Alex Perry | 2124ae8 | 2020-03-07 14:19:06 -0800 | [diff] [blame] | 341 | ctx.restore(); |
| 342 | } |
| 343 | |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 344 | setShooter(div: HTMLElement, flywheelStatus: FlywheelControllerStatus): void { |
| 345 | const currentVelocity = flywheelStatus.angularVelocity(); |
| 346 | const goal = flywheelStatus.angularVelocityGoal(); |
| 347 | // Show it as 'near' if difference between |
| 348 | if (Math.abs(currentVelocity - goal) < 5) { |
| 349 | this.setNear(div, currentVelocity.toFixed(2)); |
| 350 | return; |
| 351 | } |
| 352 | div.classList.remove('faulted'); |
| 353 | div.classList.remove('zeroing'); |
| 354 | div.classList.remove('near'); |
| 355 | div.innerHTML = currentVelocity.toFixed(2); |
Austin Schuh | 840132b | 2021-10-17 17:40:14 -0700 | [diff] [blame] | 356 | } |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 357 | |
| 358 | setZeroing(div: HTMLElement): void { |
| 359 | div.innerHTML = 'zeroing'; |
| 360 | div.classList.remove('faulted'); |
| 361 | div.classList.add('zeroing'); |
| 362 | div.classList.remove('near'); |
Austin Schuh | 840132b | 2021-10-17 17:40:14 -0700 | [diff] [blame] | 363 | } |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 364 | |
| 365 | setEstopped(div: HTMLElement): void { |
| 366 | div.innerHTML = 'estopped'; |
| 367 | div.classList.add('faulted'); |
| 368 | div.classList.remove('zeroing'); |
| 369 | div.classList.remove('near'); |
| 370 | } |
| 371 | |
| 372 | setNear(div: HTMLElement, val: string): void { |
| 373 | div.innerHTML = val; |
| 374 | div.classList.remove('faulted'); |
| 375 | div.classList.remove('zeroing'); |
| 376 | div.classList.add('near'); |
| 377 | } |
| 378 | |
| 379 | setTargetValue( |
| 380 | div: HTMLElement, target: number, val: number, tolerance: number): void { |
| 381 | div.innerHTML = val.toFixed(4); |
| 382 | div.classList.remove('faulted'); |
| 383 | div.classList.remove('zeroing'); |
| 384 | if (Math.abs(target - val) < tolerance) { |
| 385 | div.classList.add('near'); |
| 386 | } else { |
| 387 | div.classList.remove('near'); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | setValue(div: HTMLElement, val: number): void { |
| 392 | div.innerHTML = val.toFixed(4); |
| 393 | div.classList.remove('faulted'); |
| 394 | div.classList.remove('zeroing'); |
| 395 | div.classList.remove('near'); |
Austin Schuh | 840132b | 2021-10-17 17:40:14 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 398 | draw(): void { |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 399 | this.reset(); |
| 400 | this.drawField(); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 401 | |
| 402 | // Draw the matches with debugging information from the localizer. |
| 403 | const now = Date.now() / 1000.0; |
| 404 | for (const [time, value] of this.localizerImageMatches) { |
| 405 | const age = now - time; |
| 406 | const kRemovalAge = 2.0; |
| 407 | if (age > kRemovalAge) { |
| 408 | this.localizerImageMatches.delete(time); |
| 409 | continue; |
| 410 | } |
| 411 | const ageAlpha = (kRemovalAge - age) / kRemovalAge |
| 412 | for (let i = 0; i < value.matchesLength(); i++) { |
| 413 | const imageDebug = value.matches(i); |
| 414 | const x = imageDebug.impliedRobotX(); |
| 415 | const y = imageDebug.impliedRobotY(); |
| 416 | const theta = imageDebug.impliedRobotTheta(); |
| 417 | const cameraX = imageDebug.cameraX(); |
| 418 | const cameraY = imageDebug.cameraY(); |
| 419 | const cameraTheta = imageDebug.cameraTheta(); |
| 420 | const accepted = imageDebug.accepted(); |
| 421 | // Make camera readings fade over time. |
| 422 | const alpha = Math.round(255 * ageAlpha).toString(16).padStart(2, '0'); |
| 423 | const dashed = false; |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 424 | const acceptedRgb = accepted ? '#00FF00' : '#FF0000'; |
James Kuszmaul | 286b80c | 2021-10-23 21:56:33 -0700 | [diff] [blame] | 425 | const acceptedRgba = acceptedRgb + alpha; |
| 426 | const cameraRgb = PI_COLORS[imageDebug.camera()]; |
| 427 | const cameraRgba = cameraRgb + alpha; |
| 428 | this.drawRobot(x, y, theta, null, acceptedRgba, dashed, false); |
| 429 | this.drawCamera(cameraX, cameraY, cameraTheta, cameraRgba, false); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 430 | } |
| 431 | } |
| 432 | |
| 433 | // draw cameras from ImageMatchResults directly (helpful when viewing page |
| 434 | // on the pis individually). |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 435 | for (const keyPair of this.imageMatchResult) { |
| 436 | const value = keyPair[1]; |
| 437 | for (let i = 0; i < value.cameraPosesLength(); i++) { |
| 438 | const pose = value.cameraPoses(i); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 439 | const mat = pose.fieldToCamera(); |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 440 | // Matrix layout: |
| 441 | // [0, 1, 2, 3] |
| 442 | // [4, 5, 6, 7] |
| 443 | // [8, 9, 10, 11] |
| 444 | // [12, 13, 14, 15] |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 445 | const x = mat.data(3); |
| 446 | const y = mat.data(7); |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 447 | const theta = Math.atan2(mat.data(6), mat.data(2)); |
James Kuszmaul | 286b80c | 2021-10-23 21:56:33 -0700 | [diff] [blame] | 448 | const cameraColor = (keyPair[0].length > 0) ? |
| 449 | PI_COLORS[Number(keyPair[0][3]) - 1] : |
| 450 | 'blue'; |
| 451 | this.drawCamera(x, y, theta, cameraColor); |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | |
Alex Perry | 2124ae8 | 2020-03-07 14:19:06 -0800 | [diff] [blame] | 455 | if (this.drivetrainStatus) { |
Austin Schuh | 840132b | 2021-10-17 17:40:14 -0700 | [diff] [blame] | 456 | if (!this.drivetrainStatus.zeroing().zeroed()) { |
| 457 | this.setZeroing(this.x); |
| 458 | this.setZeroing(this.y); |
| 459 | this.setZeroing(this.theta); |
| 460 | } else if (this.drivetrainStatus.zeroing().faulted()) { |
| 461 | this.setEstopped(this.x); |
| 462 | this.setEstopped(this.y); |
| 463 | this.setEstopped(this.theta); |
| 464 | } else { |
| 465 | this.setValue(this.x, this.drivetrainStatus.x()); |
| 466 | this.setValue(this.y, this.drivetrainStatus.y()); |
| 467 | this.setValue(this.theta, this.drivetrainStatus.theta()); |
| 468 | } |
| 469 | |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 470 | if (this.superstructureStatus) { |
| 471 | this.shotDistance.innerHTML = |
| 472 | this.superstructureStatus.aimer().shotDistance().toFixed(2); |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 473 | this.setShooter( |
| 474 | this.finisher, this.superstructureStatus.shooter().finisher()); |
| 475 | this.setShooter( |
| 476 | this.leftAccelerator, |
| 477 | this.superstructureStatus.shooter().acceleratorLeft()); |
| 478 | this.setShooter( |
| 479 | this.rightAccelerator, |
| 480 | this.superstructureStatus.shooter().acceleratorRight()); |
| 481 | |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 482 | if (this.superstructureStatus.aimer().aimingForInnerPort()) { |
| 483 | this.innerPort.innerHTML = 'true'; |
Austin Schuh | 146c0bc | 2021-11-07 22:33:28 -0800 | [diff] [blame] | 484 | this.outerTarget.classList.remove('targetted'); |
| 485 | this.innerTarget.classList.add('targetted'); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 486 | } else { |
| 487 | this.innerPort.innerHTML = 'false'; |
Austin Schuh | 146c0bc | 2021-11-07 22:33:28 -0800 | [diff] [blame] | 488 | this.outerTarget.classList.add('targetted'); |
| 489 | this.innerTarget.classList.remove('targetted'); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 490 | } |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 491 | |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 492 | if (!this.superstructureStatus.hood().zeroed()) { |
| 493 | this.setZeroing(this.hood); |
| 494 | } else if (this.superstructureStatus.hood().estopped()) { |
| 495 | this.setEstopped(this.hood); |
| 496 | } else { |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 497 | this.setTargetValue( |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 498 | this.hood, |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 499 | this.superstructureStatus.hood().unprofiledGoalPosition(), |
| 500 | this.superstructureStatus.hood().estimatorState().position(), |
| 501 | 1e-3); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 502 | } |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 503 | |
Austin Schuh | 146c0bc | 2021-11-07 22:33:28 -0800 | [diff] [blame] | 504 | this.ballsShot.innerHTML = |
| 505 | this.superstructureStatus.shooter().ballsShot().toString(); |
| 506 | |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 507 | if (!this.superstructureStatus.turret().zeroed()) { |
| 508 | this.setZeroing(this.turret); |
| 509 | } else if (this.superstructureStatus.turret().estopped()) { |
| 510 | this.setEstopped(this.turret); |
| 511 | } else { |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 512 | this.setTargetValue( |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 513 | this.turret, |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 514 | this.superstructureStatus.turret().unprofiledGoalPosition(), |
| 515 | this.superstructureStatus.turret().estimatorState().position(), |
| 516 | 1e-3); |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 517 | } |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 518 | |
James Kuszmaul | f75ecd6 | 2021-10-23 14:33:46 -0700 | [diff] [blame] | 519 | if (!this.superstructureStatus.intake().zeroed()) { |
| 520 | this.setZeroing(this.intake); |
| 521 | } else if (this.superstructureStatus.intake().estopped()) { |
| 522 | this.setEstopped(this.intake); |
| 523 | } else { |
| 524 | this.setValue( |
| 525 | this.intake, |
| 526 | this.superstructureStatus.intake().estimatorState().position()); |
| 527 | } |
Austin Schuh | 840132b | 2021-10-17 17:40:14 -0700 | [diff] [blame] | 528 | } |
Alex Perry | 87cc63d | 2021-10-27 21:18:42 -0700 | [diff] [blame] | 529 | |
Alex Perry | 2124ae8 | 2020-03-07 14:19:06 -0800 | [diff] [blame] | 530 | this.drawRobot( |
| 531 | this.drivetrainStatus.x(), this.drivetrainStatus.y(), |
James Kuszmaul | 5e6aa25 | 2021-08-28 22:19:29 -0700 | [diff] [blame] | 532 | this.drivetrainStatus.theta(), |
| 533 | this.superstructureStatus ? |
| 534 | this.superstructureStatus.turret().position() : |
| 535 | null); |
Alex Perry | 2124ae8 | 2020-03-07 14:19:06 -0800 | [diff] [blame] | 536 | } |
| 537 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 538 | window.requestAnimationFrame(() => this.draw()); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | reset(): void { |
| 542 | const ctx = this.canvas.getContext('2d'); |
| 543 | ctx.setTransform(1, 0, 0, 1, 0, 0); |
| 544 | const size = window.innerHeight * 0.9; |
| 545 | ctx.canvas.height = size; |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 546 | const width = size / 2 + 20; |
| 547 | ctx.canvas.width = width; |
| 548 | ctx.clearRect(0, 0, size, width); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 549 | |
Alex Perry | b49a3fb | 2020-02-29 15:26:54 -0800 | [diff] [blame] | 550 | // Translate to center of display. |
| 551 | ctx.translate(width / 2, size / 2); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 552 | // Coordinate system is: |
| 553 | // x -> forward. |
| 554 | // y -> to the left. |
| 555 | ctx.rotate(-Math.PI / 2); |
| 556 | ctx.scale(1, -1); |
Alex Perry | 5427c9a | 2020-02-15 17:43:45 -0800 | [diff] [blame] | 557 | |
| 558 | const M_TO_PX = (size - 10) / FIELD_LENGTH; |
| 559 | ctx.scale(M_TO_PX, M_TO_PX); |
| 560 | ctx.lineWidth = 1 / M_TO_PX; |
| 561 | } |
| 562 | } |