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
reeedstudio
committed
Jun 27, 2014
0 parents
commit 4c8a29e
Showing
9 changed files
with
488 additions
and
0 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,198 @@ | ||
/* | ||
moto_4wd.cpp | ||
2012 Copyright (c) Seeed Technology Inc. All right reserved. | ||
Author: Loovee | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#include <Arduino.h> | ||
#include <seeed_pwm.h> | ||
#include "motordriver_4wd.h" | ||
|
||
/********************************************************************************************************* | ||
** Function name: init | ||
** Descriptions: init all pins | ||
*********************************************************************************************************/ | ||
void motor_4wd::init() | ||
{ | ||
motorSpeed1 = 0; | ||
motorSpeed2 = 0; | ||
|
||
motorDir1 = 0; | ||
motorDir2 = 0; | ||
|
||
motorState1 = STOP; | ||
motorState2 = STOP; | ||
|
||
// pwm set | ||
PWM.init(); | ||
PWM.setPwm(9, 0, FREQPWM); | ||
PWM.setPwm(10, 0, FREQPWM); | ||
|
||
pinMode(PINCS, OUTPUT); | ||
pinMode(PINM1F, OUTPUT); | ||
pinMode(PINM1R, OUTPUT); | ||
pinMode(PINM2F, OUTPUT); | ||
pinMode(PINM2R, OUTPUT); | ||
|
||
digitalWrite(PINCS, LOW); | ||
digitalWrite(PINM1F, LOW); | ||
digitalWrite(PINM1R, LOW); | ||
digitalWrite(PINM2F, LOW); | ||
digitalWrite(PINM2R, LOW); | ||
|
||
} | ||
|
||
/********************************************************************************************************* | ||
** Function name: setRun1 | ||
** Descriptions: set motor 1 run | ||
*********************************************************************************************************/ | ||
void motor_4wd::setRun1() | ||
{ | ||
PWM.setPwm(9, motorSpeed1, FREQPWM); | ||
ALLMOSON; | ||
if(motorDir1 == DIRF) | ||
{ | ||
digitalWrite(PINM1F, HIGH); | ||
digitalWrite(PINM1R, LOW); | ||
} | ||
else | ||
{ | ||
digitalWrite(PINM1F, LOW); | ||
digitalWrite(PINM1R, HIGH); | ||
} | ||
motorState1 = RUN; | ||
} | ||
|
||
/********************************************************************************************************* | ||
** Function name: setRun2 | ||
** Descriptions: set motor 2 run | ||
*********************************************************************************************************/ | ||
void motor_4wd::setRun2() | ||
{ | ||
PWM.setPwm(10, motorSpeed2, FREQPWM); | ||
ALLMOSON; | ||
if(motorDir2 == DIRF) | ||
{ | ||
digitalWrite(PINM2F, HIGH); | ||
digitalWrite(PINM2R, LOW); | ||
} | ||
else | ||
{ | ||
digitalWrite(PINM2F, LOW); | ||
digitalWrite(PINM2R, HIGH); | ||
} | ||
motorState2 = RUN; | ||
} | ||
|
||
/********************************************************************************************************* | ||
** Function name: setStop1 | ||
** Descriptions: set motor 1 stop | ||
*********************************************************************************************************/ | ||
void motor_4wd::setStop1() | ||
{ | ||
PWM.setPwm(9, 0, FREQPWM); | ||
digitalWrite(PINM1F, LOW); | ||
digitalWrite(PINM1R, LOW); | ||
motorState1 = STOP; | ||
} | ||
|
||
/********************************************************************************************************* | ||
** Function name: setStop2 | ||
** Descriptions: set motor 2 stop | ||
*********************************************************************************************************/ | ||
void motor_4wd::setStop2() | ||
{ | ||
PWM.setPwm(10, 0, FREQPWM); | ||
digitalWrite(PINM2F, LOW); | ||
digitalWrite(PINM2R, LOW); | ||
motorState2 = STOP; | ||
} | ||
|
||
/********************************************************************************************************* | ||
** Function name: setSpeed1 | ||
** Descriptions: set motor 1 speed | ||
*********************************************************************************************************/ | ||
void motor_4wd::setSpeed1(int ispeed) // pwm, 0-100 | ||
{ | ||
motorSpeed1 = ispeed < 100 ? ispeed : 100; | ||
} | ||
|
||
/********************************************************************************************************* | ||
** Function name: setSpeed2 | ||
** Descriptions: set motor 1 speed | ||
*********************************************************************************************************/ | ||
void motor_4wd::setSpeed2(int ispeed) // pwm, 0-100 | ||
{ | ||
motorSpeed2 = ispeed < 100 ? ispeed : 100; | ||
} | ||
|
||
/********************************************************************************************************* | ||
** Function name: setDir1 | ||
** Descriptions: set motor 1 direction | ||
*********************************************************************************************************/ | ||
void motor_4wd::setDir1(unsigned char dir) | ||
{ | ||
motorDir1 = dir; | ||
} | ||
|
||
/********************************************************************************************************* | ||
** Function name: setDir2 | ||
** Descriptions: set motor 2 direction | ||
*********************************************************************************************************/ | ||
void motor_4wd::setDir2(unsigned char dir) | ||
{ | ||
motorDir2 = dir; | ||
} | ||
/********************************************************************************************************* | ||
** Function name: setSpeedDir | ||
** Descriptions: set motor 2 direction | ||
*********************************************************************************************************/ | ||
void motor_4wd::setSpeedDir(int ispeed, unsigned char dir) | ||
{ | ||
setSpeedDir1(ispeed, dir); | ||
setSpeedDir2(ispeed, dir); | ||
} | ||
|
||
/********************************************************************************************************* | ||
** Function name: setSpeedDir1 | ||
** Descriptions: set motor1 speed and direction | ||
*********************************************************************************************************/ | ||
void motor_4wd::setSpeedDir1(int ispeed, unsigned char dir) | ||
{ | ||
setSpeed1(ispeed); | ||
setDir1(dir); | ||
setRun1(); | ||
|
||
} | ||
|
||
/********************************************************************************************************* | ||
** Function name: setSpeedDir2 | ||
** Descriptions: set motor2 speed and direction | ||
*********************************************************************************************************/ | ||
void motor_4wd::setSpeedDir2(int ispeed, unsigned char dir) | ||
{ | ||
setSpeed2(ispeed); | ||
setDir2(dir); | ||
setRun2(); | ||
} | ||
|
||
motor_4wd MOTOR; | ||
|
||
/********************************************************************************************************* | ||
END FILE | ||
*********************************************************************************************************/ |
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,67 @@ | ||
/* | ||
moto_4wd.h | ||
2012 Copyright (c) Seeed Technology Inc. All right reserved. | ||
Author: Loovee | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
#ifndef __MOTORDRIVER_4WD_H__ | ||
#define __MOTORDRIVER_4WD_H__ | ||
|
||
#include "motordriver_4wd_dfs.h" | ||
|
||
class motor_4wd | ||
{ | ||
private: | ||
|
||
unsigned char motorSpeed1; // pwm: 0-100 | ||
unsigned char motorSpeed2; // pwm: 0-100 | ||
|
||
unsigned char motorDir1; | ||
unsigned char motorDir2; | ||
|
||
unsigned char motorState1; | ||
unsigned char motorState2; | ||
|
||
public: | ||
|
||
void init(); | ||
|
||
void setRun1(); | ||
void setRun2(); | ||
|
||
void setStop1(); | ||
void setStop2(); | ||
|
||
void setSpeed1(int ispeed); // pwm, 0-100 | ||
void setSpeed2(int ispeed); // pwm, 0-100 | ||
|
||
void setDir1(unsigned char dir); | ||
void setDir2(unsigned char dir); | ||
|
||
void setSpeedDir(int ispeed, unsigned char dir); | ||
void setSpeedDir1(int ispeed, unsigned char dir); | ||
void setSpeedDir2(int ispeed, unsigned char dir); | ||
|
||
}; | ||
|
||
extern motor_4wd MOTOR; | ||
#endif | ||
/********************************************************************************************************* | ||
END FILE | ||
*********************************************************************************************************/ | ||
|
||
|
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,56 @@ | ||
/* | ||
moto_4wd_dfs.h | ||
2012 Copyright (c) Seeed Technology Inc. All right reserved. | ||
Author: Loovee | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
#ifndef __MOTORDRIVER_4WD_DFS_H__ | ||
#define __MOTORDRIVER_4WD_DFS_H__ | ||
|
||
#define FREQPWM 10000 // 10khZ | ||
|
||
// order SEND | ||
#define RETM1SPEED 0x87 | ||
#define RETM2SPEED 0x88 | ||
#define RETM1STATE 0x90 | ||
#define RETM2STATE 0x91 | ||
|
||
// motor state | ||
#define STOP 0x00 // motor stop | ||
#define RUN 0x01 // motor run | ||
|
||
#define DIRF 0x00 // Forward | ||
#define DIRR 0x01 // Reversion | ||
|
||
// pin ctrl | ||
#define PINCS 6 // all mos cs | ||
#define PINM1F 4 | ||
#define PINM1R 5 | ||
#define PINM2F 7 | ||
#define PINM2R 8 | ||
|
||
//ctrl | ||
#define ALLMOSON digitalWrite(PINCS, HIGH) | ||
#define ALLMOSOFF digitalWrite(PINCS, LOW) | ||
|
||
|
||
|
||
|
||
#endif | ||
/********************************************************************************************************* | ||
END FILE | ||
*********************************************************************************************************/ |
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,4 @@ | ||
Hercules_Motor_Driver | ||
===================== | ||
|
||
Hercules, Motor Driver, SeeedStudio |
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,20 @@ | ||
#include "motordriver_4wd.h" | ||
#include <seeed_pwm.h> | ||
|
||
void setup() | ||
{ | ||
MOTOR.init(); | ||
} | ||
|
||
void loop() | ||
{ | ||
MOTOR.setSpeedDir(80, DIRF); | ||
delay(3000); | ||
MOTOR.setSpeedDir(80, DIRR); | ||
delay(3000); | ||
} | ||
/********************************************************************************************************* | ||
* END FILE | ||
*********************************************************************************************************/ | ||
|
||
|
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,13 @@ | ||
|
||
#include "seeed_pwm.h" | ||
void setup() | ||
{ | ||
PWM.init(); // init | ||
PWM.setPwm(9, 20, 5000); // pin: 9, duty: 20%, freq: 5kHz | ||
PWM.setPwm(10, 80, 50000); // pin: 10, duty: 80%, freq: 5kHz | ||
|
||
} | ||
|
||
void loop() | ||
{ | ||
} |
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,28 @@ | ||
####################################### | ||
# Syntax Coloring Map For SoftPWM | ||
####################################### | ||
|
||
####################################### | ||
# Datatypes (KEYWORD1) | ||
####################################### | ||
|
||
SoftPWM KEYWORD1 | ||
|
||
####################################### | ||
# Methods and Functions (KEYWORD2) | ||
####################################### | ||
|
||
SoftPWMSet KEYWORD2 | ||
SoftPWMSetPercent KEYWORD2 | ||
SoftPWMSetFadeTime KEYWORD2 | ||
SoftPWMBegin KEYWORD2 | ||
SoftPWMEnd KEYWORD2 | ||
SoftPWMSetPolarity KEYWORD2 | ||
|
||
####################################### | ||
# Constants (LITERAL1) | ||
####################################### | ||
|
||
ALL LITERAL1 | ||
SOFTPWM_NORMAL LITERAL1 | ||
SOFTPWM_INVERTED LITERAL1 |
Oops, something went wrong.