void motorSquare(uint16_t peakVoltage)
{
	uint16_t zero = 0;								// 16 bit zero
	motorForward();
	setMotorAmplitude(peakVoltage);				// drive the motor at DC voltage
	__delay_cycles(2000000);						// 1 second delay
	setMotorAmplitude(zero);					// stop motor
	motorOpen();									// bring motor to open state as recomended from datasheet
	__delay_cycles(20);							// let voltage levels settle
	motorBrake();
	__delay_cycles(2000000);
	// break motor
	//while(ADC12MEM0 > 100){}
	//ADC12IER0 &= ~ADC12IE0;                     // disable interupt on ADC12IFG0 bit
	//ADC12IER0 &= ~ADC12IE1;                     // disable interupt on ADC12IFG1 bit
	//startTimer();
}
示例#2
0
void processCmdMsg(pb_istream_t *streamPtr) {
	pb_istream_t substream;
	gCmdParamNum = 0;
	double degSec;
	double pos;
	EMotorDirection dir;

	if (pb_make_string_substream(streamPtr, &substream)) {
		MotorMsg_Cmd motorCmd = MotorMsg_Cmd_init_zero;
		motorCmd.params.funcs.decode = &motorCmdParamCallback;
		//motorCmd.params.arg = (void *) (&motorCmd.action);

		pb_decode(&substream, MotorMsg_Cmd_fields, &motorCmd);
		pb_close_string_substream(streamPtr, &substream);

		switch (motorCmd.action) {
			case MotorMsg_Cmd_Action_UNKNOWN:
				break;
			case MotorMsg_Cmd_Action_BRAKE:
				motorBrake();
				break;
			case MotorMsg_Cmd_Action_FREEWHEEL:
				motorFreewheel();
				break;
			case MotorMsg_Cmd_Action_RUN:
				degSec = getMotorParam(MotorMsg_Cmd_Param_Id_VELOCITY, gCmdParams, gCmdParamNum);
				dir = (getMotorParam(MotorMsg_Cmd_Param_Id_CLOCKWISE, gCmdParams, gCmdParamNum) != 0.0) ? eClockwise : eCounterClockwise;
				motorRun(dir, degSec);
				break;
			case MotorMsg_Cmd_Action_GOTO_POS:
				pos = getMotorParam(MotorMsg_Cmd_Param_Id_POSITION, gCmdParams, gCmdParamNum);
				degSec = getMotorParam(MotorMsg_Cmd_Param_Id_VELOCITY, gCmdParams, gCmdParamNum);
				dir = (getMotorParam(MotorMsg_Cmd_Param_Id_CLOCKWISE, gCmdParams, gCmdParamNum) != 0.0) ? eClockwise : eCounterClockwise;
				motorGotoPos(dir, pos, degSec);
				break;
		}
	}
}
示例#3
0
void Move::brake() {
  changeMoveState(MOV_STOP);
  motorBrake(MOTOR_LEFT);
  motorBrake(MOTOR_RIGHT);
}