MovableLifterArm.c 12.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
#include "MovableLifterArm.h"

#if P_SETUP_PLATFORM_TYPE == 1
//参数初始化
void initPlaformParam(void)
{
    Y9(0); // 关闭agv自动充电触点

    Y10(0); //默认伸出挡块

    Y11(1); //供电

    //	Y12(1);//打开光圈

    agv.Command.standSiteID = 1;

    agv.Command.Au_Hand = 1;

    agv.Public.i_UpdatePathSig = 1;

    DriverMotor1.Command.speedSlope 	= 1;
    DriverMotor2.Command.speedSlope		= 1;
    DriverLifter1.Command.speedSlope 	= 3;
    DriverShifter1.Command.speedSlope = 3;
    DriverPusher1.Command.speedSlope 	= 3;

    agv.Parameter.SetLift1Height = -290;
    agv.Parameter.TargerPusherPos = -95;

		#if P_SETUP_SINGLE_PLAYER == 0 //不开启单机测试
		SetAlarm(0x0040);
		#endif
}

void lifterRunManu(DriverStruct *Motor)
{
    if (agv.Command.HandLiftState == 1)
    {
        Motor->Command.speed = agv.Parameter.LiftSpeed;
    }
    else if (agv.Command.HandLiftState == 2)
    {
        Motor->Command.speed = -agv.Parameter.LiftSpeed;
    }
    else
    {
        Motor->Command.speed = 0;
    }
    if ((Motor->Public.encoderPose < LIFTMIN && Motor->Command.speed < 0) || (Motor->Public.encoderPose > LIFTMAX && Motor->Command.speed > 0))
    {
        Motor->Command.speed = 0;
    }
}

void lifterRunAuto(DriverStruct *Motor, float LiftOffsetBias) //3750  -4500
{
    if (LiftOffsetBias > QR_BIAS_MIN)
    {
        if (LiftOffsetBias >= 0.1)
        {
            Motor->Command.speed = -agv.Parameter.LiftSpeed;
        }
        else
        {
            Motor->Command.speed = mapping(LiftOffsetBias, 0, 0.1, -200, -(float)agv.Parameter.LiftSpeed);
        }
    }
    else if (LiftOffsetBias < -QR_BIAS_MIN)
    {
        if (LiftOffsetBias <= -0.1)
        {
            Motor->Command.speed = agv.Parameter.LiftSpeed;
        }
        else
        {
            Motor->Command.speed = mapping(LiftOffsetBias, 0, -0.1, 200, (float)agv.Parameter.LiftSpeed);
        }
    }
    else
        Motor->Command.speed = 0;

    if ((Motor->Public.encoderPose < LIFTMIN && Motor->Command.speed < 0) || (Motor->Public.encoderPose > LIFTMAX && Motor->Command.speed > 0))
    {
        Motor->Command.speed = 0;
    }
}

void shifterRunManu(DriverStruct *Motor)
{
    if (agv.Command.HandShiftState == 1)
    {
        Motor->Command.speed = agv.Parameter.ShiftSpeed;
    }
    else if (agv.Command.HandShiftState == 2)
    {
        Motor->Command.speed = -agv.Parameter.ShiftSpeed;
    }
    else
    {
        Motor->Command.speed = 0;
    }
    if ((Motor->Public.encoderPose < SHIFTMIN && Motor->Command.speed < 0) || (Motor->Public.encoderPose > SHIFTMAX && Motor->Command.speed > 0))
    {
        Motor->Command.speed = 0;
    }
}

void shifterRunAuto(DriverStruct *Motor, float ShiftOffetBias) // 1850 -750
{
    if (ShiftOffetBias > QR_BIAS_MIN)
    {
        if (ShiftOffetBias >= 0.1)
        {
            Motor->Command.speed = -agv.Parameter.ShiftSpeed;
        }
        else
        {
            Motor->Command.speed = mapping(ShiftOffetBias, 0, 0.1, -400, -(float)agv.Parameter.ShiftSpeed);
        }
    }
    else if (ShiftOffetBias < -QR_BIAS_MIN)
    {
        if (ShiftOffetBias <= -0.1)
        {
            Motor->Command.speed = agv.Parameter.ShiftSpeed;
        }
        else
        {
            Motor->Command.speed = mapping(ShiftOffetBias, 0, -0.1, 400, (float)agv.Parameter.ShiftSpeed);
        }
    }
    else
        Motor->Command.speed = 0;

    if ((Motor->Public.encoderPose < SHIFTMIN && Motor->Command.speed < 0) || (Motor->Public.encoderPose > SHIFTMAX && Motor->Command.speed > 0))
    {
        Motor->Command.speed = 0;
    }
}

void pusherRunManu(DriverStruct *Motor)
{
    if (agv.Command.HandPushState == 1)
    {
        Motor->Command.speed = agv.Parameter.PushSpeed;
    }
    else if (agv.Command.HandPushState == 2)
    {
        Motor->Command.speed = -agv.Parameter.PushSpeed;
    }
    else
    {
        Motor->Command.speed = 0;
    }
    if ((Motor->Public.encoderPose > agv.Parameter.LimitPusherPos && Motor->Command.speed > 0) || (agv.Public.i_Push1_Origain && Motor->Command.speed < 0))
    {
        Motor->Command.speed = 0;
    }
}

void pusherRunAuto(DriverStruct *Motor) // -1200  4000
{
    if (abs(Motor->Public.encoderPose - agv.Parameter.TargerPusherPos) < 5)
    {
        Motor->Command.speed = 0;
    }
    else if (Motor->Public.encoderPose - agv.Parameter.TargerPusherPos < 0) //实际位置减目标位置
    {
        Motor->Command.speed = agv.Parameter.PushSpeed;
    }
    else if (Motor->Public.encoderPose - agv.Parameter.TargerPusherPos > 0)
    {
        Motor->Command.speed = -agv.Parameter.PushSpeed;
    }
    //安全限制,不能超出范围
    if ((Motor->Public.encoderPose > agv.Parameter.LimitPusherPos && Motor->Command.speed > 0) || (agv.Public.i_Push1_Origain && Motor->Command.speed < 0)) //761
    {
        Motor->Command.speed = 0;
    }
}

void returnZeroPoint(int TargetHight) //悬臂轴回原点
{
    //平移
    if (DriverShifter1.Public.encoderPose < 19 && !agv.Public.i_Shift1_Origin) //实际位置减目标位置
    {
        DriverShifter1.Command.speed = agv.Parameter.ShiftSpeed;
    }
    else if (DriverShifter1.Public.encoderPose > 19 && !agv.Public.i_Shift1_Origin)
    {
        DriverShifter1.Command.speed = -agv.Parameter.ShiftSpeed;
    }
    else
        DriverShifter1.Command.speed = 0;

    if ((DriverShifter1.Public.encoderPose < -47 && DriverShifter1.Command.speed < 0) || (DriverShifter1.Public.encoderPose > 52 && DriverShifter1.Command.speed > 0))
    {
        DriverShifter1.Command.speed = 0;
    }
    //举升
    if (abs(DriverLifter1.Public.encoderPose - TargetHight) < 5) //达到目标位置
    {
        DriverLifter1.Command.speed = 0;
    }
    else if (DriverLifter1.Public.encoderPose - TargetHight < 0) //实际位置减目标位置,小于不止5
    {
        DriverLifter1.Command.speed = agv.Parameter.LiftSpeed;
    }
    else if (DriverLifter1.Public.encoderPose - TargetHight > 0)
    {
        DriverLifter1.Command.speed = -agv.Parameter.LiftSpeed;
    }
    if ((DriverLifter1.Public.encoderPose < LIFTMIN && DriverLifter1.Command.speed < 0) || (DriverLifter1.Public.encoderPose > LIFTMAX && DriverLifter1.Command.speed > 0))
    {
        DriverLifter1.Command.speed = 0;
    }
}

void platformControlManual() //悬臂轴点动控制
{
    lifterRunManu(&DriverLifter1); //点动举升

    shifterRunManu(&DriverShifter1); //点动移轴

    pusherRunManu(&DriverPusher1); //点动推杆
}

extern int QRDataFlag;
void platformControlAuto() //悬臂轴自动对接处理
{
    static int LastTime = 0, LastTime2 = 0;

    static u8 LastQRDataFlag = 0;

    if (agv.Command.LightStopSig == 1) //光电停车对接信号
    {
        if (LastQRDataFlag == 0 && QRDataFlag == 1)
        {
            agv.Public.i_QRCodeOKFlag = 1;
        }
        LastQRDataFlag = QRDataFlag;

        Y12(1); //打开光圈

        allDriverEnable = true; //如果开启光电对接,不关使能

        lifterRunAuto(&DriverLifter1, agv.Public.QR_YbiasFromros); //根据二维码反馈偏移值,举升自动纠偏,

        shifterRunAuto(&DriverShifter1, agv.Public.QR_XbiasFromros); //根据二维码反馈偏移值,移轴自动纠偏

        //自动对接未扫到二维码,距离终点300MM停车,延时1S
        if (navi.Public.VerticalDistanceAgvToTARGET < 100 && agv.Public.i_QRCodeOKFlag == 0)
        {
            if (agv.Public.SystemTime - LastTime > 1000)
            {
                agv.Command.SetBaseSpeed = 0;

                agv.Command.SetBaseSpeed = 0;

                //				LED_color(LED_yellow, 0);//黄灯常亮
            }
        }
        else
            LastTime = agv.Public.SystemTime;

        //距离对接工位10CM以内,上下左右偏差大于10MM,或者车身角度偏差太大   停车
        if (navi.Public.VerticalDistanceAgvToTARGET < 100 && (fabs(agv.Public.QR_XbiasFromros) > 0.010 || fabs(agv.Public.QR_YbiasFromros) > 0.010 || fabs(navi.Public.AngleDifference) > 0.015))
        {
            agv.Command.SetBaseSpeed = 0;

            agv.Command.SetBaseSpeed = 0;

            //			LED_color(LED_yellow, 0);//黄灯常亮
        }

        //极限触发,二维码偏移量过大  1,左极限触发,偏移量大于0,不能向左移  停车
        //		if((Driver_PINGYI_motor_first.ActualPos <= -760&&AGVStatus.QR_XbiasFromros > 0.005)
        //			||(Driver_PINGYI_motor_first.ActualPos >= 1850&&AGVStatus.QR_XbiasFromros < -0.005))
        //		{
        //			agv.Command.SetBaseSpeed = 0;
        //
        //			agv.Command.SetBaseSpeed = 0;
        //
        //			LED_color(LED_yellow, 0);//黄灯常亮
        //
        //		}
        //对接时车身角度过大
        if (fabs(navi.Public.AngleDifference) > 0.1)
        {
            agv.Command.SetBaseSpeed = 0;

            agv.Command.SetBaseSpeed = 0;

            //			LED_color(LED_yellow, 0);//黄灯常亮
        }
    }
    else //没有光电停车
    {
        LastQRDataFlag = 0;

        agv.Public.i_QRCodeOKFlag = 0;

        Y12(0); //关闭光圈//因为相机需要补光才能稳定识别二维码,所以提前开启光源

        allDriverEnable = false;
        //防止手自动切换路径清掉复位
        if (navi.Public.VerticalDistanceAgvToSTART > 100 && agv.Public.i_UpdatePathSig == 0) //不能在原地回位,如果在对接状态会撞上
        {
            returnZeroPoint(agv.Parameter.SetLift1Height); //移轴举升归位
        }
        else //其他情况速度置0
        {
            DriverLifter1.Command.speed = 0;

            DriverShifter1.Command.speed = 0;
        }
    }

    pusherRunAuto(&DriverPusher1); //推杆对接
}

void platformDataProcess()
{
    //升降下限位
    if (X13)
    {
        agv.Public.i_Lift1DownLimit = 1;
    }
    else
        agv.Public.i_Lift1DownLimit = 0;
    //升降上限位
    if (X14)
    {
        agv.Public.i_Lift1UpLimit = 1;
    }
    else
        agv.Public.i_Lift1UpLimit = 0;
    //物料检测
    if (X15)
    {
        agv.Public.i_MaterialTesting = 1;
    }
    else
        agv.Public.i_MaterialTesting = 0;

    //物料到位
    if (X16)
    {
        agv.Public.i_MaterialOKFlag = 1;
    }
    else
        agv.Public.i_MaterialOKFlag = 0;

    //平移左限位
    if (X17)
    {
        agv.Public.i_Shift1_LimitLeft = 1;
    }
    else
        agv.Public.i_Shift1_LimitLeft = 0;

    //平移原点
    if (X18)
    {
        agv.Public.i_Shift1_Origin = 1;
    }
    else
        agv.Public.i_Shift1_Origin = 0;

    //平移右限位
    if (X19)
    {
        agv.Public.i_Shift1_LimitRight = 1;
    }
    else
        agv.Public.i_Shift1_LimitRight = 0;

    //推杆原点
    if (X20)
    {
        agv.Public.i_Push1_Origain = 1;
    }
    else
        agv.Public.i_Push1_Origain = 0;

    //推杆极限
    if (X21)
    {
        agv.Public.i_Push1_Limit = 1;
    }
    else
        agv.Public.i_Push1_Limit = 0;

    if (!agv.Command.Au_Hand)
    {
        //横移
        if (usCoilBuf[6] & 0x01) //上升
        {
            agv.Command.HandShiftState = 1;
        }
        else if (usCoilBuf[6] & 0x02)
        {
            agv.Command.HandShiftState = 2;
        }
        else
            agv.Command.HandShiftState = 0;

        //举升
        if (usCoilBuf[6] & 0x04) //上升
        {
            agv.Command.HandLiftState = 1;
        }
        else if (usCoilBuf[6] & 0x08)
        {
            agv.Command.HandLiftState = 2;
        }
        else
            agv.Command.HandLiftState = 0;

        //推杆
        if (usCoilBuf[8] & 0x01)
        {
            agv.Command.HandPushState = 1;
        }
        else if (usCoilBuf[8] & 0x02)
        {
            agv.Command.HandPushState = 2;
        }
        else
        {
            agv.Command.HandPushState = 0;
        }
        //阻挡块
        if (usCoilBuf[9] & 0x08) //弹出
        {
            Y10(0);
        }
        if (usCoilBuf[9] & 0x10) //缩回
        {
            Y10(1);
        }
        agv.Public.QR_Compensation_X = (float)usRegHoldingBuf[31] / 1000.0f; //

        agv.Public.QR_Compensation_Y = (float)usRegHoldingBuf[32] / 1000.0f; //

        agv.Parameter.ShiftSpeed	= usRegHoldingBuf[11]; //横移速度600
				agv.Parameter.LiftSpeed		= usRegHoldingBuf[12]; //举升速度600
        agv.Parameter.PushSpeed		= usRegHoldingBuf[39]; //推杆速度1200

        agv.Parameter.LimitPusherPos = usRegHoldingBuf[14]; //3700

        usRegInputBuf[6] = DriverLifter1.Public.encoderPose; //上层举升高度

        usRegInputBuf[7] = DriverShifter1.Public.encoderPose;

        usRegInputBuf[8] = DriverPusher1.Public.encoderPose;

        usRegInputBuf[13] = CanBatteryStruct.TotalVoltage; //电量显示
    }
}
/*SETVMOT动作指令解析*/
void commandActionAnalysis(int dataOne, int dataTwo)
{
    switch (dataOne)
    {
    case 1: //升降
        agv.Parameter.SetLift1Height = dataTwo;
        break;
    case 2: //推杆
        agv.Parameter.TargerPusherPos = dataTwo;
        break;
    case 3:              //阻挡块伸缩
        switch (dataTwo) //小车运动方式设置       //
        {
        case 1:
            Y10(0); //伸出
            break;
        case 2:
            Y10(1); //缩回
            break;
        }
        break;
    case 4:              //打开充电状态
        switch (dataTwo) //小车运动方式设置       //
        {
        case 0:
            Y9(0); //关闭充电器触点
            break;
        case 1:    //自动充电站停靠传感器选型   充电预停车指令
            Y9(1); //打开充电器触点
            break;
        }
    }
}
#endif