Arduino and STL - stl

I know this has been posted all over the place but I can not find what I need. I have a Arduino project that I must have vector or another way of allocating a dynamic array safely. I am trying to get the "StandardCplusplus" library to compile but I am getting an error
'Starting combiner'
"C:\Eclipse\eclipse\arduinoPlugin\tools\arduino\avr-gcc\4.8.1-arduino5/bin/avr-gcc" -Os -Wl,--gc-sections,--relax -mmcu=atmega2560 -o "D:/Development/MegaTesting/Release/MegaTesting.elf" ./.ino.cpp.o ./libraries/StandardCplusplus/algorithm.cpp.o ./libraries/StandardCplusplus/associative_base.cpp.o ./libraries/StandardCplusplus/bitset.cpp.o ./libraries/StandardCplusplus/char_traits.cpp.o ./libraries/StandardCplusplus/complex.cpp.o ./libraries/StandardCplusplus/del_op.cpp.o ./libraries/StandardCplusplus/del_opnt.cpp.o ./libraries/StandardCplusplus/del_opv.cpp.o ./libraries/StandardCplusplus/del_opvnt.cpp.o ./libraries/StandardCplusplus/deque.cpp.o ./libraries/StandardCplusplus/eh_alloc.cpp.o ./libraries/StandardCplusplus/eh_globals.cpp.o ./libraries/StandardCplusplus/exception.cpp.o ./libraries/StandardCplusplus/fstream.cpp.o ./libraries/StandardCplusplus/func_exception.cpp.o ./libraries/StandardCplusplus/iomanip.cpp.o ./libraries/StandardCplusplus/ios.cpp.o ./libraries/StandardCplusplus/iostream.cpp.o ./libraries/StandardCplusplus/istream.cpp.o ./libraries/StandardCplusplus/iterator.cpp.o ./libraries/StandardCplusplus/limits.cpp.o ./libraries/StandardCplusplus/list.cpp.o ./libraries/StandardCplusplus/locale.cpp.o ./libraries/StandardCplusplus/map.cpp.o ./libraries/StandardCplusplus/new_handler.cpp.o ./libraries/StandardCplusplus/new_op.cpp.o ./libraries/StandardCplusplus/new_opnt.cpp.o ./libraries/StandardCplusplus/new_opv.cpp.o ./libraries/StandardCplusplus/new_opvnt.cpp.o ./libraries/StandardCplusplus/numeric.cpp.o ./libraries/StandardCplusplus/ostream.cpp.o ./libraries/StandardCplusplus/queue.cpp.o ./libraries/StandardCplusplus/set.cpp.o ./libraries/StandardCplusplus/sstream.cpp.o ./libraries/StandardCplusplus/stack.cpp.o ./libraries/StandardCplusplus/stdexcept.cpp.o ./libraries/StandardCplusplus/streambuf.cpp.o ./libraries/StandardCplusplus/string.cpp.o ./libraries/StandardCplusplus/support.cpp.o ./libraries/StandardCplusplus/typeinfo.cpp.o ./libraries/StandardCplusplus/utility.cpp.o ./libraries/StandardCplusplus/valarray.cpp.o ./libraries/StandardCplusplus/vector.cpp.o arduino.ar "-LD:/Development/MegaTesting/Release" -lm
arduino.ar(new.cpp.o): In function `operator new[](unsigned int)':
C:/Eclipse/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.10/cores/arduino/new.cpp:26: multiple definition of `operator new[](unsigned int)'
./libraries/StandardCplusplus/new_opv.cpp.o:C:/Eclipse/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.10/libraries/StandardCplusplus/new_opv.cpp:24: first defined here
c:/eclipse/eclipse/arduinoplugin/tools/arduino/avr-gcc/4.8.1-arduino5/bin/../lib/gcc/avr/4.8.1/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
arduino.ar(new.cpp.o): In function `operator new(unsigned int)':
C:/Eclipse/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.10/cores/arduino/new.cpp:22: multiple definition of `operator delete[](void*)'
makefile:83: recipe for target 'MegaTesting.elf' failed
./libraries/StandardCplusplus/del_opv.cpp.o:C:/Eclipse/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.10/libraries/StandardCplusplus/del_opv.cpp:25: first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [MegaTesting.elf] Error 1
06:23:57 Build Finished (took 21s.666ms)
I have searched here and online and there seems to be a bunch of fixes but none of them work. There was some mention of including a pnew.cpp in one of your files but this file is not in the library anywhere.
All my code contains that I am trying to compile is
#include "StandardCplusplus.h"
#include "Arduino.h"
void setup(void) {
Serial.begin(57600);
}
void loop(void) {
}
There are a couple of versions of this library out there and I have tried the two main forks that I can find and both of them generate this error.
Also I am using Eclipse with the Arduino AVR plugin to compile.
Edit
I thought that commenting out the lines did work until I tried to use a vector. Once I did the StandardCplusplus library got really mad saying that the function new was not defined.
I think that there needs to be something done to the StandardCplusplus library like in new/new_opv delete/delete_opv files? Or is there a better way?
Edit - 2
Alright so I went into the files:
StandardCplusplus/new_opv.h
StandardCplusplus/del_opv.h
And commented out the bodies for the functions and everything seems to be happy. I did a simple test and everything looks like it is working but now I am concerned that I might of removed something that something else in the library might need, can anyone tell me if my changes will hurt anything?
Edit - 3
Well the last fix didn't work so I tried going to another library all together and I am allot closer. I Downloaded this STL-AVR library and had to make a minor edit to vector.h now I am having problems with the pnew.cpp file. Looks like the template is calling a "new" function that is now defined in arduino but if I try to comment out this body I get that it is not defined. I am sure this is some sort of order of the includes or missing one can anyone help?

Those STL like libary versions you have were put together before operator new was added to the Arduino core. Now they are in the core you are getting a multiple definition error.
You can go into your core and comment out the bits causing the multiple definition error.
You can probably just get away with commenting out the function definitions in the .cpp:
C:/Eclipse/eclipse/arduinoPlugin/packages/arduino/hardware/avr/1.6.10/cores/arduino/new.cpp
If you still get the errors, also comment out the function declarations in new.h, but you shouldn't need to as multiple declarations are allowed, only definitions must be unique.

Related

TCL stack trace not showing desired error line number

The -errorline element of the return options dictionary for the following TCL script is "2":
puts [info patchlevel]
try {
error "this is an error"
} trap {} {result ropts} {
puts $result
puts $ropts
}
How do I get the stacktrace to display the line number in the source file where the error was actually raised (ie. line 4 instead of 2) ?
Example screenshot:
Tcl often has that information available, but doesn't use it.
It has the information available because you have a chance to retrieve it with info frame and getbytecode (which is in the tcl::unsupported namespace, mostly because we reserve the right to change how the bytecodes themselves work at any time). I'm not quite sure if that would work in your specific case, but if you put your test code in a procedure then it definitely would. (There are complexities here with fragility that I don't fully understand.)
It doesn't use it because, for backward-compatibility with existing tooling, it uses the line numbers it was using prior to the creation of the machinery to support info frame. Those line numbers are relative to the local script fragment (which is whatever reports the line number in the error info trace first); in this case, that is the body of the try.
I don't like that it works like that at all. However, changing things is a bit tricky because we'd need to also figure out what else to report and what to do in the cases where the information genuinely isn't available (such as for automatically-generated code where things are assembled from many strings from many lines).

How to run Julia function on specific processor using remotecall(), when the function itself does not have return

I tried to use remotecall() in julia to distribute work to specific processor. The function I like to run does not have any return but it will output something. I can not make it work as there is no output file after running the code.
This is the test code I am creating:
using DelimitedFiles
addprocs(4) # add 4 processors
#everywhere function test(x) # Define the function
print("hi")
writedlm(string("test",string(x),".csv"), [x], ',')
end
remotecall(test, 2, 2) # To run the function on process 2
remotecall(test, 3, 3) # To run the function on process 3
This is the output I am getting:
Future(3, 1, 67, nothing)
And there is no output file (csv), or "hi" shown
I wonder if anyone can help me with this or I did anything wrong. I am fairly new to julia and have never used parallel processing.
The background is I need to run a big simulation (A big function with bunch of includes, but no direct return outputs) lots of times, and I like to split the work to different processors.
Thanks a lot
If you want to use a module function in a worker, you need to import that module locally in that worker first, just like you have to do it in your 'root' process. Therefore your using DelimitedFiles directive needs to occur "#everywhere" first, rather than just on the 'root' process. In other words:
#everywhere using DelimitedFiles
Btw, I am assuming you're using a relatively recent version of Julia and simply forgot to add the using Distributed directive in your example.
Furthermore, when you perform a remote call, what you get back is a "Future" object, which is a way of allowing you to obtain the 'future results of that computation' from that worker, once they're finished. To get the results of that 'future computation', use fetch.
This is all very simplistic and general information, since you haven't provided a specific example that can be copy / pasted and answered specifically. Have a look at the relevant section in the manual, it's fairly clearly written: https://docs.julialang.org/en/v1/manual/parallel-computing/#Multi-Core-or-Distributed-Processing-1

How do I debug lua functions called from conky?

I'm trying to add some lua functionality to my existing conky setup so that repetitive "code" in my conky text can be cleaned up. For example, I have information for each mounted FS, each core, etc. where each row displayed in my panel differs ONLY by one parameter.
My first skeletal, attempt at using lua functions for this seems to run but displays nothing in my panel. I've only found very simple examples to base this on, so I may have made a simple error, but I don't even know how to diagnose it. My code here is modeled after what I HAVE been able to find regarding writing functions, such as this How to implement a basic Lua function in Conky? , but that's about all the depth I've found on the topic except for drawing and cairo examples.
Here's the code added to my conky config, as well as the contents of my functions.lua file
conky.config = {
...
lua_load = '/home/conky-manager/MyConky/functions.lua',
};
conky.text = [[
...
${voffset 5}${lua conky_test 'test'}
...
]]
file - functions.lua
function conky_test(parm1)
return 'result text'
end
What I would expect is to see is "result text" displayed in my panel at the location where that function call appears, but nothing shows.
Is there a log created by conky as it runs, or a way to provide some debug output? Even if I'd made a simple error here, I'd still like to have the ability to diagnose things as my code gets more complex.
Success!
After cobbling info from several articles together, I figured out my basic flaws -
1. Missing a 'conky_main' function,
2. Missing a 'lua_draw_hook_post' to invoke it, and
3. Realizing that if I invoke conky from a terminal, print statements in lua would appear there.
So, for anyone who sees this question and has the same issues, here's the corrected code.
conky.config = {
...
lua_load = '/home/conky-manager/MyConky/functions.lua',
lua_draw_hook_post = "main",
};
conky.text = [[
...
${lua conky_test 'test'}
...
]]
and the proper basics in my functions.lua file
function conky_test(parm1)
return 'result text'
end
function conky_main()
if conky_window == nil then
return
end
end
A few notes:
I still haven't determined if using 'lua_draw_hook_pre' instead of 'lua_draw_hook_post' makes any difference, but it doesn't seem to in this example.
Also, some examples showed actually calling this 'test' function instead of writing a 'main', but the 'main' seemed to have value in checking to see if conky_window existed.
Some examples seemed to state that naming functions with the prefix 'conky_' was required, but then showed examples of calling those functions without the prefix, so I assume the prefix is inferred during the call.
a major note: you should run conky from the directory containing the lua scripts.

Status of in-place `rfft` and `irfft` in Julia

So I'm doing some hobby-related stuff which involves taking Fourier transforms of large real arrays which barely fit in memory, and was curious to see if there was an in-place version of rfft and irfft that saved RAM, since RAM consumption is important to me. These transforms are possible despite the input-vs-output-type mismatch, and require an extra row of padding.
In Implement in-place rfft! and irfft!, Tim Holy said he was working on an in-place rfft! and irfft! that made use of a buffer-containing RCpair object, but then Steven Johnson said that he was implementing something equivalent using A_mul_B!(y, plan, x), which he elaborated on here.
Things get a little weird from then on. In the documentation for both 0.3.0 and 0.4.0 there is no mention of A_mul_B!, although A_mul_B is listed. But when I try entering them into Julia, I get
A_mul_B!
A_mul_B! (generic function with 28 methods)
A_mul_B
ERROR: A_mul_B not defined
which suggests that the situation is actually the opposite of what the documentation currently describes.
So since A_mul_B! seems to exist, but isn't documented anywhere, I tried to guess how to test it in-place as follows:
A = rand(Float32, 10, 10);
p = plan_rfft(A);
A_mul_B!(A,p,A)
which resulted in
ERROR: `A_mul_B!` has no method matching A_mul_B!(::Array{Float32,2}, ::Function, ::Array{Float32,2})
So...
Are in-place real FFTs still a work in progress? Or am I using A_mul_B! wrong?
Is there a mismatch between the 0.3.0 documentation and 0.3.0's function library?
That pull request from Steven Johnson is listed as open, not merged; that means the work hasn't been finished yet. The one from me is closed, but if you want the code you can grab it by clicking on the commits.
The docs indeed omit mention of A_mul_B!. A_mul_B is equivalent to A*B, and so isn't exported independently now. A_mul_B! would be used like this: instead of C = A*B, you could say A_mul_B!(C, A, B).
Can you please edit the docs to fix these issues? (You can edit files here in your webbrowser.)

Invalid method when method is valid

I have just started a new version of my Crysis Wars Server Side Modification called InfinityX. For better management, I have put the functions inside tables as it looks neater and I can group functions together (like Core.PlayerHandle:GetIp(player)), but I have ran into a problem.
The problem is that the specified method to get the players' name, player:GetName() is being seen as an invalid method, when the method actually is completely valid.
I would like to know if using the below structure is causing a problem and if so, how to fix it. This is the first time I've used this structure for functions, but it is already proving easier than the old method I was using.
The Code:
Event =
{
PlayerConnect = function(player)
Msg.All:CenteredConsole("$4Event$8 (Connect)$9: $3"..player:GetName().." on channel "..player.actor:GetChannel());
System.LogAlways(Default.Tag.."Incoming Connect on Channel "..player.actor:GetChannel());
Event:Log("Connect", player);
end;
};
The below code works when I bypass the function and put the code directly where it's needed:
Msg.All:CenteredConsole("$4Event$8 (Connect)$9: $3"..player:GetName().." on channel "..player.actor:GetChannel());
System.LogAlways(Default.Tag.."Incoming Connect on Channel "..player.actor:GetChannel());
The Error:
[Warning] [Lua Error] infinityx/main/core.events.lua:23: attempt to call method 'GetName' (a nil value)
PlayerConnect, (infinityx/main/core.events.lua: 23)
ConnectScript, (infinityx/main/core.main.lua: 52)
OnClientEnteredGame, (scripts/gamerules/instantaction.lua: 511)
(null) (scripts/gamerules/teaminstantaction.lua: 520)
Any clarification would be appreciated.
Thanks :)
Well, as PlayerConnect is inside the table Event, and you are calling with a ":", add self as first arg in the function, like:
PlayerConnect = function(self, player)
Clearly, player in the first block of code is not the same as player in the second block of code. The problem must be that the caller of Event.PlayerConnect is not passing the same value.
To test that your Event.PlayerConnect function works, try this in the same place as your second block of code:
Event.PlayerConnect(player)
That should work as you expect.
So, the problem comes down to how Event.PlayerConnect is called without the second block of code. I'm not familiar with that game engine so I don't know how it is done. Perhaps reviewing the documentation and/or debugging that area would help. If you print(player) or call the equivalent log function in both cases, you should see they are different. If you can't run in a debugger, you can still get a stack trace with print(debug.traceback("Accessing player, who's value is: "..player)). If there is indeed some kind of table-based player object in both cases, you can try comparing their fields to see how they are different. You might need to write a simple dumping function to help with that.