Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 3rd November 2009, 10:10 PM   #1
Default Writing an API

I'm part of a project building an autonomous quad-rotor UAV. my job is the electronics hardware and firmware. I want to provide an API to the guys doing the algorithmic programming (to make it actually be autonomous) so that they don't have to deal with hardware when they need to read a sensor or change a motor's speed. We have a 3-axis accelerometer and a 3-axis gyro, plus a barometric pressure sensor, ultrasonic sounder and stereo ccd cameras.

How do you go about writing an API for an embedded processor? Their code will be (most of) the main program running on the processor

Can they just use variable types like int, char, bool, etc in their program, or do they need to use processor-specific types? (i'm assuming processor specific)

Thanks guys. I'm kind of flying blind with the api, no pun intended
galed is online now  
Old 3rd November 2009, 11:34 PM   #2
Default

They can and should use familiar data types. If I were you, I would think about implementing a client server model with message passing as the primary method of passing information. In this fashion you can hide practically all of the details that the algorithm developers don't need to worry about.

Let me know what I can do to help you get where you need to be.
__________________
We never have time to do it right; but we always have time to do it over.

Last edited by Papabravo; 3rd November 2009 at 11:35 PM.
Papabravo is offline  
Old 4th November 2009, 03:24 AM   #3
Default

what do you mean by the client/server model?
galed is online now  
Old 4th November 2009, 04:10 AM   #4
Default

Assuming this is a nonthreaded, DSP microcontroller, I'm not sure the "interface" will meet the definition of an API.

You can (must) write in structured, well documented tasks in either C or assembly for strong, flexible reuse. In C, the int and char type are definitely used, as are structs. C is used all the time, but high-performance numerically intensive stuff needs frequently requires assembly. But, asm tasks can actually be called from C. For dsPICs, the true DSP ops using the Accumulator won't even be invoked by standard C math, although there are some built-in special-purpose function calls which can invoke the DSP core ops for specific jobs.

But you cannot let in application developers who aren't familiar the controller used. For example, the "fractional" type is very powerful on dsPIC controllers, but float/double are a slow boondoogle to avoid at any cost. Developers need to understand how interrupts may change data mid-calculation.

What controller are you looking at?
__________________
I thought what I'd do was I'd pretend I was one of those deaf-mutes.

Last edited by Oznog; 4th November 2009 at 04:14 AM.
Oznog is offline  
Old 4th November 2009, 04:30 AM   #5
Default

i guess by API what i meant was that I want to provide some functions (get_accel(), set_motor(motor,speed), etc) so that they can interface with the hardware without dealing with the hardware itself.

These guys doing the algorithm stuff are all (as a friend put it) from "computer science la la land." They're not really used to working with micros. How to deal with that?

Not sure on the controller yet. I was thinking about using an ATXmega but i'm willing to go to something else. ARM7's crossed my radar too
galed is online now  
Old 4th November 2009, 05:44 AM   #6
Default

In a client server model there are two entities. The client sends requests and receives responses. The other endpoint, called a server receives requests and sends responses. It is not necessary for either the client or the server to know anything about the other. It is only necessary for them to know how to talk to each other. They could be running on the same machine or different machines connected by some kind of nework. In the case that client and server run ondifferent machines one could be written in assembly language and one could be written in Java. What is important is that both endpoints must agree on both the syntax, and the semantics of the messages that are exchanged.

If both are running on the same machine it provides a very clean framework for interprocess communications and is well suited to OO techniques. This beats the pure hell out of trying to remember a large library of function calls each with its own list of parameters and return values -- IMHO.
__________________
We never have time to do it right; but we always have time to do it over.

Last edited by Papabravo; 4th November 2009 at 05:46 AM.
Papabravo is offline  
Old 4th November 2009, 07:35 AM   #7
Default

Quote:
Originally Posted by galed View Post
i guess by API what i meant was that I want to provide some functions (get_accel(), set_motor(motor,speed), etc) so that they can interface with the hardware without dealing with the hardware itself.

These guys doing the algorithm stuff are all (as a friend put it) from "computer science la la land." They're not really used to working with micros. How to deal with that?

Not sure on the controller yet. I was thinking about using an ATXmega but i'm willing to go to something else. ARM7's crossed my radar too
Well, "how to deal with that" is someone has to know micros. Either they explain what needs to happen and someone interprets the task into microcontroller code, or they need to understand it.

In many cases a BASIC-like "get_something()" sequential task just isn't efficient. The ADC, for example, would need to be set up, left in acquisition time, then converted. This not only takes up an unnecessary amount of time if the code just waits on these steps, the spacing of the ADC samples may be irregular. More often we like to configure the ADC to automatically collect readings and an adc_done interrupt allows the program to access them in an orderly fashion. The ISR might store the ADC reading in a buffer and get_ADC() retrieves it, but even this may be an inefficient type of solution. If the system is demanding of performance- and it kinda sounds like it- then it may not be able to afford sloppy programming.

So that's the thing. You generally can't just use an interface to make computer-science guys' code which wasn't written for a microcontroller to work well on a microcontroller. Learning new skills is essential to being "good". Assuming this is a class project, that was kind of the point.
__________________
I thought what I'd do was I'd pretend I was one of those deaf-mutes.

Last edited by Oznog; 4th November 2009 at 07:39 AM.
Oznog is offline  
Old 4th November 2009, 04:36 PM   #8
Default

Some of the decisions depend on the hardware you are using. If this is a single processor doing all the work then just a subroutine library might be good. As things get bigger maybe client server would make sense. Will all the computing be done on one uc?
Russ Hensel is offline  
Old 5th November 2009, 01:03 AM   #9
Default

How are they communicating with mcu? Are they writing code on it or for pc?
AtomSoft is offline  
Old 5th November 2009, 03:58 AM   #10
Default

Quote:
Originally Posted by Papabravo View Post
In a client server model there are two entities. The client sends requests and receives responses. The other endpoint, called a server receives requests and sends responses. It is not necessary for either the client or the server to know anything about the other. It is only necessary for them to know how to talk to each other. They could be running on the same machine or different machines connected by some kind of nework. In the case that client and server run ondifferent machines one could be written in assembly language and one could be written in Java. What is important is that both endpoints must agree on both the syntax, and the semantics of the messages that are exchanged.

If both are running on the same machine it provides a very clean framework for interprocess communications and is well suited to OO techniques. This beats the pure hell out of trying to remember a large library of function calls each with its own list of parameters and return values -- IMHO.
Client/server seems like an option. They'd be running on the same chip. My biggest worry is that this has to be real-time. How would scheduling work?

Quote:
Some of the decisions depend on the hardware you are using. If this is a single processor doing all the work then just a subroutine library might be good. As things get bigger maybe client server would make sense. Will all the computing be done on one uc?
I'd really like it to be a single processor. If that can't happen, so be it. As of right now, it is one processor

Quote:
Well, "how to deal with that" is someone has to know micros. Either they explain what needs to happen and someone interprets the task into microcontroller code, or they need to understand it.

In many cases a BASIC-like "get_something()" sequential task just isn't efficient. The ADC, for example, would need to be set up, left in acquisition time, then converted. This not only takes up an unnecessary amount of time if the code just waits on these steps, the spacing of the ADC samples may be irregular. More often we like to configure the ADC to automatically collect readings and an adc_done interrupt allows the program to access them in an orderly fashion. The ISR might store the ADC reading in a buffer and get_ADC() retrieves it, but even this may be an inefficient type of solution. If the system is demanding of performance- and it kinda sounds like it- then it may not be able to afford sloppy programming.

So that's the thing. You generally can't just use an interface to make computer-science guys' code which wasn't written for a microcontroller to work well on a microcontroller. Learning new skills is essential to being "good". Assuming this is a class project, that was kind of the point.
Well, it's looking like the electronics team and the software team are almost the same set of people. What I was thinking for the ADCs (which take in all the sensor values) was to get a maximum update rate from the software team and setting up a timer/counter match interrupt to run and store all the conversion values in memory at least as quickly as they'd need it. The get_value() functions would simply return the most recent value.

Quote:
How are they communicating with mcu? Are they writing code on it or for pc?
they're writing code directly for the micro

Quote:
Assuming this is a nonthreaded, DSP microcontroller, I'm not sure the "interface" will meet the definition of an API.
Got any recommendations of a DSP micro?
galed is online now  
Reply

Tags
api, writing

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Writing to TMR0 eng1 Micro Controllers 8 27th July 2009 09:05 PM
PIC 18F4550 and the evil USB api TiagoSilva Micro Controllers 2 28th January 2009 06:36 PM
nd help in writing the following program... zak4546 Micro Controllers 5 17th March 2008 05:41 PM
Please help me in writing code abdosat2000 Micro Controllers 9 5th June 2007 02:41 PM
mplab plugin api bluex_scf Micro Controllers 0 24th April 2005 07:35 PM



All times are GMT. The time now is 03:33 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker