コード例 #1
0
        /// <summary>
        /// 整车控制器1 驱动信息
        /// ID:0x0C61D1D0
        /// 波特率:250Kbps
        /// 数据长度:8bytes
        /// 周期:10ms
        /// </summary>
        CanStandardData ScmEvcu1ToBytes(Scm_EVCU1 scmEvcu1)
        {
            CanStandardData scmCanByte = new CanStandardData();

            scmCanByte.canId    = Scm_EVCU1.canId;
            scmCanByte.baudrate = Scm_EVCU1.baudrate; //250K
            scmCanByte.datas    = new byte[8];        //数据长度为8

            //byte0
            scmCanByte.datas[0] = (byte)(Convert.ToByte(scmEvcu1.isg_ctrl_ena_dmd_sd) +        //电机使能指令,分辨率1,偏移量0,范围0~2,byte0,bit0,1,2bits,00无效,01有效,10清故障
                                         (Convert.ToByte(scmEvcu1.isg_run_dir_dmd_sd) << 2) +  //电机运行方向,分辨率1,偏移量0,范围0~2,byte0,bit2,3,2bits 00停止,01正转,10反转,从轴往后盖看,顺时针为正转
                                         (Convert.ToByte(scmEvcu1.isg_ctrl_mod_dmd_sd) << 4)); //电机控制模式,分辨率1,偏移量0,默认值1,4bits,00自由转,01转速控制,02扭矩控制,11主动放电

            //byte1,byte2,电机需求扭矩/电机扭矩限制,6bits,偏移量-2000,低位在前,范围-2000-2000,默认值-2000,分辨率1
            scmCanByte.datas[1] = Convert.ToByte((scmEvcu1.isg_tq_dmd_sd + 2000) & 0xff);        //低位
            scmCanByte.datas[2] = Convert.ToByte(((scmEvcu1.isg_tq_dmd_sd + 2000) >> 8) & 0xff); //高位

            //byte3,byte4,电机转速扭矩/电机转速限制,6bits,偏移量-12000,低位在前,范围-12000-12000,默认值-12000,分辨率1
            scmCanByte.datas[3] = Convert.ToByte((scmEvcu1.isg_spd_dmd_sd + 12000) & 0xff);        //低位
            scmCanByte.datas[4] = Convert.ToByte(((scmEvcu1.isg_spd_dmd_sd + 12000) >> 8) & 0xff); //高位


            //byte 7/6/5 保留

            return(scmCanByte);
        }
コード例 #2
0
        public override AbstractMotorControl.ScmCanSendMsg EcuClearMcuFault()
        {
            ScmCanSendMsg scmSendMsg = new ScmCanSendMsg();

            Scm_EVCU1 scmEvcu1 = new Scm_EVCU1();

            scmEvcu1.isg_ctrl_ena_dmd_sd = 0x02; //清故障
            scmEvcu1.isg_ctrl_mod_dmd_sd = 0x00;
            scmEvcu1.isg_run_dir_dmd_sd  = 0x00;
            scmEvcu1.isg_spd_dmd_sd      = 0;
            scmEvcu1.isg_tq_dmd_sd       = 0;

            CanStandardData canData = ScmEvcu1ToBytes(scmEvcu1);

            scmSendMsg.canId    = canData.canId;
            scmSendMsg.baudrate = canData.baudrate;
            scmSendMsg.datas    = canData.datas;

            return(scmSendMsg);
        }
コード例 #3
0
        /// <summary>
        /// 发送命令给电控
        /// 00备用,01转速,02转矩,03放电
        /// </summary>
        /// <param name="scmSendData"></param>
        /// <returns></returns>
        public override List <ScmCanSendMsg> TransformEcuSendData(uint canIndex, Ecm_WorkMode cmdType, short data, uint motorIndex = 0)
        {
            List <ScmCanSendMsg> canSendDatas = new List <ScmCanSendMsg>();

            Scm_EVCU1 scmEvcu1 = new Scm_EVCU1();

            ScmCanSendMsg canSendData = new ScmCanSendMsg();

            canSendData.FeedBkMtclMode = cmdType;

            string strCmdDetail = string.Empty; //命令解析字符串信息

            AbstractMotorControl.Ecm_Gear gear; //0空挡,1前进,2后退
            if (data > 0)
            {
                gear = AbstractMotorControl.Ecm_Gear.DriveGear;
            }
            else if (data < 0)
            {
                gear = AbstractMotorControl.Ecm_Gear.ReverseGear;
            }
            else
            {
                gear = AbstractMotorControl.Ecm_Gear.NeutralGear;
            }

            switch (gear)
            {
            case Ecm_Gear.NeutralGear:
                scmEvcu1.isg_run_dir_dmd_sd = 0x00;
                strCmdDetail = "空挡" + "\r\n";
                break;

            case Ecm_Gear.DriveGear:
                scmEvcu1.isg_run_dir_dmd_sd = 0x01;
                strCmdDetail = "D档" + "\r\n";
                break;

            case Ecm_Gear.ReverseGear:
                scmEvcu1.isg_run_dir_dmd_sd = 0x02;
                strCmdDetail = "倒档" + "\r\n";
                break;

            case Ecm_Gear.ErrorGear:
                scmEvcu1.isg_run_dir_dmd_sd = 0x03;
                strCmdDetail = "错误" + "\r\n";
                break;

            default: scmEvcu1.isg_run_dir_dmd_sd = 0x00; break;
            }

            //电机转速模式设定
            scmEvcu1.isg_ctrl_ena_dmd_sd = 0x00; //mcu使能


            switch (cmdType)
            {
            case Ecm_WorkMode.None:                  //备用
                scmEvcu1.isg_ctrl_mod_dmd_sd = 0x00; //控制模式
                strCmdDetail += "备用" + "\r\n";
                break;

            case Ecm_WorkMode.SpeedMode:             //转速模式
            {
                scmEvcu1.isg_spd_dmd_sd      = data; //偏移12000,0表示-12000
                canSendData.FeedBkMotorSpeed = data;
                scmEvcu1.isg_ctrl_ena_dmd_sd = 0x01; //mcu使能
                scmEvcu1.isg_ctrl_mod_dmd_sd = 0x01; //控制模式
                strCmdDetail += "转速命令:" + data.ToString() + "\r\n";
                break;
            }

            case Ecm_WorkMode.TorqueMode:             //转矩模式
            {
                scmEvcu1.isg_tq_dmd_sd        = data; //偏移2000,0表示-2000
                canSendData.FeedBkMotorTorque = data;
                scmEvcu1.isg_ctrl_ena_dmd_sd  = 0x01; //mcu使能
                scmEvcu1.isg_ctrl_mod_dmd_sd  = 0x02; //控制模式
                strCmdDetail += "扭矩命令:" + data.ToString() + "\r\n";
                break;
            }

            case Ecm_WorkMode.DisCharging:           //放电模式
                scmEvcu1.isg_ctrl_ena_dmd_sd = 0x01; //mcu使能
                scmEvcu1.isg_ctrl_mod_dmd_sd = 0x03; //控制模式
                strCmdDetail += "放电" + "\r\n";
                break;

            default: scmEvcu1.isg_ctrl_mod_dmd_sd = 0x00; break;
            }
            CanStandardData canData = ScmEvcu1ToBytes(scmEvcu1);

            canSendData.canId    = canData.canId;
            canSendData.baudrate = canData.baudrate;
            canSendData.datas    = canData.datas;

            canSendData.canIndex = canIndex;

            canSendData.cmdDetail = strCmdDetail;

            canSendDatas.Add(canSendData);

            return(canSendDatas);
        }