Demo entry 6742732

123

   

Submitted by fr on May 18, 2018 at 13:28
Language: C. Code size: 664 Bytes.

uint8_t CAN_Send(uint16_t StdId,int16_t motor1,int16_t motor2,int16_t motor3)
{
	CanTxMsg tx;	
	if(motor1>8000) motor1=3000;
	if(motor1<-8000) motor1=-3000;
	if(motor2>8000) motor2=3000;
	if(motor2<-8000) motor2=-3000;
	if(motor3>8000) motor3=3000;
	if(motor3<-8000) motor3=-3000; //限制电流的给出值,保护电机
	tx.StdId=StdId;
	tx.IDE=CAN_ID_STD;
	tx.RTR=CAN_RTR_DATA;
	tx.DLC=8;
	tx.Data[0]=motor1>>8;       //电流高八位
	tx.Data[1]=motor1&0x00ff;   //电流低八位
	tx.Data[2]=motor2>>8;       //电流高八位
	tx.Data[3]=motor2&0x00ff;   //电流低八位
	tx.Data[4]=motor3>>8;       //电流高八位
	tx.Data[5]=motor3&0x00ff;   //电流低八位
	CAN_Transmit(CAN1,&tx);  //通过CAN通信发送指令
	return 1;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).