CalibrationInfo.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using TeamAAS.Robot.Models;
  6. using TeamAAS.Robot.Models.Robot;
  7. using TeamAAS.Vision.Calibration.Enums;
  8. namespace TeamAAS.Vision.Calibration.Models
  9. {
  10. /// <summary>
  11. /// 一次标定的完整配置与结果。
  12. /// 引擎无关:视觉工具以 <see cref="VisionTool"/>(运行时句柄,不序列化)
  13. /// 与 <see cref="VisionToolRef"/>(持久化引用,如 .vpp 路径)表示,
  14. /// 具体由当前视觉引擎(VisionPro/VM/Halcon)解释。
  15. /// </summary>
  16. [JsonObject(MemberSerialization.OptOut)]
  17. public class CalibrationInfo : TeamAAS.BindableBase
  18. {
  19. private bool _IsCreate;
  20. /// <summary>正在创建(尚未持久化)。</summary>
  21. [JsonIgnore]
  22. public bool IsCreate
  23. {
  24. get { return _IsCreate; }
  25. set { SetProperty(ref _IsCreate, value); }
  26. }
  27. private Guid _Id;
  28. public Guid Id
  29. {
  30. get { return _Id; }
  31. set { SetProperty(ref _Id, value); }
  32. }
  33. private int _Index;
  34. /// <summary>编号。</summary>
  35. public int Index
  36. {
  37. get { return _Index; }
  38. set { SetProperty(ref _Index, value); }
  39. }
  40. private string _Name;
  41. /// <summary>校准的名称。</summary>
  42. public string Name
  43. {
  44. get { return _Name; }
  45. set { SetProperty(ref _Name, value); }
  46. }
  47. private DateTime _DateTime;
  48. public DateTime DateTime
  49. {
  50. get { return _DateTime; }
  51. set { SetProperty(ref _DateTime, value); }
  52. }
  53. private string _CameraName;
  54. /// <summary>相机名称。</summary>
  55. public string CameraName
  56. {
  57. get { return _CameraName; }
  58. set { SetProperty(ref _CameraName, value); }
  59. }
  60. private Guid _CameraID;
  61. /// <summary>相机 ID。</summary>
  62. public Guid CameraID
  63. {
  64. get { return _CameraID; }
  65. set { SetProperty(ref _CameraID, value); }
  66. }
  67. private Guid _RobotId;
  68. /// <summary>机器人 ID。</summary>
  69. public Guid RobotId
  70. {
  71. get { return _RobotId; }
  72. set { SetProperty(ref _RobotId, value); }
  73. }
  74. private Guid _FeederId;
  75. /// <summary>Feeder(喂料器/光源)ID。</summary>
  76. public Guid FeederId
  77. {
  78. get { return _FeederId; }
  79. set { SetProperty(ref _FeederId, value); }
  80. }
  81. private CameraMount _CameraMount;
  82. /// <summary>相机安装方式。</summary>
  83. public CameraMount CameraMount
  84. {
  85. get { return _CameraMount; }
  86. set { SetProperty(ref _CameraMount, value); }
  87. }
  88. private PickInfo _Pick;
  89. /// <summary>取料方式(吸取/夹取 + IO 点位)。</summary>
  90. public PickInfo Pick
  91. {
  92. get { return _Pick; }
  93. set { SetProperty(ref _Pick, value); }
  94. }
  95. private int _Brightness;
  96. /// <summary>光源亮度。</summary>
  97. public int Brightness
  98. {
  99. get { return _Brightness; }
  100. set { SetProperty(ref _Brightness, value); }
  101. }
  102. private float _ExposureTime;
  103. /// <summary>相机曝光时间。</summary>
  104. public float ExposureTime
  105. {
  106. get { return _ExposureTime; }
  107. set { SetProperty(ref _ExposureTime, value); }
  108. }
  109. private float _Gain;
  110. /// <summary>相机增益。</summary>
  111. public float Gain
  112. {
  113. get { return _Gain; }
  114. set { SetProperty(ref _Gain, value); }
  115. }
  116. private CalibTechP0Mode _CalibTechP0Mode;
  117. /// <summary>移动相机中心作为 P0 还是手动示教 P0。</summary>
  118. public CalibTechP0Mode CalibTechP0Mode
  119. {
  120. get { return _CalibTechP0Mode; }
  121. set { SetProperty(ref _CalibTechP0Mode, value); }
  122. }
  123. private RPoint _CenterPoint;
  124. /// <summary>中心点。</summary>
  125. public RPoint CenterPoint
  126. {
  127. get { return _CenterPoint; }
  128. set { SetProperty(ref _CenterPoint, value); }
  129. }
  130. private RPoint _HomePoint;
  131. /// <summary>待机点。</summary>
  132. public RPoint HomePoint
  133. {
  134. get { return _HomePoint; }
  135. set { SetProperty(ref _HomePoint, value); }
  136. }
  137. private double _Width;
  138. /// <summary>机器人移动的范围 X。</summary>
  139. public double Width
  140. {
  141. get { return _Width; }
  142. set { SetProperty(ref _Width, value); }
  143. }
  144. private double _Height;
  145. /// <summary>机器人移动的范围 Y。</summary>
  146. public double Height
  147. {
  148. get { return _Height; }
  149. set { SetProperty(ref _Height, value); }
  150. }
  151. private double _Angle = 180;
  152. /// <summary>机器人移动的范围 U(旋转标定用角度)。</summary>
  153. public double Angle
  154. {
  155. get { return _Angle; }
  156. set { SetProperty(ref _Angle, value); }
  157. }
  158. private RobotTool _Tool;
  159. /// <summary>工具坐标(TCP)。</summary>
  160. public RobotTool Tool
  161. {
  162. get { return _Tool; }
  163. set { SetProperty(ref _Tool, value); }
  164. }
  165. private RobotArm _Arm;
  166. /// <summary>Arm。</summary>
  167. public RobotArm Arm
  168. {
  169. get { return _Arm; }
  170. set { SetProperty(ref _Arm, value); }
  171. }
  172. private int _Speed;
  173. public int Speed
  174. {
  175. get { return _Speed; }
  176. set { SetProperty(ref _Speed, value); }
  177. }
  178. private int _Accel;
  179. public int Accel
  180. {
  181. get { return _Accel; }
  182. set { SetProperty(ref _Accel, value); }
  183. }
  184. private int _WaitPhoto;
  185. public int WaitPhoto
  186. {
  187. get { return _WaitPhoto; }
  188. set { SetProperty(ref _WaitPhoto, value); }
  189. }
  190. private int _WaitSuction;
  191. /// <summary>吸真空延时。</summary>
  192. public int WaitSuction
  193. {
  194. get { return _WaitSuction; }
  195. set { SetProperty(ref _WaitSuction, value); }
  196. }
  197. private int _WaitBlow;
  198. /// <summary>破真空延时。</summary>
  199. public int WaitBlow
  200. {
  201. get { return _WaitBlow; }
  202. set { SetProperty(ref _WaitBlow, value); }
  203. }
  204. private bool _Power;
  205. public bool Power
  206. {
  207. get { return _Power; }
  208. set { SetProperty(ref _Power, value); }
  209. }
  210. private bool _IsDistortionCorrection;
  211. /// <summary>是否进行畸变校正。</summary>
  212. public bool IsDistortionCorrection
  213. {
  214. get { return _IsDistortionCorrection; }
  215. set { SetProperty(ref _IsDistortionCorrection, value); }
  216. }
  217. private RPoint _MarkPoint;
  218. /// <summary>特征点的坐标(移动相机模式下记录标定块绝对坐标)。</summary>
  219. public RPoint MarkPoint
  220. {
  221. get { return _MarkPoint; }
  222. set { SetProperty(ref _MarkPoint, value); }
  223. }
  224. private ObservableCollection<RobotPixelPoint> _CalibPoints;
  225. /// <summary>9 点校准点(机器人坐标与像素坐标对应)。</summary>
  226. public ObservableCollection<RobotPixelPoint> CalibPoints
  227. {
  228. get { return _CalibPoints; }
  229. set { SetProperty(ref _CalibPoints, value); }
  230. }
  231. private double[,] _RobotCameraRotationMatrix;
  232. /// <summary>机器人与相机之间的旋转矩阵。</summary>
  233. public double[,] RobotCameraRotationMatrix
  234. {
  235. get { return _RobotCameraRotationMatrix; }
  236. set { SetProperty(ref _RobotCameraRotationMatrix, value); }
  237. }
  238. private double _PixelScaleX;
  239. /// <summary>图像 X 方向像素与毫米缩放系数,mm/pixel。</summary>
  240. public double PixelScaleX
  241. {
  242. get { return _PixelScaleX; }
  243. set { SetProperty(ref _PixelScaleX, value); }
  244. }
  245. private double _PixelScaleY;
  246. /// <summary>图像 Y 方向像素与毫米缩放系数,mm/pixel。</summary>
  247. public double PixelScaleY
  248. {
  249. get { return _PixelScaleY; }
  250. set { SetProperty(ref _PixelScaleY, value); }
  251. }
  252. private double[,] _AffineTransformationMaterial;
  253. /// <summary>仿射变换 2*3 矩阵(像素 → 机器人)。</summary>
  254. public double[,] AffineTransformationMaterial
  255. {
  256. get { return _AffineTransformationMaterial; }
  257. set { SetProperty(ref _AffineTransformationMaterial, value); }
  258. }
  259. private CalibrationResult _CalibrationResult;
  260. /// <summary>校准结果。</summary>
  261. public CalibrationResult CalibrationResult
  262. {
  263. get { return _CalibrationResult; }
  264. set { SetProperty(ref _CalibrationResult, value); }
  265. }
  266. private CalibrationTestResult _CalibrationTestResult;
  267. /// <summary>校准验证结果。</summary>
  268. public CalibrationTestResult CalibrationTestResult
  269. {
  270. get { return _CalibrationTestResult; }
  271. set { SetProperty(ref _CalibrationTestResult, value); }
  272. }
  273. private string _VisionToolRef;
  274. /// <summary>视觉标定工具的持久化引用(如 .vpp 路径),随引擎解释。</summary>
  275. public string VisionToolRef
  276. {
  277. get { return _VisionToolRef; }
  278. set { SetProperty(ref _VisionToolRef, value); }
  279. }
  280. /// <summary>视觉标定工具的运行时句柄(引擎私有对象,不序列化)。</summary>
  281. [JsonIgnore]
  282. public object VisionTool { get; set; }
  283. /// <summary>畸变校正工具的运行时句柄(引擎私有对象,不序列化)。</summary>
  284. [JsonIgnore]
  285. public object DistortionTool { get; set; }
  286. public CalibrationInfo Clone()
  287. {
  288. return new CalibrationInfo
  289. {
  290. Id = this.Id,
  291. Index = this.Index,
  292. Name = this.Name,
  293. DateTime = this.DateTime,
  294. CameraName = this.CameraName,
  295. CameraID = this.CameraID,
  296. RobotId = this.RobotId,
  297. FeederId = this.FeederId,
  298. CameraMount = this.CameraMount,
  299. Pick = this.Pick?.Clone(),
  300. Brightness = this.Brightness,
  301. ExposureTime = this.ExposureTime,
  302. Gain = this.Gain,
  303. CalibTechP0Mode = this.CalibTechP0Mode,
  304. CenterPoint = this.CenterPoint?.Clone(),
  305. HomePoint = this.HomePoint?.Clone(),
  306. Width = this.Width,
  307. Height = this.Height,
  308. Angle = this.Angle,
  309. Tool = this.Tool?.Copy(),
  310. Arm = this.Arm,
  311. Speed = this.Speed,
  312. Accel = this.Accel,
  313. WaitPhoto = this.WaitPhoto,
  314. WaitSuction = this.WaitSuction,
  315. WaitBlow = this.WaitBlow,
  316. Power = this.Power,
  317. IsDistortionCorrection = this.IsDistortionCorrection,
  318. MarkPoint = this.MarkPoint?.Clone(),
  319. CalibPoints = new ObservableCollection<RobotPixelPoint>((this.CalibPoints ?? new ObservableCollection<RobotPixelPoint>()).Select(p => p.Clone())),
  320. RobotCameraRotationMatrix = (double[,])this.RobotCameraRotationMatrix?.Clone(),
  321. PixelScaleX = this.PixelScaleX,
  322. PixelScaleY = this.PixelScaleY,
  323. AffineTransformationMaterial = (double[,])this.AffineTransformationMaterial?.Clone(),
  324. VisionToolRef = this.VisionToolRef,
  325. };
  326. }
  327. }
  328. }