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