sensor values in stabilizer.c

Firmware/software/electronics/mechanics
Post Reply
mannaris
Beginner
Posts: 23
Joined: Tue Oct 13, 2015 6:05 pm

sensor values in stabilizer.c

Post by mannaris »

Hi,
I hope someone can help me with my goal. I want to include my infrarot sensor value in the stabilizer.c file for reaching that the sensor values enable the motor. I have include the parameter to enable the motors abd I have the driver from the sensor.

my sensor driver

Code: Select all

#include "deck.h"

#include "log.h"

#include "FreeRTOS.h"
#include "timers.h"

static xTimerHandle timer;
static float range;




void SensorValue(xTimerHandle timer)
{
   range=analogRead(DECK_GPIO_TX2);
}

void mySensorInit(DeckInfo *info)
{
  pinMode(DECK_GPIO_TX2,INPUT); 

  
  timer = xTimerCreate("irsensorTmr", M2T(100), pdTRUE, NULL, SensorValue);
  xTimerStart(timer, 100);
}

static const DeckDriver mySensor_driver = {
  .name = "myIrSensors",

  .usedGpio = DECK_USING_TX2,
  .init = mySensorInit
};

DECK_DRIVER(mySensor_driver);


LOG_GROUP_START(myIrSensors)
LOG_ADD(LOG_FLOAT, range, &range)
LOG_GROUP_STOP(myIrSensors)

what should i do that my range variable is defined in stabilizer.c?
vivekrk44
Beginner
Posts: 7
Joined: Sun Nov 23, 2014 6:17 pm

Re: sensor values in stabilizer.c

Post by vivekrk44 »

What i would suggest is to define a global variable that holds the value that you want transmitted. So in your sensor driver code add

float dat;

dat will contain the relevant data. Next add a function that returns the required data

float getData()
{
return dat;
}

define this function in the header file of your driver

Then include the header fine in the stabilizer.c file and call the getData function.

Let me know if you have understood this method

Regards
Vivek
mannaris
Beginner
Posts: 23
Joined: Tue Oct 13, 2015 6:05 pm

Re: sensor values in stabilizer.c

Post by mannaris »

Thank you very much for your help!
I understand your point and i have tried to include it.
I type this in the driver:

Code: Select all

float dat;
dat=5;
getData(dat);
This is my header.h file:

Code: Select all

float getData(dat)
{
return dat;
}
I included the header in both files.

but i get this error:

Code: Select all

21:41:17 **** Build of configuration Build (GNU) for project crazyflie-firmware ****
make all DEBUG=0 CLOAD=1 
  CLEAN_VERSION
  VTMPL version.c
  CC    version.o
  CC    infrarot.o
deck/drivers/src/infrarot.c:13:1: warning: data definition has no type or storage class
 dat=5;
 ^
deck/drivers/src/infrarot.c:13:1: warning: type defaults to 'int' in declaration of 'dat' [-Wimplicit-int]
deck/drivers/src/infrarot.c:13:1: error: conflicting types for 'dat'
tools/make/targets.mk:26: recipe for target 'infrarot.o' failed
deck/drivers/src/infrarot.c:12:7: note: previous declaration of 'dat' was here
 float dat;
       ^
deck/drivers/src/infrarot.c:14:1: warning: data definition has no type or storage class
 getData(dat);
 ^
deck/drivers/src/infrarot.c:14:1: warning: type defaults to 'int' in declaration of 'getData' [-Wimplicit-int]
deck/drivers/src/infrarot.c:14:1: warning: parameter names (without types) in function declaration
deck/drivers/src/infrarot.c:14:1: error: conflicting types for 'getData'
In file included from deck/drivers/src/infrarot.c:4:0:
./header.h:1:7: note: previous definition of 'getData' was here
 float getData(dat)
       ^
make: *** [infrarot.o] Error 1

21:41:18 Build Finished (took 697ms)

chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: sensor values in stabilizer.c

Post by chad »

Code: Select all

#include <math.h>
?
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
mannaris
Beginner
Posts: 23
Joined: Tue Oct 13, 2015 6:05 pm

Re: sensor values in stabilizer.c

Post by mannaris »

ok i will try it.

but today as i cload my firmaware i received this error:

Code: Select all

22:25:01 **** Build of configuration Build (GNU) for project crazyflie-firmware ****
make all DEBUG=0 CLOAD=1 
ERROR: One or more of the git submodules are not initialized. Try
make: *** [check_submodules] Error 255
    git submodule init
    git submodule update
Makefile:357: recipe for target 'check_submodules' failed

22:25:02 Build Finished (took 829ms)
what have i done wrong?
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: sensor values in stabilizer.c

Post by chad »

mannaris wrote:what have i done wrong?
Nothing you've done wrong but this is the problem.
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
mannaris
Beginner
Posts: 23
Joined: Tue Oct 13, 2015 6:05 pm

Re: sensor values in stabilizer.c

Post by mannaris »

Post Reply