Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Raspberry Pi / How to manipulate servo?

Author
Message
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 22nd Jan 2018 12:54
Hello everybody.
I read a WIP thread about RC car using AppGameKit for Raspberry Pi. https://forum.thegamecreators.com/thread/211666
May I know how we can command the servo using AppGameKit commands?
I'm just trying to manipulate a servo using AppGameKit for Raspberry Pi, but I can't see any command for doing that. Or what value should I put in.
Thanks in advance. Really need the help because I don't have much experience with this...
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 22nd Jan 2018 13:39 Edited at: 22nd Jan 2018 13:46
On the PI you can have control of the GPIO pins by using the file functions OpenToWrite() and WriteByte()

AGK Documentation wrote: "On Raspberry Pi you can use this command to open a GPIO pin for writing by using the filename "gpio:" followed by the GPIO pin number, for example OpenToWrite(1, "gpio:4"), this is case sensitive. You can then use WriteByte to write 0 or 1 to the pin and CloseFile to close the pin."


This allows you so set a pin voltage high or low.


It doesnt allow you to set up hardware controlled PWM on a pin or to use the UART or SPI pins. You can make a crude PWM output based on timers in side of AGK2 by turning the pin on and off at regular intervals.

PLEASE NOTE: These functions just set the pin voltages and you would still need to connect a servo driver PCB or IC to actually control a motor. The pin alone doesnt have enough current sourcing capability to drive a servo/motor by itself

For hardware PWM, you would need to write a teir 2 program or a plugin to access the more complex I/O functionality through wiringpi or BCM8235 libraries.
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 22nd Jan 2018 13:50 Edited at: 22nd Jan 2018 13:53
I see. So it's impossible to control servo using PMW in tier 1, without importing the libraries?
In that thread I linked, the author said he controlled using software pulse width modulation on the PI. How did he do that? By importing libraries in Tier 2?
Or I still can control it using OpenToWrite(1, "gpio:4"), then use WriteByte to that pin on each loop? Don't know what bytes I should write lol. guess it's impossible after all...
Just wanted to make sure of its impossibilities in Tier 1, before I force myself to learn Phyton (brrrr)
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 22nd Jan 2018 14:09
No its not impossible .....You can do software PWM as I said above:
Ben wrote: "You can make a crude PWM output based on timers inside of AGK2 by turning the pin on and off at regular intervals."


So you would set up a loop and turn the pin on for a set amount of time then off for a set amount of time. You would simply choose which pin you want to use then write 1 to it for 10mS then write 0 to it for 10mS etc...(you would need to turn off Vsync if you also rendering graphics to get the loop to run this quickly)

The hardware solution is much better but... you would need a plugin for Teir 1 or to import library functions to do it in tier 2. Writing in python or C on the PI is the easiest way to do it.


hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 22nd Jan 2018 22:45
I see, so its sort of possible in tier 1. I'll try it when the servos arrived from shipping. Will ask again here later. Thank you very much for the clarifications!
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 22nd Jan 2018 23:37 Edited at: 22nd Jan 2018 23:38
With RC servos its typically a case of driving the control pin high for between 1ms and 2ms to set the servo position (Fully left to fully right) but it depends on exact model. This is typically repeated around every 20-50mS or so to constantly update it , again depending on model.

You have to get the timing very quick for it to work well. I can post some example code if you get stuck.

It would be great if we had more control over the pi hardware from AppGameKit as the hardware can be used to do this so that no super quick software loops are needed. With the hard ware its a case of set the position once and the hardware just sorts it out.
hakimfullmetal
9
Years of Service
User Offline
Joined: 17th Feb 2015
Location:
Posted: 23rd Jan 2018 06:13
I see. I heard AppGameKit for Pi is only limited to 60fps. If I were to switch on/off the gpio pin alternately in Tier 1, so each loop the smallest miliseconds I can get would be around 15ms each loop, which is not really good?

And I wonder how would I be able to read and separate gyroscope input, since it has x y z axis, so 3 separate values... Trying to make a self-balancing robot leg, so currently I'm trying to see what is possible in AppGameKit Tier 1. Worst comes to worst I'll have to learn Phyton instead and code it directly in Raspberry Pi...

Login to post a reply

Server time is: 2024-03-29 11:01:53
Your offset time is: 2024-03-29 11:01:53