Hi,

I need to switch led On/OF form autopilot, in every 5 min (without radio).

If i managed to change code(arduplane 2,65)  to make: relay_on() relay_off() every 5 min , then what PIN dose that correspond to?


Or how can i make costum PIN output? (for relay, or optron)

 

Tags: code, relay

Views: 533

Reply to This

Replies to This Discussion

Hello Mell,

I found this in the system.pde:

#if CONFIG_RELAY == ENABLED
    DDRL |= B00000100;     // Set Port L, pin 2 to output for the relay
#endif

This is Digital pin 47

In the Eagle files I could find any connection to this pin !

I'm afraid this connection is cancelled on the APM2 and APM2.5 boards !

I think it's easier and more safe to use a Arduino Nano board or similar.

Nano V3.0 board

You can easily change that 3 functions to alter the pin of your choice. Then just upload your custom firmware to APM.

Can you give me a simple code example. 

Thx :)

Take a look at file libraries/AP_Relay/AP_Relay.cpp.

You can see there a bunch of methods that operate on PL2 (port L, pin 2). I can confirm what Marten already found that this pin looks unconnected on APM2 but you could modify that code to alter one of AN pins located on APM2 board.

For example:

digitalWrite(AN5, HIGH);

I just found out that digitalWrite is MUCH slower than accessing pin directly but for your purpose you could stick with that.

It isn't that simple...

AN5 is used for the COPTER_LEDs !

I think this will work when you add this in APM_Config.pde:

////////////////////////////////////////////////////////
// LED and IO Pins
//
#if CONFIG_APM_HARDWARE == APM_HARDWARE_APM1
 # define A_LED_PIN        37
 # define B_LED_PIN        36
 # define C_LED_PIN        35
 # define LED_ON           HIGH
 # define LED_OFF          LOW
 # define SLIDE_SWITCH_PIN 40
 # define PUSHBUTTON_PIN   41
 # define USB_MUX_PIN      -1
 # define CLI_SLIDER_ENABLED DISABLED
 # define OPTFLOW_CS_PIN   34
 # define BATTERY_PIN_1      0
 # define CURRENT_PIN_1      1
#elif CONFIG_APM_HARDWARE == APM_HARDWARE_APM2
 # define A_LED_PIN        27
 # define B_LED_PIN        26
 # define C_LED_PIN        25
 # define LED_ON           LOW
 # define LED_OFF          HIGH
 # define SLIDE_SWITCH_PIN (-1)
 # define PUSHBUTTON_PIN   (-1)
 # define CLI_SLIDER_ENABLED DISABLED
 # define USB_MUX_PIN      23
 # define OPTFLOW_CS_PIN   A3
 # define BATTERY_PIN_1      1
 # define CURRENT_PIN_1      2
 # define RELAY                     59 // is AN5
#endif

#define pinMode(RELAY, OUTPUT);
////////////////////////////////////////////////////////////////////////////////
// CopterLEDs
//

#ifndef COPTER_LEDS
 #define COPTER_LEDS DISABLED
#endif

Here I Disabled the COPTER_LEDs and defined RELAY to digital pin 59 which is defined as a output.

Now you can use RELAY in your own sketch with a timer function.

Well, sorry not to mention that. Somehow it was obvious for me that this is necessary
#define COPTER_LEDS DISABLED
Thanks for updating.

No problem dude :-)

For me it's also still Try and error :-)

The reason why COPTER_LEDs need to be disabled is this,

in the system.pde you will find this:

#if COPTER_LEDS == ENABLED
    pinMode(COPTER_LED_1, OUTPUT);              //Motor LED
    pinMode(COPTER_LED_2, OUTPUT);              //Motor LED
    pinMode(COPTER_LED_3, OUTPUT);              //Motor LED
    pinMode(COPTER_LED_4, OUTPUT);              //Motor LED
    pinMode(COPTER_LED_5, OUTPUT);              //Motor or Aux LED
    pinMode(COPTER_LED_6, OUTPUT);              //Motor or Aux LED
    pinMode(COPTER_LED_7, OUTPUT);              //Motor or GPS LED
    pinMode(COPTER_LED_8, OUTPUT);              //Motor or GPS LED

    if ( !bitRead(g.copter_leds_mode, 3) ) {
        piezo_beep();
    }
#endif

Thank you for answers!

(note: this is my 2nd ever arducode, so I waid for feedback)

I have an ArduPlane, so I dont heave the COPTER_LEDs

I did not find "APM_Config.pde", I found "APM_Config.h"

and APM_config.h says:

...

// This file is just a placeholder for your configuration file. If
// you wish to change any of the setup parameters from their default
// values, place the appropriate #define statements here.

...

And your code seems to be from config.h, which says:

...

 

// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
//
// DO NOT EDIT this file to adjust your configuration. Create your own
// APM_Config.h and use APM_Config.h.example as a reference.
//
// WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
...

So I write on blank page (everything commented out) (APM_config.h)?, so I did  :

I defined analog 8 to be output (61 according to this) in :

# define RELAY            61 // is AN8

#define pinMode(RELAY, OUTPUT);

And in  arduplane.pde I made some robust? changes:

original:

static void one_second_loop()
{

if (g.log_bitmask & MASK_LOG_CUR)
Log_Write_Current();

// send a heartbeat
gcs_send_message(MSG_HEARTBEAT);
}

My cahnges:

int sec=0; //added sec integer
static void one_second_loop()
{

if (sec==300){   //after 5 min
analogWrite(RELAY, 255);} // hold the an8 at 5v 

if (sec==305){                  
analogWrite(RELAY, 0); sec=0;}   //hold 5v for 5 sek, and reset integer sec back to 0.


if (g.log_bitmask & MASK_LOG_CUR)
Log_Write_Current();


// send a heartbeat
gcs_send_message(MSG_HEARTBEAT);
sec=sec++;  //add +1 on every loop
}

analogWrite(RELAY, 255)

analogWrite(RELAY, 0)

is the same as

digitalWrite(RELAY, HIGH)

digitalWrite(RELAY, LOW)

but looks more obvious what is should do.

sec=sec++;  //add +1 on every loop

sec++ is the same as

sec = sec + 1;

so sec++ is enough;

I think your int sec=0; position is not correct !

This things must be done before void loop() and are also done in a for statement.

A better place is to put them somewhere what is most closed to the goal...

I would place it in System Timers.

You will find this in Arduplane.pde at line 626:

////////////////////////////////////////////////////////////////////////////////
// System Timers
////////////////////////////////////////////////////////////////////////////////
// Time in miliseconds of start of main control loop.  Milliseconds
static uint32_t fast_loopTimer_ms;

// Time Stamp when fast loop was complete.  Milliseconds
static uint32_t fast_loopTimeStamp_ms;

// Number of milliseconds used in last main loop cycle
static uint8_t delta_ms_fast_loop;

// Counter of main loop executions.  Used for performance monitoring and failsafe processing
static uint16_t mainLoop_count;

// Time in miliseconds of start of medium control loop.  Milliseconds
static uint32_t medium_loopTimer_ms;

// Counters for branching from main control loop to slower loops
static byte medium_loopCounter;
// Number of milliseconds used in last medium loop cycle
static uint8_t delta_ms_medium_loop;

// Counters for branching from medium control loop to slower loops
static byte slow_loopCounter;
// Counter to trigger execution of very low rate processes
static byte superslow_loopCounter;
// Counter to trigger execution of 1 Hz processes
static byte counter_one_herz;
unsigned int sec = 0; // set the 5 minutes counter to zero
///////////////////////////////////////////////////////////////////////////////

And is the loop I would try this: (as Marooned already says)

static void one_second_loop()
{
 if (sec == 300){   //after 5 min
 digitalWrite(RELAY, HIGH);} // hold digital pin 61 HIGH

if (sec == 305){                  
digitalWrite(RELAY, LOW); sec=0;}// digital pin 61 gets LOW after 5 sek, and reset integer sec back to 0.

if (g.log_bitmask & MASK_LOG_CUR)
Log_Write_Current();

// send a heartbeat
gcs_send_message(MSG_HEARTBEAT);

sec++;  //add +1 on every loop
}

One way would be to use jD-IOBoard that already supports MAVLink to driver relays and other things. I think I will make driving relays optional on next firmware for it. IOBoard have full support for ArduCopter and MAVLink protocol. 

RSS

Social Networking

Contests

Season Two of the Trust Time Trial (T3) Contest has now begun. The fourth round is an accuracy round for multicopters, which requires contestants to fly a cube. The deadline is April 14th.

A list of all T3 contests is here

Groups

Advertisement

© 2013   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service