This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Elevator door control

Other Parts Discussed in Thread: DRV8301

Hi,

A bit of background first. We are developing a new elevador door control system, we have an old desing that we want to migrate to instaspin. We bought the DRV8301 kit and we are spinning the same bldc motor we already use. We already identified the motor and the inertia succesfuly and ran all the labs, so I already know the basics of instaspin. As my main area of expertise is not microcontroller programming, and the project is estimated to be finished within 3 or 4 months, i need some advice.

Our idea is to implement a position control with an encoder feedback. Right now the encoder and the position planning is working correctly. 

We now want to include a routine to automatically recognice the distance between the Open and Closed state. The idea is to start at any position, set a controlled opening speed, once the door is open this position will be set to cero (with st_posconv_obj->Pos_mrev=0). Then set a controlled closing speed, when the QEP velocity is 0 we assume that the door is closed and save the position Pos_mrev as the closed position. With this position we want to configure the position planning. 

The problem I'm facing is that i dont really know WHERE to implement this routine. In order to spin the motor i have to enter the main loop, but i'm supposed to configure the position planning before this loop. The main ISR will also need to change, at first i just need to spin the motor without the position planning and after the recon routine i need to control the position.

My idea is to implement two main loops and two ISRs, one for the recon, and once the distance is measured, get out of the loop, reconfigure the ISR to another one using the position planning and enter the main loop to control the position. But i dont really think this is the most efficient approach.

Is this a good idea? How do you advice to solve this problem?

Thanks in advance.
 

  • Enrique,

    Sounds like a really cool application.

    The position plan component can be modified at run time.  Take a look at lab 06d.  In that lab we can configure multiple different plans while still running the motor, but while not running a plan.

    In the plan examples we have put constant numbers but you can replace those with the variables that are holding your calculated position steps.  

    I don't think you need to add in an extra main loop and main isr.  I think the key will be to reconfigure plan during the run-time.  

  • Great, thanks for the speed to reply!

    I dont know why i didnt study that lab before, its a great example for what i'm trying to do.

    Now that i read this i think the most efficient and easy way to implement what I want is to mix a velocity plan to run the recognition routine, and once its recogniced configure a position plan to control the door. I dont think that mixing both plans separately will bring any complication.

    Thanks again, and in case i have another doubt i will return to this post!

  • Hello, i've ran into a new problem.

    At the end of the trajectory the motor has to compress a spring. I'm using ST POS MOVE and feeding it a speed reference instead of a position reference in order to do the recognition routine. 

    The problem i'm havin is finding a parameter set (Speed, acce/decel, jerk and bandwidth) to make it work across all working ranges. I need to compress the spring and stop the motor fast enough to record the position and lock it there. I tried using high acel/decel and jerk values but this only leads to the motor compressing the spring and then releasing the motor with STPOSCTL error 2002.

    EDIT: Other parameters compress the spring but then the motor moves away from the desired position and then closes the door extremely fast, it seems like the controller is oscillating.

    How can i correctly evaluate these parameters in order to make it work accordingly?

  • Enrique,

    When you get the 2002 error this means that the Position Controller has an error that is larger than the allowable maximum error.  By sending in only a speed reference you an increasing the position error until it disables the controller.  I would recommend that you find a way to do this using the position reference instead of the speed reference.  This way the controller will not become disabled.

    Also if you are feeding in a speed reference without changing the position reference, as soon as your speed reference goes back to 0, the Position Controller with react to the position error.

    I would encourage you to find a way to do this with just position reference and not the speed reference.

  • In that case, maybe the best solution is to use the velocity controller to do the recognition, and then the position controller for normal operation. 

    When i saw in lab13 that you could use the position controller as a speed controller i could use it for both cases, but maybe i should implement both controllers and make them work separately.

    EDIT: Or, i could also feed an extremely high position reference, and once it reaches and compresses the spring make it stop. 

  • Enrique,

    In order to make the position system act like velocity system you need to put the position profile generator into the velocity mode.

    1. When the motor is stopped and holding a fixed position

    2. Modify st_obj.pos.move.cfg.ProfileType to ST_POS_MOVE_VEL_TYPE, at this point you can provide velocity setpoints to the reference generator

    3. Instead of setting a goal position you need to set a velocity setpoint, do this with the function STPOSMOVE_setEndVelocity()

    4. When you want to go back into position mode, set the speed reference to 0 and set st_obj.pos.move.cfg.ProfileType to ST_POS_MOVE_POS_TYPE.

    You should be able to combine the functionality of lab 13e (speed mode) with lab 13b (position mode) in order to be able to do both operating modes.

  • Right now i'm working with a soft that is a combination of those two labs, thats what i tried to explain two posts ago. And this way lead me to the problem i first stated.

    Maybe i wasnt clear enough when i explained my problem.

  • Gotcha.  Sorry I didn't understand at first.  Can you post your main source file?  

  • My main is basically the same as the one in lab 13b. I'm just modifying the ST_runPosMove function right now in order to try some things. This is what i have.

    void ST_runPosMove(ST_Handle handle)
    {
    	ST_Obj *stObj = (ST_Obj *)handle;
    	ST_PosConv_t *obj = (ST_PosConv_t *)stObj->posConvHandle;
    
    
    	if(flgRecon){
    
    		if(!flgAbierto){
    				gMotorVars.MaxVel_krpm=_IQ(.2);
    				gMotorVars.MaxAccel_krpmps=_IQ(1);
    				gMotorVars.MaxDecel_krpmps=_IQ(1);
    				gMotorVars.MaxJrk_krpmps2=_IQ20(.5);
    				gMotorVars.SpinTAC.PosCtlBwScale=_IQ(.7);
    
    				if(Velocidad!=0)
    					flgMov=1;
    
    				if(flgMov && Velocidad==0){
    					gMotorVars.MaxVel_krpm=-_IQ(0);
    					gMotorVars.SpinTAC.PosCtlBwScale=_IQ(1);
    					gMotorVars.MaxAccel_krpmps=_IQ(2);
    					gMotorVars.MaxDecel_krpmps=_IQ(2);
    					gMotorVars.MaxJrk_krpmps2=_IQ20(4);
    
    
    					flgAbierto=true;
    				}
    		}
    		else{
    			STPOSCONV_setElecAngle_erev(stObj->posConvHandle,_IQ(0));
    			obj->Pos_mrev=_IQ(0);
    			obj->PosROCounts=0;
    		}
    
    		if(_IQmpy(gMotorVars.MaxVel_krpm, _IQ(ST_SPEED_PU_PER_KRPM)) != STPOSMOVE_getVelocityEnd(stObj->posMoveHandle)) {
    			// Get the configuration for SpinTAC Velocity Profile Generator
    			STPOSMOVE_setCurveType(stObj->posMoveHandle, gMotorVars.SpinTAC.PosMoveCurveType);
    			STPOSMOVE_setProfileType(stObj->posMoveHandle, ST_POS_MOVE_VEL_TYPE);
    			STPOSMOVE_setVelocityEnd(stObj->posMoveHandle, _IQmpy(gMotorVars.MaxVel_krpm, _IQ(ST_SPEED_PU_PER_KRPM)));
    			STPOSMOVE_setAccelerationLimit(stObj->posMoveHandle, _IQmpy(gMotorVars.MaxAccel_krpmps, _IQ(ST_SPEED_PU_PER_KRPM)));
    			STPOSMOVE_setDecelerationLimit(stObj->posMoveHandle, _IQmpy(gMotorVars.MaxDecel_krpmps, _IQ(ST_SPEED_PU_PER_KRPM)));
    			STPOSMOVE_setJerkLimit(stObj->posMoveHandle, _IQ20mpy(gMotorVars.MaxJrk_krpmps2, _IQ20(ST_SPEED_PU_PER_KRPM)));
    			// Enable the SpinTAC Position Profile Generator
    			STPOSMOVE_setEnable(stObj->posMoveHandle, true);
    			flgAux=1;
    		}
    	}
    	else
    	{
    
    		// Run SpinTAC Position Profile Generator
    		// If we are not running a profile, and command indicates we should has been modified
    		if((STPOSMOVE_getStatus(stObj->posMoveHandle) == ST_MOVE_IDLE) && (gMotorVars.RunPositionProfile == true)) {
    			// Get the configuration for SpinTAC Position Move
    			STPOSMOVE_setCurveType(stObj->posMoveHandle, gMotorVars.SpinTAC.PosMoveCurveType);
    			STPOSMOVE_setProfileType(stObj->posMoveHandle, ST_POS_MOVE_POS_TYPE);
    			STPOSMOVE_setPositionStep_mrev(stObj->posMoveHandle, gMotorVars.PosStepInt_MRev,  gMotorVars.PosStepFrac_MRev);
    			STPOSMOVE_setVelocityLimit(stObj->posMoveHandle, _IQmpy(gMotorVars.MaxVel_krpm, _IQ(ST_SPEED_PU_PER_KRPM)));
    			STPOSMOVE_setAccelerationLimit(stObj->posMoveHandle, _IQmpy(gMotorVars.MaxAccel_krpmps, _IQ(ST_SPEED_PU_PER_KRPM)));
    			STPOSMOVE_setDecelerationLimit(stObj->posMoveHandle, _IQmpy(gMotorVars.MaxDecel_krpmps, _IQ(ST_SPEED_PU_PER_KRPM)));
    			STPOSMOVE_setJerkLimit(stObj->posMoveHandle, _IQ20mpy(gMotorVars.MaxJrk_krpmps2, _IQ20(ST_SPEED_PU_PER_KRPM)));
    			// Enable the SpinTAC Position Profile Generator
    			STPOSMOVE_setEnable(stObj->posMoveHandle, true);
    			// clear the position step command
    			flgAux=0;
    			gMotorVars.PosStepInt_MRev = 0;
    			gMotorVars.PosStepFrac_MRev = 0;
    			gMotorVars.RunPositionProfile = false;
    		}
    	}
    
    	STPOSMOVE_run(stObj->posMoveHandle);
    }
    

    It isnt elegant, but its just to try functionality. flgRecon is a flag to run the recognition routine, flgAbierto is a flag that identifies the Door Open status, flgMov is a flag to know when the door is moving, and Velocidad is a iq variable to read the speed from the encoder, flgAux is just a flag to know whether i'm in position control or velocity control.

  • Enrique,

    I think the issue is that after you set flgAbierto to true, you then want to zero out the position system.  By setting STPOSCONV_setElecAngle_erev to zero it will cause some weird issues.

    What is the goal at the end of the recognition routine?  

    If you want to zero out the position system I would recommend that you SETPOSCONV_setEnable to false for 1 sample and back to true.  This will reset the Position Converter back to 0.  You would then need to also modify STPOSMOVE_setPositionStart_mrev to 0 as well.  This will align the feedback from the Position Converter and the reference from the Position Move both to zero and should not cause any issues.