-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
569 changed files
with
56,223 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/********************************************************** | ||
Description: 下位机arduino Due上的蜂鸣器模块头文件, | ||
定义蜂鸣器连接的引脚,各种声音的宏定义。 | ||
Author: ROS小课堂 www.corvin.cn | ||
History: 20190927: init this file; | ||
***********************************************************/ | ||
#ifndef _BEEP_RING_H_ | ||
#define _BEEP_RING_H_ | ||
|
||
#define BEEP_PIN 36 | ||
|
||
#define POWEROFF_BEEP 0 | ||
#define POWERON_BEEP 1 | ||
|
||
#define BEEP_ON HIGH | ||
#define BEEP_OFF LOW | ||
|
||
void initBeepPin(); | ||
void powerOnBeep(); | ||
void powerOffBeep(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/************************************************ | ||
Description: 在arduino DUE板上接蜂鸣器来生成各种声音 | ||
反馈当前下位机的运行状态。 | ||
Author: ROS小课堂 www.corvin.cn | ||
History: 20190927: init this file; | ||
*************************************************/ | ||
|
||
void initBeepPin() | ||
{ | ||
pinMode(BEEP_PIN, OUTPUT); | ||
digitalWrite(BEEP_PIN, HIGH);//init beep not ring | ||
delay(100); | ||
digitalWrite(BEEP_PIN, LOW); | ||
} | ||
|
||
void basePowerOnBeep() | ||
{ | ||
for (int i = 0; i < 2; i++) | ||
{ | ||
digitalWrite(BEEP_PIN, BEEP_ON); | ||
delay(100); | ||
digitalWrite(BEEP_PIN, BEEP_OFF); | ||
delay(100); | ||
} | ||
// digitalWrite(BEEP_PIN, HIGH); | ||
} | ||
|
||
void basePowerOffBeep() | ||
{ | ||
for (int i = 0; i < 2; i++) | ||
{ | ||
digitalWrite(BEEP_PIN, BEEP_ON); | ||
delay(500); | ||
digitalWrite(BEEP_PIN, BEEP_OFF); | ||
delay(500); | ||
} | ||
// digitalWrite(BEEP_PIN, HIGH); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*********************************************************************************** | ||
Description:Define single-letter commands that will be sent by the PC over the | ||
serial link. | ||
Author: www.corvin.cn | ||
History: 20180209:init this file,add CODE_VERSION command; | ||
************************************************************************************/ | ||
#ifndef _COMMANDS_H_ | ||
#define _COMMANDS_H_ | ||
|
||
#define ANALOG_READ 'a' | ||
#define GET_BAUDRATE 'b' | ||
#define PIN_MODE 'c' | ||
#define DIGITAL_READ 'd' | ||
#define READ_ENCODERS 'e' | ||
#define GET_CURRENT 'f' | ||
#define GET_VOLTAGE 'g' | ||
#define MOTOR_SPEEDS 'm' | ||
#define RESET_ENCODERS 'r' | ||
#define SET_SERVO_POS 's' | ||
#define GET_SERVO_POS 't' | ||
#define UPDATE_PID 'u' | ||
#define DIGITAL_WRITE 'w' | ||
#define ANALOG_WRITE 'x' | ||
#define READ_PIDIN 'i' | ||
#define READ_PIDOUT 'o' | ||
#define BEEP_RING 'p' | ||
#define CODE_VERSION 'v' | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/************************************************************** | ||
Description: 锂电池输出电流检测 | ||
Author: www.corvin.cn | ||
History: 20190927:init this file; | ||
*************************************************************/ | ||
#ifndef _CURRENT_DETECT_ | ||
#define _CURRENT_DETECT_ | ||
|
||
#define CURRENT_AREF 3.3 | ||
#define CURRENT_PIN A1 | ||
#define CURRENT_SENS 0.2 | ||
#define ADC_RESOLUTION 12 | ||
#define ADC_SENS 4095.0 | ||
#define CURRENT_OFFSET 1.48 //偏置电压,空载是A1的输出电压 | ||
|
||
void initCurrentDetect(); | ||
float detectCurrent(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*************************************************************** | ||
Description:锂电池输出电流检测功能。 | ||
Author: www.corvin.cn | ||
History: 20190927: init this file; | ||
****************************************************************/ | ||
void initCurrentDetect() | ||
{ | ||
pinMode(CURRENT_PIN, INPUT); | ||
analogReference(AR_DEFAULT); //调用板载3.3V默认基准源 | ||
analogReadResolution(ADC_RESOLUTION); | ||
} | ||
|
||
float detectCurrent() | ||
{ | ||
int sum = 0; | ||
int cnt = 10; | ||
|
||
for (int index = 0; index < cnt; index++) | ||
{ | ||
sum += analogRead(CURRENT_PIN); | ||
} | ||
|
||
int readValue = sum / cnt; | ||
float current = (readValue / ADC_SENS * CURRENT_AREF - CURRENT_OFFSET) / CURRENT_SENS; | ||
|
||
return current; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/************************************************************** | ||
Description: Encoder driver function definitions | ||
Author: www.corvin.cn | ||
History: 20180209:init this file; | ||
*************************************************************/ | ||
#ifndef __ENCODER_DRIVER_H__ | ||
#define __ENCODER_DRIVER_H__ | ||
|
||
//A wheel encode pin | ||
#define ENC_A_PIN_A 26 //pin 26 | ||
#define ENC_A_PIN_B 27 //pin 27 | ||
|
||
//B wheel encode pin | ||
#define ENC_B_PIN_A 30 //pin 30 | ||
#define ENC_B_PIN_B 31 //pin 31 | ||
|
||
//C wheel encode pin | ||
#define ENC_C_PIN_A 34 //pin 34 | ||
#define ENC_C_PIN_B 35 //pin 35 | ||
|
||
#define A_WHEEL 1 | ||
#define B_WHEEL 2 | ||
#define C_WHEEL 3 | ||
|
||
void initEncoders(void); | ||
long readEncoder(int i); | ||
void resetEncoders(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/************************************************************** | ||
Description: Encoder definitions需要连接到arduino DUE的正确引脚上: | ||
Encoder A: connect interrupt [pin 26, 27]; | ||
Encoder B: connect interrupt [pin 30, 31]; | ||
Encoder C: connect intterupt [pin 34, 35] | ||
Author: www.corvin.cn ROS小课堂 | ||
History: 20190909:init this file; | ||
**************************************************************/ | ||
#include "motor_driver.h" | ||
#include "encoder_driver.h" | ||
|
||
static volatile long A_enc_cnt = 0L; | ||
static volatile long B_enc_cnt = 0L; | ||
static volatile long C_enc_cnt = 0L; | ||
|
||
/*init encoder connect pin, config ISR functions*/ | ||
void initEncoders(void) | ||
{ | ||
pinMode(ENC_A_PIN_A, INPUT); | ||
pinMode(ENC_A_PIN_B, INPUT); | ||
attachInterrupt(ENC_A_PIN_A, encoderA_ISR, FALLING); | ||
attachInterrupt(ENC_A_PIN_B, encoderA_ISR, FALLING); | ||
|
||
pinMode(ENC_B_PIN_A, INPUT); | ||
pinMode(ENC_B_PIN_B, INPUT); | ||
attachInterrupt(ENC_B_PIN_A, encoderB_ISR, FALLING); | ||
attachInterrupt(ENC_B_PIN_B, encoderB_ISR, FALLING); | ||
|
||
pinMode(ENC_C_PIN_A, INPUT); | ||
pinMode(ENC_C_PIN_B, INPUT); | ||
attachInterrupt(ENC_C_PIN_A, encoderC_ISR, FALLING); | ||
attachInterrupt(ENC_C_PIN_B, encoderC_ISR, FALLING); | ||
} | ||
|
||
/* Interrupt routine for A encoder, taking care of actual counting */ | ||
void encoderA_ISR (void) | ||
{ | ||
if (directionWheel(A_WHEEL) == BACKWARDS) | ||
{ | ||
A_enc_cnt--; | ||
} | ||
else | ||
{ | ||
A_enc_cnt++; | ||
} | ||
} | ||
|
||
/* Interrupt routine for B encoder, taking care of actual counting */ | ||
void encoderB_ISR (void) | ||
{ | ||
if (directionWheel(B_WHEEL) == BACKWARDS) | ||
{ | ||
B_enc_cnt--; | ||
} | ||
else | ||
{ | ||
B_enc_cnt++; | ||
} | ||
} | ||
|
||
/* Interrupt routine for C encoder, taking care of actual counting */ | ||
void encoderC_ISR (void) | ||
{ | ||
if (directionWheel(C_WHEEL) == BACKWARDS) | ||
{ | ||
C_enc_cnt--; | ||
} | ||
else | ||
{ | ||
C_enc_cnt++; | ||
} | ||
} | ||
|
||
/* Wrap the encoder reading function */ | ||
long readEncoder(int i) | ||
{ | ||
if (i == A_WHEEL) | ||
{ | ||
return A_enc_cnt; | ||
} | ||
else if (i == B_WHEEL) | ||
{ | ||
return B_enc_cnt; | ||
} | ||
else | ||
{ | ||
return C_enc_cnt; | ||
} | ||
} | ||
|
||
/* Wrap the encoder count reset function */ | ||
void resetEncoders(void) | ||
{ | ||
A_enc_cnt = 0L; | ||
B_enc_cnt = 0L; | ||
C_enc_cnt = 0L; | ||
} |
Oops, something went wrong.