SmartWheels self-driving race car. Designed for NXP Cup. Uses FRDM-KL25Z, area-scan camera, and simple image processing to detect and navigate any NXP spec track.
Dependencies: TSI USBDevice mbed-dev
Fork of SmartWheels by
Hardwares/Motor.cpp
- Committer:
- hazheng
- Date:
- 2017-02-08
- Revision:
- 13:7dcb1642ef99
- Parent:
- 11:676ea42afd56
- Child:
- 44:15de535c4005
File content as of revision 13:7dcb1642ef99:
#include "Motor.h" #include "mbed.h" #include "Core.h" #include "PinAssignment.h" Motor::Motor(SW::Core& core) : m_core(core), m_dirL(DigitalOut(PIN_MC_DIR_L, 1)), m_dirR(DigitalOut(PIN_MC_DIR_R, 1)), m_pwmL(PwmOut(PIN_MC_SPEED_L)), m_pwmR(PwmOut(PIN_MC_SPEED_R)) { } void Motor::Update(float deltaTime) { } void Motor::setLeftSpeed(float speed) { if(speed < -1.0f || speed > 1.0f) return; m_pwmL.period_us(60); setLeftDirection(speed < 0 ? MDIR_Backward : MDIR_Forward); speed = speed < 0 ? -speed : speed; m_pwmL = speed; } void Motor::setRightSpeed(float speed) { if(speed < -1.0f || speed > 1.0f) return; m_pwmR.period_us(60); setRightDirection(speed < 0 ? MDIR_Backward : MDIR_Forward); speed = speed < 0 ? -speed : speed; m_pwmR = speed; } void Motor::setSpeeds(float leftSpeed, float rightSpeed) { setLeftSpeed(leftSpeed); setRightSpeed(rightSpeed); } void Motor::setLeftDirection(MotorDir dir) { m_dirL = static_cast<int>(dir); } void Motor::setRightDirection(MotorDir dir) { m_dirR = static_cast<int>(dir); } void Motor::setDirections(MotorDir dirL, MotorDir dirR) { setLeftDirection(dirL); setRightDirection(dirR); }