// aim targets the selected target, draws the linesh void aim() { RobotLocator rl = new RobotLocator(_particlefinder); // string targetSelection = _smartdashboard.GetString("targetSelection"); string targetSelection = "mid"; Particle target = null; // targetSelection = "right"; switch (targetSelection) { case "left": target = rl.targetleft; break; case "right": target = rl.targetright; break; case "mid": default: target = rl.targetmid; break; } // adjustTrim(); if (rl.targetmid != null) { _targetmid.Width = rl.targetmid.width; _targetmid.Height = rl.targetmid.height; Canvas.SetTop(_targetmid, rl.targetmid.top); Canvas.SetLeft(_targetmid, rl.targetmid.left); } else { _targetmid.Width = 0; _targetmid.Height = 0; } if (rl.targetleft != null) { _targetleft.Width = rl.targetleft.width; _targetleft.Height = rl.targetleft.height; Canvas.SetTop(_targetleft, rl.targetleft.top); Canvas.SetLeft(_targetleft, rl.targetleft.left); } else { _targetleft.Width = 0; _targetleft.Height = 0; } if (rl.targetright != null) { _targetright.Width = rl.targetright.width; _targetright.Height = rl.targetright.height; Canvas.SetTop(_targetright, rl.targetright.top); Canvas.SetLeft(_targetright, rl.targetright.left); } else { _targetright.Width = 0; _targetright.Height = 0; } int imgcenter = (rl.imgwidth / 2); double targetcenter = (target != null) ? target.centerx : 0; _targetoffset = (int)Math.Round(targetcenter - imgcenter); // we draw the lines to reflect what you want to see in the image _targetcenter.X1 = _targetcenter.X2 = (imgcenter + _targetoffset); _cameracenter.X1 = _cameracenter.X2 = imgcenter + _trim; _targetoffset -= _trim; if (target != null) { // _smartdashboard.SetDouble("offset", (double)_targetoffset); // _smartdashboard.SetDouble("width", (double)rl.targetmid.width); // _smartdashboard.SetDouble("height", (double)rl.targetmid.height); } else { // dang, no target // _smartdashboard.SetDouble("offset", (double)320); // _smartdashboard.SetDouble("width", (double)0); // _smartdashboard.SetDouble("height", (double)0); } // _smartdashboard.SetDouble("frameNum", (double)_framecount); string dir = string.Empty; if (_targetoffset < 0) dir = "left"; else if (_targetoffset > 0) dir = "right"; else dir = "centered"; _direction.Text = string.Format(" target {0} ({1})", _targetoffset.ToString(), dir); }
// aim targets the selected target, draws the linesh void aim() { RobotLocator rl = new RobotLocator(_particlefinder); // string targetSelection = _smartdashboard.GetString("targetSelection"); string targetSelection = "mid"; Particle target = null; // targetSelection = "right"; switch (targetSelection) { case "left": target = rl.targetleft; break; case "right": target = rl.targetright; break; case "mid": default: target = rl.targetmid; break; } // adjustTrim(); if (rl.targetmid != null) { _targetmid.Width = rl.targetmid.width; _targetmid.Height = rl.targetmid.height; Canvas.SetTop(_targetmid, rl.targetmid.top); Canvas.SetLeft(_targetmid, rl.targetmid.left); } else { _targetmid.Width = 0; _targetmid.Height = 0; } if (rl.targetleft != null) { _targetleft.Width = rl.targetleft.width; _targetleft.Height = rl.targetleft.height; Canvas.SetTop(_targetleft, rl.targetleft.top); Canvas.SetLeft(_targetleft, rl.targetleft.left); } else { _targetleft.Width = 0; _targetleft.Height = 0; } if (rl.targetright != null) { _targetright.Width = rl.targetright.width; _targetright.Height = rl.targetright.height; Canvas.SetTop(_targetright, rl.targetright.top); Canvas.SetLeft(_targetright, rl.targetright.left); } else { _targetright.Width = 0; _targetright.Height = 0; } int imgcenter = (rl.imgwidth / 2); double targetcenter = (target != null) ? target.centerx : 0; _targetoffset = (int)Math.Round(targetcenter - imgcenter); // we draw the lines to reflect what you want to see in the image _targetcenter.X1 = _targetcenter.X2 = (imgcenter + _targetoffset); _cameracenter.X1 = _cameracenter.X2 = imgcenter + _trim; _targetoffset -= _trim; if (target != null) { // _smartdashboard.SetDouble("offset", (double)_targetoffset); // _smartdashboard.SetDouble("width", (double)rl.targetmid.width); // _smartdashboard.SetDouble("height", (double)rl.targetmid.height); } else { // dang, no target // _smartdashboard.SetDouble("offset", (double)320); // _smartdashboard.SetDouble("width", (double)0); // _smartdashboard.SetDouble("height", (double)0); } // _smartdashboard.SetDouble("frameNum", (double)_framecount); string dir = string.Empty; if (_targetoffset < 0) { dir = "left"; } else if (_targetoffset > 0) { dir = "right"; } else { dir = "centered"; } _direction.Text = string.Format(" target {0} ({1})", _targetoffset.ToString(), dir); }