Show Posts
Pages: 1 [2] 3 4 ... 149
16  Using Arduino / Programming Questions / Re: calling variable from other tab on: September 11, 2014, 04:22:09 am
If both files are .ino, extern is not needed. The IDE will join all .ino files together, starting with the one named the same as the sketch ( so the compiler sees it as one big .cpp file. ).

If you place the float variable above the functions it is used in ( maybe the top of the main .ino. ) then you should have some luck hopefully. extern is only needed to share variables between c++ .cpp source files.

Your setup is only  a guess however, post the code from both tabs.
17  Using Arduino / Programming Questions / Re: cannot declare variable to be of abstract type on: September 11, 2014, 04:10:44 am
The message is kind of clear.

Quote
rosserial_arduino::Acc_righthand Acc_righthand_msg;

Quote
Acc_Recieverhand:15: error: cannot declare variable ‘Acc_righthand_msg’ to be of abstract type ‘rosserial_arduino::Acc_righthand
/home/sp/arduino-1.0.1/libraries/ros_lib/rosserial_arduino/Acc_righthand.h:13: note:   because the following virtual functions are pure within ‘rosserial_arduino::Acc_righthand’:


You have a function with '=0' after it ( or an error in your class that looks like one ). Using a class with pure virtual functions is a clear indication of error, as only a derived type will provide an implementation for the pure members. ( i.e a class with pure virtual functions can also be described as 'incomplete' or... abstract ).

It thinks you have these members marked as pure, do you?:

Code:
virtual int ros::Msg::serialize(unsigned char*) const
virtual const char* ros::Msg::getMD5()
18  Using Arduino / Programming Questions / Re: large array compiler error - Trying to load image into Flash on: September 10, 2014, 06:09:30 am
I've placed around 50K chunks of data in flash and was able to sequentially access all of them (which it seems I should not be able to if the pointer is SIGNED).

I used static const uint8_t bitmap[] PROGMEM = { ....~50 k of data .... };

Not using Arduino and GCC you didn't. It has a maximum of 32768 bytes, not elements per addressable object regardless of what those AVRFreaks think, try and declare these arrays bigger:

Code:
char a[ 32767 ];
short b[ 16383 ];
int c[ 16383 ];
long d[ 8191 ];
long long e[ 4095 ];
float f[ 8191 ];
double g[ 8191 ];

http://arduino.land/FAQ/content/6/7/en/what-is-the-maximum-number-of-elements-an-array-can-have.html
19  Using Arduino / Project Guidance / Re: Yes Or No, will this work or shall I go elsewhere? on: September 09, 2014, 07:31:38 pm
The PTZ is controlled by the software, the camera must be sent the PTZ data from the main box. If you can intercept the data for sure you can use an Arduino to interpret it and control some servos.

Will the camera tell the device weather it supports PTZ ( options will probably be disabled in the software if not available )?

3g is irrelevant isn't it? only the PC and main device use it to communicate ( and Arduino will not be able to intercept a 3g transmission due to security and lack of hardware ).

Why not create your own app. Even Google chrome can use the com port ( website with JavaScript... easy ). then you can independently control the servos regardless of what the DVR or its software is doing.

You are jumping in the deep end and are going to smother yourself in ideas you might not understand. Baby steps... learn how to control a servo using Arduino, then modify it to user the serial comms to control it a bit more. and so on...

Yeah you might not have time to tinker, but if that's the case, you might as well keep this as a pipe dream. A month or two of learning and you'll probably surprise yourself.

Why not get a cheapo wifi IP camera. They are full colour and some models have PTZ built in. Then everything is already done for you.
20  Development / Other Software Development / Re: Some new core functions on: September 09, 2014, 09:51:11 am
Quote
How would I do that with this, do I just use #if defined(__AVR__) and just mod the code to use dynamic memory for non AVR machines?

There is no need, my lack of sleep made me blind to the fact that N is a constant, and is legal in any C++.

For clarification, if N was a parameter to the function ( and therefore not a compile time constant in C++98 ) rather than a template parameter, things would be different.

The AVR macro is one way, however other platforms use GCC (Due) and it seems there is a __GNUC__ macro.
https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/C-Extensions.html
And the extension in question: https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Variable-Length.html#Variable-Length

Code:
#ifdef __GNUC__
  T _data[N];
#elif
  T* _data = new T[N];
#endif

//...

#ifndef __GNUC__
  delete [] _data;
#endif


Quote
When will C++11 be usable on the arduino, its usefulness will be great appreciated.

You can enable it in 1.5.7, and it'll hopefully be default in 1.5.8 ( https://github.com/arduino/Arduino/pull/2175 )
21  Development / Other Software Development / Re: Some new core functions on: September 09, 2014, 08:17:26 am
A big thing that will keep your code out of the core is dynamic memory usage.

GCC supports stack based allocation, and on an AVR, you should definitely use it over short lived dynamic allocations.

Quote
template<typename T, size_t N> T median(T (&Arr)[N])
{
  //T* _data = new T[N];
  T _data[N];
  sort(Arr);
  for (int i = 0; i < N; i++)
  {
    _data[i] = Arr[i];
  }
 
  T Med = 0;
  if ((N % 2) == 0)
    Med = (T)(_data[N/2] + _data[(N/2) - 1])/2;
  else
    Med = _data[N/2];

  //delete [] _data;
  return Med;
}

It is an extension, however the Arduino core uses gnu extensions as the AVR core has parts of its code which require it ( atomic block macros for example ), so its worth using. Also a simple #ifdef can be used to replace the dynamic handling for non AVR machines.
22  Development / Other Software Development / Re: Some new core functions on: September 09, 2014, 07:49:12 am
@Pyro
I never did look into C++11, :/ Looks like I got homework.

I'm still learning it myself, infact I didn't realize at first, but the LargerType and Select classes in my code can be replaced with the new decltype keyword:

Code:
template< typename T, typename U, typename V, typename X, typename Y >
   auto map( const T &x, U &&imin, V &&imax, X &&omin, Y &&omax ) -> T
    {
      typedef decltype( T() * U() * V() * X() * Y() ) cll;
      return (cll)(x - imin) * (omax - omin) / (imax - imin) + omin;
    }

As integer promotion will occur with each multiplication operator, the largest type can be found.

Also a new function declaration syntax allows using the same decltype as the return type of the function; and then its sized to the largest type which will prevent overflow if the data input is of a different type to the range inputs.

Code:
template< typename T, typename U, typename V, typename X, typename Y >
   auto map( const T &x, U &&imin, V &&imax, X &&omin, Y &&omax ) -> decltype( T() * U() * V() * X() * Y() )
    {
      typedef decltype( T() * U() * V() * X() * Y() ) cll;
      return (cll)(x - imin) * (omax - omin) / (imax - imin) + omin;
    }

Another feature is ranged loops, your mean function could look like this:
Code:
template<class T, size_t N>
  T mean(T(&x)[N]){
    T tmp = 0;
    for( auto i : x )  tmp += i;
    return tmp / N;
}
23  Using Arduino / Programming Questions / Re: Somebody can explain to me the meaning of this part of code on: September 09, 2014, 06:51:50 am
Template functions are not supposed to always go into a header file. I've never heard anything like that, nor read in the C++ language specifications that it was mandatory.

Actually, not firing very local declarations into interface files and just letting them in the required scope can be considered as a good practice.

Anyway, the so-called "badly-writting" (which is just a matter of point of view) is not enough to explain nor justify the particular behaviour of the Arduino compiler.

You are completely right, just take into account the article is aimed at noobs, who have most probably put a class definition in a separate .cpp to the declaration in a header; And only included the header.

As a side note, this can be solved by including the .cpp, rather than the .h.

Whean dealing with the IDE auto prototype feature, you can suppy your own prototype like Nick said, however you can also use something called an exception specification to prevent a function having its prototype generated at all, which can save time if your code is changing as it grows, it is explained in detail at the bottom of this article, also this one explains the steps the IDE takes before compiling .
24  Using Arduino / Programming Questions / Re: How do I get a class (hardware serial) to use an external buffer? on: September 08, 2014, 06:02:16 am
Quote
I will just be sending a buffer full on each occasion so the circularity is irrelevant...

I want the PC to be able to send data which is picked up and saved by the USART directly into a useable location.

If the data is the size of the internal buffer, why not double its size and access it directly; Its not that much different to having two buffers.

Here is some code I previously wrote to access the internal buffer: http://forum.arduino.cc/index.php?topic=261359.msg1845483#msg1845483
25  Development / Suggestions for the Arduino Project / Re: Update libraries button or meni item on: September 08, 2014, 05:11:31 am
I agree it can be a hassle. Post an issue on GitHub so the developers know people are interested: https://github.com/arduino/Arduino/issues
26  Development / Other Software Development / Re: Some new core functions on: September 08, 2014, 04:14:17 am
It'll only be of a benefit if the resulting inline code is smaller than the cost of calling/returning a function. Otherwise multiple use of an inline function may result in a larger code size. Only testing will prove the result, and then tests may be rubbish as they may not represent what happens in real use of the code.

Below is what I would do. It will do the maths using the largest type provided so there is no need to specify the value in pointy brackets. The code is more complex, however it makes it easier for the end user.

Code:
template< bool V, typename T, typename U > struct Select{ typedef T Result; };
template< typename T, typename U > struct Select< false, T, U >{ typedef U Result; };

template< typename T, typename U > struct LargerType{
  typedef typename Select< sizeof( U ) < sizeof( T ), T, U >::Result Result;
};

template< typename T, typename U, typename V, typename X, typename Y >
   T map( const T &x, const U &imin, const V &imax, const X &omin, const Y &omax ) throw()
    {
      typedef typename LargerType< typename LargerType< typename LargerType< T, U >::Result, typename LargerType< V, X >::Result >::Result, Y >::Result cll;
      return (cll)(x - imin) * (omax - omin) / (imax - imin) + omin;
    }

The C++11 version can be a little more efficient (specific cases) using move semantics:
Code:
template< typename T, typename U, typename V, typename X, typename Y >
   auto map( const T &x, U &&imin, V &&imax, X &&omin, Y &&omax ) -> T
    {
      typedef typename LargerType< typename LargerType< typename LargerType< T, U >::Result, typename LargerType< V, X >::Result >::Result, Y >::Result cll;
      return (cll)(x - imin) * (omax - omin) / (imax - imin) + omin;
    }
27  Using Arduino / Programming Questions / Re: How to combine Strings and other Variable Types on: September 08, 2014, 02:00:45 am
Are you using an old version of the IDE? Some of the operators may not exist in the old version of the API.

If you have two variables, a String and float, all that is needed is what you first expected:

Code:
String a = "THE ANSWER IS ";
float f = 1.23f;

String b = a + f;

Or just simply:
Code:
a += f;

The String library uses dynamic memory, and people get caught on large concatenations as temporaries will be created ( which also use dynamic memory ). Its easier ( for memory management ) to use c-strings, like econjacks example, however careful use of the String class can make it easy to do many things with text.

28  Development / Other Software Development / Re: Some new core functions on: September 07, 2014, 07:20:04 am
Could you explain to me why the normal map function in the following sketch uses more memory then my templated map function as type long?

Your template is compiled inline.

29  Using Arduino / Programming Questions / Re: Structuring data for viewing/modifying in a hex editor.(Mega2560 R3) on: September 05, 2014, 05:24:47 am
Your hardware can be whatever you like, its the Arduino core API ( software/code ) which is covered by LGPL. The bootloader source my be licensed the same, however you will have to look at the source/documentation.
30  Using Arduino / Programming Questions / Re: working with Array (basic code but very strange) on: September 04, 2014, 03:34:35 am
Quote
I'm not sure it has a name - it's just compile-time allocation.

Anything created on the heap ( globals ) has a storage lifetime called: Static storage duration.

Local static variables also have static storage duration.

Local non-static variables have: Automatic storage duration.

Memory allocated with new/custom allocator are grouped under: dynamic storage duration.

And C++11 introduces thread storage duration.
Pages: 1 [2] 3 4 ... 149