Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of autonomous Robot Android by
Actuators/MaxonESCON/MaxonESCON.cpp
- Committer:
- chrigelburri
- Date:
- 2013-02-07
- Revision:
- 0:31f7be68e52d
- Child:
- 1:6cd533a712c6
File content as of revision 0:31f7be68e52d:
#include "MaxonESCON.h"
using namespace std;
MaxonESCON::MaxonESCON(
PinName enb,
PinName isenb,
PinName pwm,
PinName actualSpeed,
Hallsensor *hall
)
:
_enb(enb),
_isenb(isenb),
_pwm(pwm),
_actualSpeed(actualSpeed),
_hall(hall)
{
_pwm = 0;
// Initial condition of output enables
_enb = 0;
// Set initial condition of PWM 2kHz
period(0.0005);
// Set the pulses to zero
_pulses = 0;
// Set the Pull Up Resistor
_isenb.mode(PullUp);
}
void MaxonESCON::setVelocity(float speed)
{
speed = speed / ESCON_SET_FACTOR * 60.0f;
if(speed > 1 ) {
_pwm = 0.9f;
} else if(speed < -1) {
_pwm = 0.1f;
} else {
_pwm = 0.4f*speed + 0.5f;
}
}
float MaxonESCON::getActualSpeed(void)
{
return (_actualSpeed.read()* 2.0f - 1.0f) * ESCON_GET_FACTOR / 60.0f;
}
void MaxonESCON::period(float period)
{
_pwm.period(period);
}
void MaxonESCON::enable(bool enb)
{
if(enb == false) {
_enb = 0;
} else {
_enb = 1;
}
}
bool MaxonESCON::isEnabled()
{
if(_isenb.read() == 1) {
return true;
} else {
return false;
}
/*
if(_enb == 0) {
return false;
} else {
return true;
}*/
}
int MaxonESCON::getPulses(void)
{
_pulses = _hall->getPulses();
return _pulses;
}
int MaxonESCON::setPulses(int setPos)
{
_hall->reset();
_pulses = _hall->getPulses();
return _pulses;
}
///// Für Polling muss mit unter Code gearbeitet werden.
/*
int MaxonESCON::getHallPosition(void)
{
return HALL_POSITION[(_hall1.read() ? 1 : 0)+(_hall2.read() ? 2 : 0)+(_hall3.read() ? 4 : 0)];
}
int MaxonESCON::getPosition(void)
{
position calculation
int actualHallPosition = getHallPosition();
if (actualHallPosition > 0) {
if ((actualHallPosition == 1) && (hallPosition >= 5)) {
turns++;
} else if ((actualHallPosition == 2) && (hallPosition == 6)) {
turns++;
} else if ((actualHallPosition == 5) && (hallPosition == 1)) {
turns--;
} else if ((actualHallPosition == 6) && (hallPosition <= 2)) {
turns--;
}
hallPosition = actualHallPosition;
}
return turns;
}
float MaxonESCON::getTransPosition(void)
{
return (turns * 2 * _wheelRadius * pi) / (_gear * _polePairs); // PULSES_PER_STEP muss weg da nach 6 hallimpus ein turn gibt
}
int MaxonESCON::setPosition(int setPos)
{
turns = setPos;
return turns;
}
*/
