I making a Localization project Using Arduino and Xbee Zg where i need to measure time in nano second resolution im using arduino due board with 84 Mhz clock and arduino 1.5.2 IDE
im trying to use clock_gettime function i already included time.h but i get the same
compiling error
clock_gettime
is not declared in this scope
this is just a part of my Distance_Measurement.c file
#include "Distance_Measurement.h"
#include "time.h"
struct timespec start, stop;
bool Start_Time()
{
if(clock_gettime(CLOCK_REALTIME,&start) == -1)
return false;
else
return true;
}
bool Stop_Time()
{
if(clock_gettime(CLOCK_REALTIME,&stop) == -1)
return false;
else
return true;
}
double Cal_Time_Nano()
{
return (stop_time.tv_nsec - start_time.tv_nsec);
}
please help me
i first used #include i got the same error i have found that visual studio have included anther time.h not time.h in arduino gcc so i copied the last one and pasted it to arduino libraries path with my distance measurement library – PrinceOfEgy
Related
I'm new in Embedded systems I am using "atmel Studio7" so I opened ASF wizard T_C driver for xmega128a1 and modified it to set just the timer TCC0 to count 50 ms and throw an overflow flag every 50 ms beside I commented other timers,
I tried to compile but I have one error and I can't correct it the error is: "expected declaration or statement at end of input".
which located in this segment of the code:
void tc_set_ccd_interrupt_callback(volatile void *tc, tc_callback_t callback)
{
#ifdef TCC0
if ((uintptr_t) tc == (uintptr_t) & TCC0)
{
tc_tcc0_ccd_callback = callback;
}
else
#endif
}
anyone have an idea or advise.
Remove the else word. It expects a new statement after it, which you do not have
I coded a simple application using SDL which displays a simple window on Windows 8 (64 bits). In a first time I compiled and executed my code with Win32 configuration (default configuration) and the program works perfectly. Now I want to have the same execution but this time with x64 configuration. So I configured Visual using 'configurations manager' in my project properties and change my SDL.lib and SDLmain.lib choosing x64 libraries in the linker. The project compilation is ok but the execution fails saying that the application has failed to start properly. Here's a screen of the message (the memory address is always the same at each execution) :
And my c++ code :
#include <iostream>
#include <SDL/SDL.h>
#include <GL/glew.h>
#include <GL/glu.h>
#define WIDTH 500
#define HEIGHT 500
static float angle = 0.0f;
static void eventListener(SDL_Event *pEvent, bool *pContinue)
{
while (SDL_PollEvent(pEvent))
{
switch(pEvent->type)
{
case SDL_QUIT:
*pContinue = false;
break;
case SDL_KEYDOWN:
switch (pEvent->key.keysym.sym)
{
case SDLK_ESCAPE:
*pContinue = false;
break;
}
break;
}
}
}
#undef main
int main(void)
{
SDL_Event myEvent;
bool isAlive = true;
SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("Simple SDL window", NULL);
SDL_SetVideoMode(WIDTH, HEIGHT, 32, SDL_OPENGL);
while (isAlive == true)
{
eventListener(&myEvent, &isAlive);
}
SDL_Quit();
return (0);
}
I don't understand this message which is not precise. However my x64 SDL libraries linked to my project seems to be correct because the compilation is ok. So I wonder what's happening here. Does anyone already have encountered the same problem ?
Just googled for your error message, and it says that this error code (0x0c000007b) means INVALID_IMAGE_FORMAT.
This means that either you are mixing 32 and 64 bit binaries or you have corrupted binaries. Try to place you binary and your dependencies at the same folder and run the application. If the error continues, than one of your libraries must be corrupted. Else, it was a problem with the Windows loading a library for a different platform of your compiled binary.
I am trying to run the following code snippet taken from this simple example of a timer:
#include <sys/time.h>
#include <stdio.h>
int SetTimer(struct timeval &tv, time_t sec) {
gettimeofday(&tv, NULL);
tv.tv_sec += sec;
return 1;
}
int CheckTimer(struct timeval &tv, time_t sec) {
struct timeval ctv;
gettimeofday(&ctv, NULL);
if ((ctv.tv_sec > tv.tv_sec)) {
gettimeofday(&tv, NULL);
tv.tv_sec += sec;
return 1;
} else {
return 0;
}
}
int main() {
struct timeval tv;
SetTimer(tv, 5); //set up a delay timer
printf("start counting.\n");
while (1)
if (CheckTimer(tv, 5) == 1)
printf("Welcome to cc.byexamples.com\n");
return 0;
}
I am obtaining the following error: field tv_sec could not be resolved
I have searched for it on the Web but no one seems to give a concrete answer.
I tried my chance looking into the libraries sys/time.h and time.h but in none of them seems to be defined this structure but is anyway used.
Am I missing any library? Since this example is rather old, did something changed that needs it to be done in a different way? I would appreciate any sight.
PS: I am using Eclipse CDT Indigo under Ubuntu 11.10 and g++ 4.6.1.
try to put this in your file : #define __USE_GNU
In the end it was an Eclipse problem since it was unable to index the time.h library. I solved it by following the most upvoted answer of this other SF question:
Adding manually time.h to the C/C++ indexer.
Currently I am using Eclipse CDT Juno and the problem doesn't seems not to be happening anymore. As a side comment in Eclipse CDT Juno I couldn't find the location where to manually edit the C/C++ indexer settings.
I just recently started playing around with SFML and I wrote this simple program.
I'm using visual studio 2010 btw.
The program compiles and runs fine when using the "start debugging" option.
but if I open the .exe file as if I was running a normal desktop application or something, it will crash on exit.
I've spent a while trying to figure it out but all I can say is that it's probably a heap corruption.
here's all the code:
#include <iostream>
#include <sstream>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
void moveSquare();
void avgFPS();
class displayFPS : public sf::Thread{
public:
private:
virtual void Run();
};
int checkEvent(sf::RenderWindow &win){
sf::Event Event;
while(win.GetEvent(Event)){
// Window closed
if (Event.Type == sf::Event::Closed){
return 0;
}
// Escape key pressed
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)){
return 0;
}
}
return -1;
}
sf::RenderWindow win(sf::VideoMode(800,600,32),"Mario Clone Test");
sf::Image img1(200,200,sf::Color(255,255,0));
sf::Sprite sprite1;
std::stringstream ss;
sf::String fps;
bool threadFPS;
int main(){
sprite1.SetImage(img1);
sprite1.SetCenter(-300,-300);
win.SetFramerateLimit(30);
moveSquare();
win.Close();
sf::Sleep(0.5);
return 0;
}
void moveSquare(){
displayFPS dispFPS;
threadFPS = true;
dispFPS.Launch();
fps.SetSize(20);
while(1){
if(!win.IsOpened() || checkEvent(win) == 0){
threadFPS = false;
dispFPS.Wait();
break;
}
win.Draw(sprite1);
win.Draw(fps);
win.Display();
win.Clear();
if(win.GetInput().IsKeyDown(sf::Key::Left)){
sprite1.Move(-100*win.GetFrameTime(),0);
}
if(win.GetInput().IsKeyDown(sf::Key::Right)){
sprite1.Move(100*win.GetFrameTime(),0);
}
if(win.GetInput().IsKeyDown(sf::Key::Up)){
sprite1.Move(0,-100*win.GetFrameTime());
}
if(win.GetInput().IsKeyDown(sf::Key::Down)){
sprite1.Move(0,100*win.GetFrameTime());
}
}
return;
}
void avgFPS(){
double frames=0.0,avg=0.0;
int j=0;
while(threadFPS){
if(win.GetFrameTime() != 0){
j++;
frames = frames+(1.0/win.GetFrameTime());
avg = frames/j;
}
ss << "avg FPS: " << avg << std::endl << "Arrow Keys to Move" << std::endl << "Press ESC to Exit";
fps.SetText(ss.str());
ss.str("");
}
return;
}
void displayFPS::Run(){
avgFPS();
}
I've had the same issue.
You need to recompile SFML when using VS2010.
Few things for you to try:
If you are suspecting heap corruption, run gflags (found in Debugging Tools for Windows) and enable page heap. Some instructions on how it works can be found here. Basically when page heap is enabled, your app will crash at the point of the memory error, not sometime later.
You said you get a crash on exit. When that happens, I'm assuming windows throws up a crash dialog box. Open one of those links that say something like "see what information is being uploaded". Somewhere among those files will be a minidump of your process. You can load that up in visual studio (open file and hit F5). Sometimes visual studio is glitchy, so another, more reliable but more difficult but more difficult to use alternative is WinDbg, also part of Debugging Tools for Windows.
SFML has multiple versions of their .lib's for release and debug.
Examples:
sfml-audio.lib
sfml-audio-d.lib
sfml-audio-s.lib
sfml-audio-s-d.lib
Make sure you are using the lib without the -d in it.
Also, when you put the .dll's with your exe (assuming you are using the dynamic libraries) make sure to use the normal versions not the debug (-d) versions.
Finally, when you are building the project make sure you build for release and not debug.
So I am trying to use LZO in my application. Here is how I have included it:
#include "lzoconf.h"
#include "lzodefs.h"
#include "lzo1x.h"
/* portability layer */
static const char *progname = NULL;
#define WANT_LZO_MALLOC 1
#define WANT_XMALLOC 1
#include "portab.h"
Then in the application I do:
if (lzo_init() != LZO_E_OK)
{
printf("internal error - lzo_init() failed !!!\n");
printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
return 4;
}
It compiles ok. No errors or warnings during compilation.
When I try to run my application though, there are two errors:
/home/richard/client/src/portab.h:145: undefined reference to `__lzo_align_gap'
Which points at this line in portab.h:
if (__lzo_align_gap(p, (lzo_uint) sizeof(lzo_align_t)) != 0)
{
printf("%s: C library problem: malloc() returned mis-aligned pointer!\n", progname);
exit(1);
}
return p;
And in my application:
/home/richard/client/src/main.cc:108: undefined reference to `__lzo_init_v2'
Which points to:
if (lzo_init() != LZO_E_OK)
{
printf("internal error - lzo_init() failed !!!\n");
printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
return 4;
}
I have all the header files inside my source directory:
config.h
lzo1x.h
lzoconf.h
lzodefs.h
miniacc.h
portab.h
portab_a.h
What am I doing wrong?
I am compiling my application in Ubuntu 10.10 in Anjuta ide.
Headers is not enough, you need to link to the libraries. Have you read the documentation?