You’re in luck. I’ve been working on this exact thing for a few years now, and even made a General Grievous MOC to go with it. Link
That’s my most recent design, which has the most range of motion, but I also have a slightly older version that I go into more detail on in my self-MOC topic. Link
I also have a design that’s a little outdated now, but uses actual Lego pistons, and ball joints. It’s larger in size, but it’s a bit more reliable. Link
If you have more questions about this, let me know.