Rank: Newbie
Groups: BetaUser, Registered Joined: 3/19/2017(UTC) Posts: 3
Was thanked: 1 time(s) in 1 post(s)
|
Hi, I'm pretty new at Embrio but it looks like a great tool for multithreading :) I created a custom agent and that was a pretty easy proces (thumbs Up) But then I start experimenting and everything was great until I declared an array in the declaration section like this: int RunningSum[] = {0,0,0,0,0}; It gives me back a variable RunningSum and an error about not defined in this scope. Then I tried int RunningSum[5]; and int RunningSum[5] = {0,0,0,0,0}; In both situations embrio gave me a variable RunningSum5 I wonder, is the parser not recognizing array declarations ?? Ruud
|
1 user thanked Hunter58 for this useful post.
|
|
|
Rank: Administration
Groups: Administrators
Joined: 12/11/2014(UTC) Posts: 661
Thanks: 1 times Was thanked: 109 time(s) in 104 post(s)
|
I'm able to create an array and assign it a value. Could you copy the node and paste it into a reply here so I can try it out? Edited by user Sunday, March 19, 2017 5:22:55 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Newbie
Groups: BetaUser, Registered Joined: 3/19/2017(UTC) Posts: 3
Was thanked: 1 time(s) in 1 post(s)
|
Hi, it is an agent with two nodes. Strange thing is with an array and one int it is working. Adding the Size int produces the error. I copied the complete agent in here: Code:<Agent> <ObjectName>Sonar</ObjectName> <Description></Description> <UniqueID>701fd87c-87ff-495c-b066-e395cad1f7b4</UniqueID> <NodeScreen> <ScreenX>-180.395054945055</ScreenX> <ScreenY>-405.887606837607</ScreenY> <ZoomAmount>1.2</ZoomAmount> <Nodes> <Node> <UniqueID>afab7860-115c-493a-9bc0-6c92e2017eef</UniqueID> <AssemblyType>Embrio.NodeEngine.AgentController.Nodes.AgentControllerCustomArduinoNode</AssemblyType> <NodeType>Custom Arduino Node</NodeType> <UserDefinedName>4 Pin Ultrasonic Sensor</UserDefinedName> <Description></Description> <NodeColor>201,204,227,255</NodeColor> <X>104.111111111111</X> <Y>5.33333333333328</Y> <Width>546</Width> <IncludeCode>#include <NewPing.h></IncludeCode> <DeclerationCode>#define TRIGGER_PIN 8 #define ECHO_PIN 7 #define MAX_DISTANCE 100 NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); </DeclerationCode> <SetupCode></SetupCode> <ImageName>arduino.png</ImageName> <InfoURL></InfoURL> <IsOpen>True</IsOpen> <EditWidth>360</EditWidth> <CodeDefinitions> <CodeDefinition> <UpdateCondition>EveryUpdate</UpdateCondition> <Code>Output_cm = sonar.ping_cm();</Code> <UniqueID>fcc85ffb-23db-45cc-84ef-ec0aa1a9103c</UniqueID> </CodeDefinition> </CodeDefinitions> <Inputs></Inputs> <Outputs> <Output> <UniqueID>69de3645-8adc-4c09-8804-b4e6fe75215b</UniqueID> <DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID> <DefaultName>Integer</DefaultName> <CustomName>cm</CustomName> <IsDisplayed>True</IsDisplayed> <IsNative>False</IsNative> <TypeName>Integer</TypeName> <IsOutsideConnection>False</IsOutsideConnection> <IOType>Embrio.NodeEngine.NodeIO.IntegerNodeOutput</IOType> <ShowGraph>True</ShowGraph> <LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID> <IsUserAdded>True</IsUserAdded> <MinValue>0</MinValue> <MaxValue>100</MaxValue> </Output> </Outputs> </Node> <Node> <UniqueID>abf0036c-fef2-4fb3-a554-3752e8a05fda</UniqueID> <AssemblyType>Embrio.NodeEngine.AgentController.Nodes.AgentControllerCustomArduinoNode</AssemblyType> <NodeType>Custom Arduino Node</NodeType> <UserDefinedName></UserDefinedName> <Description>A node that lets you write any Arduino code to interact with the Arduino hardware. Can be both an input and output.</Description> <NodeColor>144,183,227,255</NodeColor> <X>815.047619047619</X> <Y>490.380952380953</Y> <Width>403</Width> <IncludeCode></IncludeCode> <DeclerationCode>int RunningSum[] = {0,0,0,0,0,0,0,0,0,0}; int Total; int Size;</DeclerationCode> <SetupCode>Size = 10;</SetupCode> <ImageName>arduino.png</ImageName> <InfoURL></InfoURL> <IsOpen>True</IsOpen> <EditWidth>360</EditWidth> <CodeDefinitions> <CodeDefinition> <UpdateCondition>EveryUpdate</UpdateCondition> <Code>if (Input_SonarIn != 0) { Total = 0; for (int Count=0; Count&lt;(Size-1); Count++) { RunningSum[Count] = RunningSum[Count+1]; Total += RunningSum[Count]; } RunningSum[Size-1] = Input_SonarIn; Output_SonarOut = (Total + Input_SonarIn) / Size; } </Code> <UniqueID>d1d8c3fe-efe8-47fe-86b3-cdd899b1390e</UniqueID> </CodeDefinition> </CodeDefinitions> <Inputs> <Input> <UniqueID>3d5e37f3-5ccc-4b13-95c7-df110510b9aa</UniqueID> <DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID> <DefaultName>Integer</DefaultName> <CustomName>SonarIn</CustomName> <IsDisplayed>True</IsDisplayed> <IsNative>False</IsNative> <TypeName>Integer</TypeName> <IsOutsideConnection>False</IsOutsideConnection> <IOType>Embrio.NodeEngine.NodeIO.IntegerNodeInput</IOType> <ShowGraph>False</ShowGraph> <LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID> <IsUserAdded>True</IsUserAdded> <ConnectedOutputs> <Output>69de3645-8adc-4c09-8804-b4e6fe75215b</Output> </ConnectedOutputs> <DisconnectedValue>51</DisconnectedValue> <MinValue>0</MinValue> <MaxValue>100</MaxValue> </Input> </Inputs> <Outputs> <Output> <UniqueID>448e7199-6a5f-4ce7-8527-97139f209411</UniqueID> <DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID> <DefaultName>Integer</DefaultName> <CustomName>SonarOut</CustomName> <IsDisplayed>True</IsDisplayed> <IsNative>False</IsNative> <TypeName>Integer</TypeName> <IsOutsideConnection>False</IsOutsideConnection> <IOType>Embrio.NodeEngine.NodeIO.IntegerNodeOutput</IOType> <ShowGraph>True</ShowGraph> <LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID> <IsUserAdded>True</IsUserAdded> <MinValue>0</MinValue> <MaxValue>100</MaxValue> </Output> </Outputs> </Node> </Nodes> <RefreshRate>32</RefreshRate> </NodeScreen> <Type>Agent</Type> </Agent>
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 12/11/2014(UTC) Posts: 661
Thanks: 1 times Was thanked: 109 time(s) in 104 post(s)
|
Looks like there's an imperfection in the code that finds used variables in the written code. Say you had two copies of the same node, because of that Embrio needs to find the variables you wrote and give them a unique name so they don't clash.
In your case it found that you declared "Size", but it isn't finding and replacing it in "[Size-1]" in
RunningSum[Size-1] = Input_SonarIn;
I'll add that to my todo list to fix. For now just replace that piece of code with:
int index = Size - 1; RunningSum[index] = Input_SonarIn;
which seems to be working for me.
|
|
|
|
Rank: Newbie
Groups: BetaUser, Registered Joined: 3/19/2017(UTC) Posts: 3
Was thanked: 1 time(s) in 1 post(s)
|
Sorry to be back again I removed every instance but one. Created an extra variable as you said. Renamed my variables with a prefix (unique?) and tried to connect to the UNO. Here is the result I got when connecting: 2017-03-21 by Ruud de Vreugd, on Flickr And to be complete here is the xml: Code:<Agent> <ObjectName>Sonar</ObjectName> <Description></Description> <UniqueID>701fd87c-87ff-495c-b066-e395cad1f7b4</UniqueID> <NodeScreen> <ScreenX>44.0343355990414</ScreenX> <ScreenY>-258.991288613347</ScreenY> <ZoomAmount>0.9</ZoomAmount> <Nodes> <Node> <UniqueID>afab7860-115c-493a-9bc0-6c92e2017eef</UniqueID> <AssemblyType>Embrio.NodeEngine.AgentController.Nodes.AgentControllerCustomArduinoNode</AssemblyType> <NodeType>Custom Arduino Node</NodeType> <UserDefinedName>4 Pin Ultrasonic Sensor</UserDefinedName> <Description></Description> <NodeColor>201,204,227,255</NodeColor> <X>104.111111111111</X> <Y>5.33333333333328</Y> <Width>546</Width> <IncludeCode>#include <NewPing.h></IncludeCode> <DeclerationCode>#define TRIGGER_PIN 8 #define ECHO_PIN 7 #define MAX_DISTANCE 100 NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); </DeclerationCode> <SetupCode></SetupCode> <ImageName>arduino.png</ImageName> <InfoURL></InfoURL> <IsOpen>True</IsOpen> <EditWidth>360</EditWidth> <CodeDefinitions> <CodeDefinition> <UpdateCondition>EveryUpdate</UpdateCondition> <Code>Output_cm = sonar.ping_cm();</Code> <UniqueID>fcc85ffb-23db-45cc-84ef-ec0aa1a9103c</UniqueID> </CodeDefinition> </CodeDefinitions> <Inputs></Inputs> <Outputs> <Output> <UniqueID>69de3645-8adc-4c09-8804-b4e6fe75215b</UniqueID> <DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID> <DefaultName>Integer</DefaultName> <CustomName>cm</CustomName> <IsDisplayed>True</IsDisplayed> <IsNative>False</IsNative> <TypeName>Integer</TypeName> <IsOutsideConnection>False</IsOutsideConnection> <IOType>Embrio.NodeEngine.NodeIO.IntegerNodeOutput</IOType> <ShowGraph>True</ShowGraph> <LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID> <IsUserAdded>True</IsUserAdded> <MinValue>0</MinValue> <MaxValue>100</MaxValue> </Output> </Outputs> </Node> <Node> <UniqueID>abf0036c-fef2-4fb3-a554-3752e8a05fda</UniqueID> <AssemblyType>Embrio.NodeEngine.AgentController.Nodes.AgentControllerCustomArduinoNode</AssemblyType> <NodeType>Custom Arduino Node</NodeType> <UserDefinedName></UserDefinedName> <Description>A node that lets you write any Arduino code to interact with the Arduino hardware. Can be both an input and output.</Description> <NodeColor>144,183,227,255</NodeColor> <X>815.047619047619</X> <Y>490.380952380953</Y> <Width>430</Width> <IncludeCode></IncludeCode> <DeclerationCode>int RunningSum[] = {0,0,0,0,0,0,0,0,0,0}; int cn_Total; int cn_Size; int cn_Index;</DeclerationCode> <SetupCode>cn_Size = 10; cn_Index = cn_Size - 1;</SetupCode> <ImageName>arduino.png</ImageName> <InfoURL></InfoURL> <IsOpen>True</IsOpen> <EditWidth>360</EditWidth> <CodeDefinitions> <CodeDefinition> <UpdateCondition>EveryUpdate</UpdateCondition> <Code>if (Input_SonarIn != 0) { cn_Total = 0; for (int Count=0; Count&lt;(cn_Index); Count++) { RunningSum[Count] = RunningSum[Count+1]; cn_Total += RunningSum[Count]; } RunningSum[cn_Index] = Input_SonarIn; Output_SonarOut = (cn_Total + Input_SonarIn) / cn_Size; } </Code> <UniqueID>d1d8c3fe-efe8-47fe-86b3-cdd899b1390e</UniqueID> </CodeDefinition> </CodeDefinitions> <Inputs> <Input> <UniqueID>3d5e37f3-5ccc-4b13-95c7-df110510b9aa</UniqueID> <DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID> <DefaultName>Integer</DefaultName> <CustomName>SonarIn</CustomName> <IsDisplayed>True</IsDisplayed> <IsNative>False</IsNative> <TypeName>Integer</TypeName> <IsOutsideConnection>False</IsOutsideConnection> <IOType>Embrio.NodeEngine.NodeIO.IntegerNodeInput</IOType> <ShowGraph>False</ShowGraph> <LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID> <IsUserAdded>True</IsUserAdded> <ConnectedOutputs> <Output>69de3645-8adc-4c09-8804-b4e6fe75215b</Output> </ConnectedOutputs> <DisconnectedValue>51</DisconnectedValue> <MinValue>0</MinValue> <MaxValue>100</MaxValue> </Input> </Inputs> <Outputs> <Output> <UniqueID>448e7199-6a5f-4ce7-8527-97139f209411</UniqueID> <DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID> <DefaultName>Integer</DefaultName> <CustomName>SonarOut</CustomName> <IsDisplayed>True</IsDisplayed> <IsNative>False</IsNative> <TypeName>Integer</TypeName> <IsOutsideConnection>False</IsOutsideConnection> <IOType>Embrio.NodeEngine.NodeIO.IntegerNodeOutput</IOType> <ShowGraph>True</ShowGraph> <LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID> <IsUserAdded>True</IsUserAdded> <MinValue>0</MinValue> <MaxValue>100</MaxValue> </Output> </Outputs> </Node> </Nodes> <RefreshRate>32</RefreshRate> </NodeScreen> <Type>Agent</Type> </Agent> As you can see it is not working. As soon as I declare more than one variable after the array declaration this is happening. If I change the cn_Size and cn_Index to be a long it is working Putting them on one line like this: " int var1, var2, var3;" is not working either. I'm very confused I'm still on the free version and testing. Your software has great potential and I'm willing to buy but thus issue is holding me back, for now. Ruud
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.