mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
servo: Added new module servo
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
This commit is contained in:
parent
f1cf463126
commit
aac51c4850
@ -8,6 +8,7 @@ add_executable (led-bar led-bar.cxx)
|
|||||||
add_executable (seg-lcd 4digitdisplay.cxx)
|
add_executable (seg-lcd 4digitdisplay.cxx)
|
||||||
add_executable (nrf_transmitter nrf_transmitter.cxx)
|
add_executable (nrf_transmitter nrf_transmitter.cxx)
|
||||||
add_executable (nrf_receiver nrf_receiver.cxx)
|
add_executable (nrf_receiver nrf_receiver.cxx)
|
||||||
|
add_executable (es08a es08a.cxx)
|
||||||
|
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||||
@ -16,6 +17,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/buzzer)
|
|||||||
include_directories (${PROJECT_SOURCE_DIR}/src/ledbar)
|
include_directories (${PROJECT_SOURCE_DIR}/src/ledbar)
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src/4digitdisplay)
|
include_directories (${PROJECT_SOURCE_DIR}/src/4digitdisplay)
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src/nrf24l01)
|
include_directories (${PROJECT_SOURCE_DIR}/src/nrf24l01)
|
||||||
|
include_directories (${PROJECT_SOURCE_DIR}/src/servo)
|
||||||
|
|
||||||
target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||||
target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
|
||||||
@ -27,3 +29,4 @@ target_link_libraries (led-bar ledbar ${CMAKE_THREAD_LIBS_INIT})
|
|||||||
target_link_libraries (seg-lcd 4digitdisplay ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries (seg-lcd 4digitdisplay ${CMAKE_THREAD_LIBS_INIT})
|
||||||
target_link_libraries (nrf_transmitter nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries (nrf_transmitter nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
|
||||||
target_link_libraries (nrf_receiver nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries (nrf_receiver nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
target_link_libraries (es08a servo ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
68
examples/es08a.cxx
Normal file
68
examples/es08a.cxx
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||||
|
* Copyright (c) 2014 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "es08a.h"
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int running = 0;
|
||||||
|
|
||||||
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
|
{
|
||||||
|
printf("got signal\n");
|
||||||
|
if (signo == SIGINT) {
|
||||||
|
printf("exiting application\n");
|
||||||
|
running = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
upm::ES08A *servo = new upm::ES08A(5);
|
||||||
|
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
int clock = 0;
|
||||||
|
while (!running) {
|
||||||
|
for (int i = 0; i < 18; i++) {
|
||||||
|
servo->setAngle (clock);
|
||||||
|
clock += 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 18; i++) {
|
||||||
|
servo->setAngle (clock);
|
||||||
|
clock -= 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "exiting application" << std::endl;
|
||||||
|
|
||||||
|
delete servo;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -5,3 +5,4 @@ add_subdirectory (buzzer)
|
|||||||
add_subdirectory (ledbar)
|
add_subdirectory (ledbar)
|
||||||
add_subdirectory (4digitdisplay)
|
add_subdirectory (4digitdisplay)
|
||||||
add_subdirectory (nrf24l01)
|
add_subdirectory (nrf24l01)
|
||||||
|
add_subdirectory (servo)
|
||||||
|
4
src/servo/CMakeLists.txt
Normal file
4
src/servo/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
set (libname "servo")
|
||||||
|
add_library (servo SHARED servo.cxx es08a.cxx)
|
||||||
|
include_directories (${MAA_INCLUDE_DIR})
|
||||||
|
target_link_libraries (servo ${MAA_LIBRARIES})
|
39
src/servo/es08a.cxx
Normal file
39
src/servo/es08a.cxx
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||||
|
* Copyright (c) 2014 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "es08a.h"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
ES08A::ES08A (int pin) : Servo(pin) {
|
||||||
|
m_name = "ES08A";
|
||||||
|
m_maxAngle = 180.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ES08A::~ES08A() {
|
||||||
|
|
||||||
|
}
|
40
src/servo/es08a.h
Normal file
40
src/servo/es08a.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||||
|
* Copyright (c) 2014 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "servo.h"
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
|
#define MIN_PULSE_WIDTH 600
|
||||||
|
#define MAX_PULSE_WIDTH 2500
|
||||||
|
|
||||||
|
class ES08A : public Servo {
|
||||||
|
public:
|
||||||
|
ES08A (int pin);
|
||||||
|
~ES08A ();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
7
src/servo/jsupm_es08a.i
Normal file
7
src/servo/jsupm_es08a.i
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
%module jsupm_es08a
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "es08a.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "es08a.h"
|
8
src/servo/pyupm_es08a.i
Normal file
8
src/servo/pyupm_es08a.i
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
%module pyupm_es08a
|
||||||
|
|
||||||
|
%feature("autodoc", "3");
|
||||||
|
|
||||||
|
%include "es08a.h"
|
||||||
|
%{
|
||||||
|
#include "es08a.h"
|
||||||
|
%}
|
88
src/servo/servo.cxx
Normal file
88
src/servo/servo.cxx
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||||
|
* Copyright (c) 2014 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "servo.h"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
Servo::Servo (int pin) {
|
||||||
|
maa_result_t error = MAA_SUCCESS;
|
||||||
|
|
||||||
|
m_maxAngle = 180.0;
|
||||||
|
m_servoPin = pin;
|
||||||
|
m_pwmServoContext = maa_pwm_init (m_servoPin);
|
||||||
|
}
|
||||||
|
|
||||||
|
Servo::~Servo () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* X = between (MIN_PULSE_WIDTH , MAX_PULSE_WIDTH)
|
||||||
|
*
|
||||||
|
* X usec
|
||||||
|
* _______
|
||||||
|
* |_______________________________________
|
||||||
|
* 20000 usec
|
||||||
|
*
|
||||||
|
* Max period can be only 7968750(nses) which is ~8(msec)
|
||||||
|
* so the servo wil not work as expected.
|
||||||
|
* */
|
||||||
|
maa_result_t Servo::setAngle (int angle) {
|
||||||
|
if (m_pwmServoContext == NULL) {
|
||||||
|
std::cout << "PWM context is NULL" << std::endl;
|
||||||
|
return MAA_ERROR_UNSPECIFIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
maa_pwm_enable (m_pwmServoContext, 1);
|
||||||
|
for (int cycles = 0; cycles < 128; cycles++) {
|
||||||
|
maa_pwm_period_us (m_pwmServoContext, MAX_PERIOD);
|
||||||
|
maa_pwm_pulsewidth_us (m_pwmServoContext, calcPulseTraveling(angle));
|
||||||
|
}
|
||||||
|
maa_pwm_enable (m_pwmServoContext, 0);
|
||||||
|
|
||||||
|
std::cout << "angle = " << angle << " ,pulse = " << calcPulseTraveling(angle) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculating relative pulse time to the value.
|
||||||
|
* */
|
||||||
|
int Servo::calcPulseTraveling (int value) {
|
||||||
|
// if bigger than the boundaries
|
||||||
|
if (value > m_maxAngle) {
|
||||||
|
return MAX_PULSE_WIDTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if less than the boundaries
|
||||||
|
if (value < 0) {
|
||||||
|
return MIN_PULSE_WIDTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the conversion
|
||||||
|
return (int) ((float)MIN_PULSE_WIDTH + ((float)value / m_maxAngle) * ((float)MAX_PULSE_WIDTH - (float)MIN_PULSE_WIDTH));
|
||||||
|
}
|
58
src/servo/servo.h
Normal file
58
src/servo/servo.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
||||||
|
* Copyright (c) 2014 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <maa/pwm.h>
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
|
#define MIN_PULSE_WIDTH 600
|
||||||
|
#define MAX_PULSE_WIDTH 2500
|
||||||
|
#define MAX_PERIOD 7968
|
||||||
|
|
||||||
|
#define HIGH 1
|
||||||
|
#define LOW 0
|
||||||
|
|
||||||
|
class Servo {
|
||||||
|
public:
|
||||||
|
Servo (int pin);
|
||||||
|
~Servo();
|
||||||
|
maa_result_t setAngle (int angle);
|
||||||
|
|
||||||
|
std::string name()
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
int calcPulseTraveling (int value);
|
||||||
|
|
||||||
|
std::string m_name;
|
||||||
|
int m_servoPin;
|
||||||
|
float m_maxAngle;
|
||||||
|
maa_pwm_context m_pwmServoContext;
|
||||||
|
// maa_gpio_context m_servoPinCtx;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user