Welcome Guest! To enable all features please Login or Register.
Options
Go to last post Go to first unread
marcschoemann@gmail.com  
#1 Posted : Saturday, February 13, 2016 7:02:34 AM(UTC)
marcschoemann@gmail.com

Rank: Newbie

Groups: Registered
Joined: 5/23/2015(UTC)
Posts: 4

Was thanked: 3 time(s) in 3 post(s)
Hello,

im playing around with embrio for a while now on a very simple basis, but now i got a project where i need to go a bit deeper.

I want to use the MPU-6050 Accelometer & Gyro to control a Servo via PID (for a self stabilizing device) but i already failed to implement the MPU.

Can someon give me a hint how i can integrate this Code:
http://playground.arduino.cc/Main/MPU-6050
into a usable Node?

Thanks in advance!
EmbrioAdmin  
#2 Posted : Saturday, February 13, 2016 2:43:02 PM(UTC)
EmbrioAdmin

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 661

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
You might need to play with the transform lines at the end, but this gives you the idea. Mostly just a copy/paste from an example on that link with the addition of setting outputs with the transformed data. I noticed there's a bug in Embrio where you can't declare multiple variables on the same line so I had to put each on its own line, I'll fix that for the next version.

Let me know if you have any trouble.

<EmbrioCopy>
<Version>1.3.6.0</Version>
<Nodes>
<Node>
<UniqueID>1bdc2fee-5322-476f-beaf-48f7b26cb5b7</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>0</X>
<Y>0</Y>
<Width>691</Width>
<IncludeCode>#include&lt;Wire.h&gt;</IncludeCode>
<DeclerationCode>const int MPU_addr=0x68; // I2C address of the MPU-6050
int16_t AcX;
int16_t AcY;
int16_t AcZ;
int16_t Tmp;
int16_t GyX;
int16_t GyY;
int16_t GyZ;</DeclerationCode>
<SetupCode>Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);</SetupCode>
<ImageName>arduino.png</ImageName>
<InfoURL></InfoURL>
<IsOpen>True</IsOpen>
<EditWidth>360</EditWidth>
<CodeDefinitions>
<CodeDefinition>
<UpdateCondition>EveryUpdate</UpdateCondition>
<Code>Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers
AcX=Wire.read()&amp;lt;&amp;lt;8|Wire.read(); // 0x3B (ACCEL_XOUT_H) &amp;amp; 0x3C (ACCEL_XOUT_L)
AcY=Wire.read()&amp;lt;&amp;lt;8|Wire.read(); // 0x3D (ACCEL_YOUT_H) &amp;amp; 0x3E (ACCEL_YOUT_L)
AcZ=Wire.read()&amp;lt;&amp;lt;8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) &amp;amp; 0x40 (ACCEL_ZOUT_L)
Tmp=Wire.read()&amp;lt;&amp;lt;8|Wire.read(); // 0x41 (TEMP_OUT_H) &amp;amp; 0x42 (TEMP_OUT_L)
GyX=Wire.read()&amp;lt;&amp;lt;8|Wire.read(); // 0x43 (GYRO_XOUT_H) &amp;amp; 0x44 (GYRO_XOUT_L)
GyY=Wire.read()&amp;lt;&amp;lt;8|Wire.read(); // 0x45 (GYRO_YOUT_H) &amp;amp; 0x46 (GYRO_YOUT_L)
GyZ=Wire.read()&amp;lt;&amp;lt;8|Wire.read(); // 0x47 (GYRO_ZOUT_H) &amp;amp; 0x48 (GYRO_ZOUT_L)
Output_AcX = transform(AcX, 0, 255, 0.0, 1.0);
Output_AcY = transform(AcY, 0, 255, 0.0, 1.0);
Output_AcZ = transform(AcZ, 0, 255, 0.0, 1.0);
Output_Tmp = Tmp / 340.00 + 36.53;
Output_GyX = transform(GyX, 0, 255, 0.0, 1.0);
Output_GyY = transform(GyY, 0, 255, 0.0, 1.0);
Output_GyZ = transform(GyZ, 0, 255, 0.0, 1.0);
</Code>
<UniqueID>29530af4-1bd5-4d8b-8270-ccb92f21910e</UniqueID>
</CodeDefinition>
</CodeDefinitions>
<Inputs></Inputs>
<Outputs>
<Output>
<UniqueID>8029cc3c-fced-4448-8efd-2ce79450ff50</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Activation</DefaultName>
<CustomName>AcX</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Numeric</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.NumericNodeOutput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<MinValue>0</MinValue>
<MaxValue>1</MaxValue>
<UseNegativeRange>False</UseNegativeRange>
<CanUseNegativeRange>True</CanUseNegativeRange>
</Output>
<Output>
<UniqueID>0de43eea-89b5-45d8-b5c3-4a296875b9af</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Activation 1</DefaultName>
<CustomName>AcY</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Numeric</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.NumericNodeOutput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<MinValue>0</MinValue>
<MaxValue>1</MaxValue>
<UseNegativeRange>False</UseNegativeRange>
<CanUseNegativeRange>True</CanUseNegativeRange>
</Output>
<Output>
<UniqueID>88a6a5dd-2eed-4858-a666-d43b99779f98</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Activation 2</DefaultName>
<CustomName>AcZ</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Numeric</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.NumericNodeOutput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<MinValue>0</MinValue>
<MaxValue>1</MaxValue>
<UseNegativeRange>False</UseNegativeRange>
<CanUseNegativeRange>True</CanUseNegativeRange>
</Output>
<Output>
<UniqueID>ffbd8438-1c9f-44b1-be0c-1f4e5af52ccc</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Activation 4</DefaultName>
<CustomName>GyX</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Numeric</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.NumericNodeOutput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<MinValue>0</MinValue>
<MaxValue>1</MaxValue>
<UseNegativeRange>False</UseNegativeRange>
<CanUseNegativeRange>True</CanUseNegativeRange>
</Output>
<Output>
<UniqueID>e6f46306-86c1-4739-abec-32d607ae68df</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Activation 5</DefaultName>
<CustomName>GyY</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Numeric</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.NumericNodeOutput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<MinValue>0</MinValue>
<MaxValue>1</MaxValue>
<UseNegativeRange>False</UseNegativeRange>
<CanUseNegativeRange>True</CanUseNegativeRange>
</Output>
<Output>
<UniqueID>5f4e44ec-6812-4d30-96c5-7a0d079f727d</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Activation 6</DefaultName>
<CustomName>GyZ</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Numeric</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.NumericNodeOutput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<MinValue>0</MinValue>
<MaxValue>1</MaxValue>
<UseNegativeRange>False</UseNegativeRange>
<CanUseNegativeRange>True</CanUseNegativeRange>
</Output>
<Output>
<UniqueID>219cfa07-a3ad-468b-a187-5347dbf364fb</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Integer</DefaultName>
<CustomName>Tmp</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Integer</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.IntegerNodeOutput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<MinValue>0</MinValue>
<MaxValue>100</MaxValue>
</Output>
</Outputs>
</Node>
</Nodes>
</EmbrioCopy>
thanks 1 user thanked EmbrioAdmin for this useful post.
sample@email.tst on 4/7/2024(UTC)
marcschoemann@gmail.com  
#3 Posted : Monday, February 15, 2016 12:23:23 PM(UTC)
marcschoemann@gmail.com

Rank: Newbie

Groups: Registered
Joined: 5/23/2015(UTC)
Posts: 4

Was thanked: 3 time(s) in 3 post(s)
wow, thank you, it seems way easier to implement that than i thought!
The connection wasn´t a problem and at first it look it works well but the values are of course really messed up. The most significant problem i noticed is that the values won´t stay up, they always drop down after a while as you can see in the screenshot:

mpu6050

Im not sure if thats because of the missing offset or something else,
if im using this sketch (even without offset), i get really nice readings.
https://github.com/jrowb...50_DMP6/MPU6050_DMP6.ino

But you already helped greatly, thanks a lot!

Edited by user Monday, February 15, 2016 12:23:57 PM(UTC)  | Reason: Not specified

thanks 1 user thanked marcschoemann@gmail.com for this useful post.
sample@email.tst on 4/7/2024(UTC)
EmbrioAdmin  
#4 Posted : Monday, February 15, 2016 12:28:43 PM(UTC)
EmbrioAdmin

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 661

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
I don't know how much I can help debug it without the hardware. All I can suggest is that you start simple add complexity until you get it all working. If you come across a problem that you can't explain let me know.
thanks 1 user thanked EmbrioAdmin for this useful post.
sample@email.tst on 4/7/2024(UTC)
marcschoemann@gmail.com  
#5 Posted : Tuesday, February 16, 2016 10:53:06 AM(UTC)
marcschoemann@gmail.com

Rank: Newbie

Groups: Registered
Joined: 5/23/2015(UTC)
Posts: 4

Was thanked: 3 time(s) in 3 post(s)
The Problem seems to be that the Gyro outputs angular speed not, not angular position.
Therefore it needs to be summed up during the refresh rate (which seems to be 1/32s?)
descibed here: http://playground.arduino.cc/Main/Gyro

I feel very foolish because the solution is right in front of me but i fail to integrate it.

//Ignore the gyro if our angular velocity does not meet our threshold
if (gyroRate >= rotationThreshold || gyroRate <= -rotationThreshold) {
//This line divides the value by 100 since we are running in a 10ms loop (1000ms/10ms)
gyroRate /= 100;
currentAngle += gyroRate;
}

This seems to be the solution but i don´t know how i get the gyroRate Variable...
thanks 1 user thanked marcschoemann@gmail.com for this useful post.
sample@email.tst on 4/7/2024(UTC)
EmbrioAdmin  
#6 Posted : Wednesday, February 17, 2016 3:03:57 PM(UTC)
EmbrioAdmin

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 661

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
Yeah in the bottom right of an agent is a "refresh rate" drop down that selects how many times per second the agent updates. There should be a helper function that an Arduino node can use to get the refresh rate, I'll put that on the to-do list.

Note that if something updates 32 times per second, it updates ever 31.25 milliseconds, not 10, hopefully that is what's causing your issue.

If you're still stuck, copy and paste the full node here so I can see exactly what you're doing.

Edited by user Wednesday, February 17, 2016 3:05:05 PM(UTC)  | Reason: Last line.

thanks 1 user thanked EmbrioAdmin for this useful post.
sample@email.tst on 4/7/2024(UTC)
marcschoemann@gmail.com  
#7 Posted : Thursday, February 18, 2016 5:48:01 AM(UTC)
marcschoemann@gmail.com

Rank: Newbie

Groups: Registered
Joined: 5/23/2015(UTC)
Posts: 4

Was thanked: 3 time(s) in 3 post(s)
Im getting compiling errors all the way, mostly undeclared Variables.
Here is the Node, the Input is hooked up to the GyX output.

<EmbrioCopy>
<Version>1.3.6.0</Version>
<Nodes>
<Node>
<UniqueID>29150abf-85a1-4703-8f1f-f88ce671bb87</UniqueID>
<AssemblyType>Embrio.NodeEngine.AgentController.Nodes.AgentControllerCustomArduinoNode</AssemblyType>
<NodeType>Custom Arduino Node</NodeType>
<UserDefinedName>Custom Arduino Node</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>201,204,227,255</NodeColor>
<X>0</X>
<Y>0</Y>
<Width>734</Width>
<IncludeCode></IncludeCode>
<DeclerationCode>float currentAngle = 0; //Keep track of our current angle
float rotationThreshold = 1;
int16_t Input_GyroRate;</DeclerationCode>
<SetupCode></SetupCode>
<ImageName>arduino.png</ImageName>
<InfoURL></InfoURL>
<IsOpen>True</IsOpen>
<EditWidth>360</EditWidth>
<CodeDefinitions>
<CodeDefinition>
<UpdateCondition>EveryUpdate</UpdateCondition>
<Code>if (gyroRate &amp;gt;= rotationThreshold || gyroRate &amp;lt;= -rotationThreshold) {
gyroRate /= 32;
currentAngle += gyroRate;
}

if (currentAngle &amp;lt; 0)
currentAngle += 360;
else if (currentAngle &amp;gt; 359)
currentAngle -= 360;

Output_Result = currentAngle</Code>
<UniqueID>307e9860-33e0-4837-b6ad-f80f9568f71e</UniqueID>
</CodeDefinition>
</CodeDefinitions>
<Inputs>
<Input>
<UniqueID>0468cbea-4c03-4a06-9064-8d0f03a152d9</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Activation</DefaultName>
<CustomName>GyroRate</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Numeric</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.NumericNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<ConnectedOutputs></ConnectedOutputs>
<BlendMode>Add</BlendMode>
<DisconnectedValue>0</DisconnectedValue>
<UseNegativeRange>False</UseNegativeRange>
<CanUseNegativeRange>True</CanUseNegativeRange>
</Input>
</Inputs>
<Outputs>
<Output>
<UniqueID>2be0f914-dd7b-486f-9ba2-ed3dae365a06</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Integer</DefaultName>
<CustomName>Result</CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Integer</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.IntegerNodeOutput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<MinValue>0</MinValue>
<MaxValue>100</MaxValue>
</Output>
</Outputs>
</Node>
</Nodes>
</EmbrioCopy>

Edited by user Thursday, February 18, 2016 5:56:58 AM(UTC)  | Reason: Not specified

thanks 1 user thanked marcschoemann@gmail.com for this useful post.
sample@email.tst on 4/7/2024(UTC)
EmbrioAdmin  
#8 Posted : Thursday, February 18, 2016 2:53:47 PM(UTC)
EmbrioAdmin

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 661

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
I cleaned up your node a bit, you were getting some stuff with accessing the input value mixed up. You also uncovered a bug where putting a - before a variable messes up the compile which was preventing you from seeing it. I'll fix that in the next update, for now I multiplied the variable by -1 written out.

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.

Notification

Icon
Error