I made one myself a couple of years ago, and yes, it was a fair bit of trial and error to get it working.
Of course, the gain values will be dependent on a number of factors, for example, the torque constant of your motor, the gear ratio, the mass of the robot, where your centre of gravity is located, your loop rate, and where you've located your mpu-6050.
I located my mpu-6050 over the axis at 12 o'clock near the vertical centre of my bot.
What are you control variables?
I used pitch (angle of rotation around motor axis) calculated from gx, gz and tan function.
I also used pitch rate from the gyro.
Are you using the onboard DSP of the mpu-6050 to do the calculations?
I had no luck with this, the mpu-6050 kept freezing up, bad clone I guess.
You also have to verify the direction of rotation of your motor versus your control variables.
If you have the wrong direction, it will just run away.
My gains are Kp:41, Ki:160, Kd:0.4
I started with only Kp and kept increasing the value until the system became unstable, then I backed off to a stable point.
Next, I began increasing Ki. This will bring you to steady state stability. It should balance itself when Kp & Ki.
You will likely have to reduce Kp somewhat as you move to higher Ki values, if your system becomes unstable.
Finally, I added Kd, to help it react more quickly to changes in angle.
How do you change your gains?
I have a bluetooth module on mine, to allow me to send serial commands to the robot, to set the gains and other things.
My robot's biggest problem is gear backlash. This generates acceleration noise as it vibrates backward/forward, balancing itself. This vibration can feedback on itself and cause instability (when you increase Kp too high). It looks like the robot has Parkinsons when this happens!
I'd like to update my design to use a belt/gear drive or continuous rotation servo, but I haven't had a chance to get back to it.
I hope this helps.
Success! In all my testing and trying new settings, I missed that I had commented out on the gateway the frequency setting. It was noobie mistake and I want to thank all of you for your help. I ended up using @FarmerEd's sketches to get my gateway and sensor to work.
Is your relay coil connected directly to Arduino pin?
It draws too much current, this needs to be powered through transistor or use ready made module:
Based on the quite useful reverse engineered schematic at https://hackaday.io/project/174308-tradfri-pir-motion-sensor-hacking the measurements were somewhat sabotaged by the 2N7002 (see Connors comment "enables voltage dividers only when triggered").
the transistor is controlled by the Elmos E931.96 PIR motion controller IC.
The latter is programmable by the IKEA TRÅDFRI ICC-1 module's EFR32MG1P132F256GM32 MCU.
2. Blind Time
Ignores motion after the interrupt output is switched back to 0
Range: 0.5s... 8s.
The blind time is [Register Value] *0.5s
3. Programmable pulse counter
1... 4 pulses with sign change in between
Amount of pulses = [Register Value] + 1
4. Window time
For noisy environments
2s... 8s window
Window time = [Register Value] * 2s + 2s
https://github.com/basilfx/TRADFRI-Hacking gives a good overview on that.
What is the issue with tose 60s?
I'm not really familiar with FHEM, but as far as the MySensors side, you still need the gateway software running. However, this code can run directly on a Raspberry Pi, at least with a radio network for the MySensors transport. I haven't ever used RS485 myself, but I would think it would be similar.
At least the code itself has sections for dealing with running on Linux, which is what is used when running it on the RPi, so I think you're good. https://github.com/mysensors/MySensors/blob/master/hal/transport/RS485/MyTransportRS485.cpp
The gateway code runs as a systemctl service, so it can easily run in parallel with most things, so probably wouldn't conflict with FHEM on the same device.
Oh yeah, and in case you haven't found it, there's this page: https://www.mysensors.org/build/rs485