[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Paparazzi-devel] Scaling factor: uint16_t into float

From: Gautier Hattenberger
Subject: Re: [Paparazzi-devel] Scaling factor: uint16_t into float
Date: Fri, 17 Oct 2008 13:59:39 +0200
User-agent: Thunderbird (X11/20080925)

If you want to use the last option (not the easiest one, writing an Ivy agent is probably a better solution...), you can use the adc_generic service to read the adc value. Then:

- define a message, for example:
   <message name="BC" id="__">
      <field name="scaled_adc" type="float" format="%.2f"/>

- write a header in sw/airborne (bc.h) with at least:
   #include "adc_generic.h"
   #include "ap_downlink.h"

   extern void send_val_bc();

- write the c file (bc.c):
   #include "bc.h"

   void send_val_bc() {
      float v = (float)adc_generic_val1 / 208.3;  (or adc_generic_val2)

- add the c file to the makefile part of the airframe conf file:
   ap.srcs += bc.c

- in your flight plan add a header section and use pre_call in the blocks during which you want to receive data:
   #include "bc.h"

   <block name="___" pre_call="send_val_bc()">

You should receive the scaled values at 4Hz when your flying in a block that call your function.

This should work (unless I've missed some dependencies...).

Good luck


Brendan Chen a écrit :
Hi Gautier,

Yea the last option is exactly what im doing. I've got the message showing on 
gnd station after adding a new tab in the messages.xml and all, but I used the 
ADC_GENERIC utility set to read the ADC (not sure if you call that cheating 
because I dont know how to set my own set of code for it to read the ADC from 

Now my problem is that I can get the ADC data reading and its displaying a 3 
digit integer (uint16_t I presume), but now I want that to display in a 2 
decimal place floating number.

How would I scale that uint16_t raw number to the floating point number I want?


From: address@hidden address@hidden On Behalf Of Gautier Hattenberger 
Sent: Thursday, 16 October 2008 10:05 PM
To: address@hidden
Subject: Re: [Paparazzi-devel] Scaling factor: uint16_t into float

The ADC uses a 10 bits converter. So it gives values between 0 (0V) and
1023 (3V, unless you use adc 5 or 6 of a Tiny2.x).

For your problem, it all depends of the way you want to use these values.
- You can display them in a real time plotter with a scaling factor.
- You can use the values in the log file after your flight.
- You can write a small Ivy agent (C,Ocaml) that read the values coming
from the telemetry and do whatever you want.
- You can write a piece of airborne code that reads the adc value,
define a new message and send it to the ground.


Brendan Chen a écrit :
Hi all,

Anyone know where and how to convert the downlinked ADC_GENERIC value into a 
more meaningful value?

I could be wrong but from what i understand, the ADC_GENERIC function returns a 
uint16_t value... I would like to scale that down by a factor of 208.3 
(adc_generic_val1 / 208.3) and give a return in 2 decimal float number.

How and where would I do that?


Paparazzi-devel mailing list

Paparazzi-devel mailing list

Paparazzi-devel mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]