RasPi/CopterController/PCA9685tester.cpp

75 lines
2.2 KiB
C++
Raw Normal View History

2015-02-04 20:37:34 -07:00
#include <iostream>
2015-02-06 15:16:40 -07:00
#include "stdlib.h"
2015-02-04 20:37:34 -07:00
#include "wiringPi.h"
#include "PCA9685.h"
2015-02-06 15:16:40 -07:00
#define MOTOR_MIN 200
#define MOTOR_MAX 600
#define SERVO_FREQ 60
2015-02-04 20:37:34 -07:00
int main( int argc, const char* argv[] )
{
2015-02-06 15:16:40 -07:00
std::cout << "will only test motor 0" << std::endl;
int currentValue = MOTOR_MIN;
2015-02-04 20:37:34 -07:00
wiringPiSetup();
PCA9685 servo = PCA9685( 0x40 );
2015-02-06 15:16:40 -07:00
servo.setFrequency( SERVO_FREQ );
std::cout << "freq set: " << SERVO_FREQ << std::endl;
2015-02-04 20:37:34 -07:00
2015-02-06 15:16:40 -07:00
if( argc > 1 )
{
if( atoi(argv[1]) == 1 )
{
std::cout << "will set max pwm" << std::endl;
servo.setPwm( 0, 0, MOTOR_MAX );
std::cout << "pwm set " << MOTOR_MAX << std::endl;
std::cout << "press ENTER to continue" << std::endl;
while( std::cin.get() != '\n' );
}
}
2015-02-04 20:37:34 -07:00
2015-02-06 15:16:40 -07:00
servo.setPwm( 0, 0, MOTOR_MIN );
std::cout << "pwm set " << MOTOR_MIN << std::endl;
std::cout << "press ENTER to continue" << std::endl;
2015-02-04 20:37:34 -07:00
while( std::cin.get() != '\n' );
while( true )
{
2015-02-06 15:16:40 -07:00
int keyPressed = std::cin.get();
if( keyPressed == ' ' )
{
std::cout << "KILL MOTOR" << std::endl;
currentValue = MOTOR_MIN;
servo.setPwm( 0, 0, currentValue );
std::cout << "pwm: " << currentValue << std::endl;
}
else if( keyPressed == 'w' ) // up arrow
{
std::cout << "up pressed" << std::endl;
currentValue += 5;
if( currentValue > MOTOR_MAX ) currentValue = MOTOR_MAX;
servo.setPwm( 0, 0, currentValue );
std::cout << "pwm: " << currentValue << std::endl;
}
else if( keyPressed == 's' ) // down arrow
{
std::cout << "down pressed" << std::endl;
currentValue -= 5;
if( currentValue < MOTOR_MIN ) currentValue = MOTOR_MIN;
servo.setPwm( 0, 0, currentValue );
std::cout << "pwm: " << currentValue << std::endl;
}
/*
servo.setPwm( 0, 0, MOTOR_MAX );
std::cout << "pwm: " << MOTOR_MAX << std::endl;
2015-02-04 20:37:34 -07:00
delay( 1000 );
2015-02-06 15:16:40 -07:00
servo.setPwm( 0, 0, MOTOR_MIN );
std::cout << "pwm: " << MOTOR_MIN << std::endl;
2015-02-04 20:37:34 -07:00
delay( 1000 );
2015-02-06 15:16:40 -07:00
*/
2015-02-04 20:37:34 -07:00
}
}