Skip to content

Commit

Permalink
Module with servo tester function (#2001)
Browse files Browse the repository at this point in the history
useful for identifying the response of a servo
  • Loading branch information
EwoudSmeur authored and flixr committed Feb 12, 2017
1 parent 498c326 commit 6ffd819
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
36 changes: 36 additions & 0 deletions conf/modules/servo_tester.xml
@@ -0,0 +1,36 @@
<!DOCTYPE module SYSTEM "module.dtd">

<module name="servo_tester" dir="servo_tester">
<doc>
<description>
Servo tester
Has a setting to change the input to the servo in millisecond units.

You have to give the servo you want to test the name SERVO_TEST, and don't use
it in the command laws.

Additionally, you can make the servo do a series of step maneuvers, with increasing
amplitude. Tip: Open up the servo and measure the voltage on the potmeter with
a high speed recorder device (like a saleae Logic analyzer with analog inputs). This
will let you model the response of the servo.
</description>
<define name="TIME_PER_DEFLECTION" value="0.8" description="Time between servo steps for the 'servo_run' feature"/>
</doc>
<settings>
<dl_settings NAME="Servo test">
<dl_settings NAME="Servo tester">
<dl_setting var="servo_test_val" min="1000" step="1" max="2000" module="modules/servo_tester/servo_tester" shortname="servo_input"/>
<dl_setting var="do_servo_run" min="0" step="1" max="1" module="modules/servo_tester/servo_tester" values="Off|On" shortname="servo_run"/>
</dl_settings>
</dl_settings>
</settings>
<header>
<file name="servo_tester.h"/>
</header>
<init fun="servo_tester_init()"/>
<periodic fun="servo_tester_periodic()" freq="512"/>
<makefile>
<file name="servo_tester.c"/>
</makefile>
</module>

83 changes: 83 additions & 0 deletions sw/airborne/modules/servo_tester/servo_tester.c
@@ -0,0 +1,83 @@
/*
* Copyright (C) 2012 Ewoud Smeur <ewoud_smeur@msn.com>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/

/** @file modules/servo_tester/servo_tester.c
* Module that has a setting to change the input to a servo
* Call the servo that you want to test SERVO_TEST,
* and don't use it with the command laws
*/

#include "servo_tester.h"
#include "subsystems/commands.h"
#include "generated/airframe.h"
#include "generated/airframe.h"
#include "subsystems/actuators.h"

int32_t servo_test_val;

bool do_servo_run;
int32_t servo_run_counter;
int32_t servo_run_timer;
int32_t servo_run_step;

#ifndef TIME_PER_DEFLECTION
/** Time in seconds per deflection, before going to the next */
#define TIME_PER_DEFLECTION 0.8
#endif

int32_t servo_mean;

void servo_tester_init()
{
servo_test_val = SERVO_SERVO_TEST_NEUTRAL;
do_servo_run = false;
servo_run_counter = 0;
servo_run_timer = 0;
servo_run_step = (SERVO_SERVO_TEST_MAX - SERVO_SERVO_TEST_MIN) / 2 / 8;

servo_mean = SERVO_SERVO_TEST_NEUTRAL;
}


void servo_tester_periodic()
{

/*Go up and down with increasing amplitude*/
if (do_servo_run && (servo_run_counter < 8)) {
servo_test_val = servo_mean + servo_run_counter * servo_run_step * ((servo_run_counter % 2) * 2 - 1);
servo_run_timer += 1;

/*Give time to reach the setpoint*/
if (servo_run_timer > (TIME_PER_DEFLECTION*SERVO_TESTER_PERIODIC_FREQ)) {
servo_run_timer = 0;
servo_run_counter += 1;
}
} else if (do_servo_run == true) {
/*Reset de servo run*/
do_servo_run = false;
servo_run_counter = 0;
servo_test_val = servo_mean;
}

Bound(servo_test_val, SERVO_SERVO_TEST_MIN, SERVO_SERVO_TEST_MAX);
Set_SERVO_TEST_Servo(servo_test_val);
}

38 changes: 38 additions & 0 deletions sw/airborne/modules/servo_tester/servo_tester.h
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2012 Ewoud Smeur <ewoud_smeur@msn.com>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/

/** @file modules/servo_tester/servo_tester.h
*
* Module useful for testing a servo and finding the response
*/

#ifndef SERVO_TESTER_H
#define SERVO_TESTER_H

#include "generated/airframe.h"

extern int32_t servo_test_val;
extern bool do_servo_run;

void servo_tester_init(void);
void servo_tester_periodic(void);

#endif /* SERVO_TESTER_H */

0 comments on commit 6ffd819

Please sign in to comment.