paparazzi-devel
[Top][All Lists]
Advanced

[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 2.0.0.17 (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"/>
   </message>

- 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)
      DOWNLINK_SEND_BC(&v);
   }

- 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:
   <header>
   #include "bc.h"
   </header>

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

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

Gautier

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 
scratch).

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?


Thanks
Brendan

________________________________________
From: address@hidden address@hidden On Behalf Of Gautier Hattenberger 
address@hidden
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.

Gautier


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?


Thanks
Brendan


_______________________________________________
Paparazzi-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/paparazzi-devel



_______________________________________________
Paparazzi-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/paparazzi-devel


_______________________________________________
Paparazzi-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/paparazzi-devel




reply via email to

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