Пример #1
0
void car_movement_control(struct movement_info *cmd)
{
	if (cmd->car_forward == 0x01)  //前进控制
	{
		DC_Motor(1, 0, 60);	//右轮正转
		//Delay_ms(30);
		DC_Motor(2, 0, 50); //左轮正转
	}
	else if (cmd->car_back == 0x01) //后退控制
	{
		DC_Motor(1, 2, 70); //右轮反转
		Delay_ms(10);
		DC_Motor(2, 2, 90); //左轮反转
	}
	else if (cmd->car_right == 0x01) //右转控制
	{
		DC_Motor(1, 2, 40);  //右轮反转
		DC_Motor(2, 0, 50);  //左轮大速度(此处电机有问题给很大的占空比,转速仍很小)
	}
	else if (cmd->car_left == 0x01)
	{
		DC_Motor(1, 0, 20);	//右轮大速度
		DC_Motor(2, 2, 20); //左轮反转
	}
	else if (cmd->car_stop == 0x01)
	{
		DC_Motor(1, 1, 0);	//右轮停止
		DC_Motor(2, 1, 0);  //左轮停止
	}
	else
	{}

	if (cmd->steer_left == 0x01) //舵机左转
	{
		servo_turn_left();
	}
	else if (cmd->steer_right == 0x01) //舵机右转
	{
		servo_turn_right();
	}
	else if (cmd->steer_stop == 0x01) //舵机停止
	{
		servo_stop();
	}
	else
	{}

}
Пример #2
0
#include "DefendMain.h"
#include <arduino.h>
#include "limits.h"

#ifndef DEBUG
#define DEBUG
#define debugSerial Serial1
#endif

HMC5883L            compass;
IR_Eye              eye(A0,6,180);

DC_MotorPair<DC_Motor>  motor(DC_Motor(4,5),DC_Motor(6,7));

US_Distance         frontUS(8,9);

AnalogGray_Color    gray(A6,4);

float xAxisMagDir = 0.0;

void setCompassOffset()
{
#ifdef DEBUG
    debugSerial.println("setCompassOffset");
#endif
    Wire.begin();
    compass.setRange(HMC5883L_RANGE_1_3GA);
    compass.setMeasurementMode(HMC5883L_CONTINOUS);
    compass.setDataRate(HMC5883L_DATARATE_30HZ);
    compass.setSamples(HMC5883L_SAMPLES_8);
//## class DC_Motor
DC_Motor::DC_Motor(void) {
    NOTIFY_CONSTRUCTOR(DC_Motor, DC_Motor(), 0, ArduiniCar_Structure_DC_Motor_DC_Motor_SERIALIZE);
}