private void InitSingleNodeReg(byte n) { NodeMaster.SetNodeReg(n, new string[] { "magnet_freq", "magnet_amp", "magnet_time", "motor_speed", "cs_filter" }, new UInt32[] { UInt32.Parse(nodes_config[n].Current.Element("magnet_freq").Value), UInt32.Parse(nodes_config[n].Current.Element("magnet_amp").Value), UInt32.Parse(nodes_config[n].Current.Element("magnet_time").Value), UInt32.Parse(nodes_config[n].Current.Element("cs_filter").Value), UInt32.Parse(nodes_config[n].Current.Element("motor_speed").Value) }); NodeMaster.SetNodeReg(n, new string[] { "cs_gain_wordrate", "delay_f", "delay_w" }, new UInt32[] { UInt32.Parse(nodes_config[n].Current.Element("cs_gain_wordrate").Value), UInt32.Parse(nodes_config[n].Current.Element("delay_f").Value), UInt32.Parse(nodes_config[n].Current.Element("delay_w").Value) }); NodeMaster.SetNodeReg(n, new string[] { "delay_s", "open_s", "open_w", "target_weight" }, new UInt32[] { UInt32.Parse(nodes_config[n].Current.Element("delay_s").Value), UInt32.Parse(nodes_config[n].Current.Element("open_s").Value), UInt32.Parse(nodes_config[n].Current.Element("open_w").Value), UInt32.Parse(nodes_config[n].Current.Element("target_weight").Value) }); }
//update weight of each node based on current setting public void UpdateEachNodeTarget() { if (curr_cfg.target_comb <= 1) { foreach (byte naddr in weight_nodes) { NodeMaster.SetNodeReg(naddr, new string[] { "target_weight" }, new UInt32[] { 0 }); } return; } double avg = curr_cfg.target / curr_cfg.target_comb; double step = avg * NodeAgent.VAR_RANGE / weight_nodes.Count; // +/-15% variation of avg , example: for 30, step will be 0.9 gram foreach (byte naddr in weight_nodes) { if ((NodeMaster.GetStatus(naddr) == NodeStatus.ST_IDLE)) { double per = avg + (Int32.Parse(naddr.ToString()) - (weight_nodes.Count) / 2) * step; NodeMaster.SetNodeReg(naddr, new string[] { "target_weight" }, new UInt32[] { Convert.ToUInt32(per) }); } } }