linux systems startup stuff for a servo controller daemon

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

linux systems startup stuff for a servo controller daemon

timrowledge
 
This is a bit off topic but since it is for Squeak to be able to easily control PWM devices it shouldn’t upset anyone too much…

I’ve written a daemon to run on a Pi that provides /dev/pca9685servo so you can write commands to move a servo using a HAT that has a PCA9685 pwm chip. It in turn uses the pigpiod daemon that handles the i2c communications for me. It all works quite nicely *except*….

So, if I build the daemon and install it by doing the usual sort of terminal dance
sudo make install
then the code builds and gets copied and the init-script copied and all appears to be well. I can then do
echo 0=50% > /dev/pca9685servo
and have the servo connected to port 0 move to the centre of its range.
echo o=+10% > /dev/pca9685servo
will move it by 10% - you get the picture I’m sure. There a bucket load of options with some explanation in the help message.

Sounds great! Except if I reboot the Pi things go weird. Part of the problem is likely that the init-script is an old-style inti.d file and not a systemd unit file. Part is that it doesn’t automatically start pigpiod, so I have to manually do that and restart the pca9685servo daemon. If I do that, the status claism all is well. I can send commands. But nothing happens to the servos. Sigh.

If I kill the daemon with
sudo systemctl stop pca9685servo
and then manually start it with
sudo /usr/local/sbin/pca9685servod
well then my servos move around like the willing servants they are meant to be.

I’ve been around and around on this far too many times for my sanity and I could do with some advice/assistance from someone that actually has a grip on this level of stuff. Since the source tgz is a whole 8Kb I’ll just attach it here -



tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange OpCodes: PSP: Push Stack Pointer



pca9685servod.tgz (10K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: linux systems startup stuff for a servo controller daemon

David T. Lewis
 
On Wed, Jan 10, 2018 at 05:42:40PM -0800, tim Rowledge wrote:

>  
> This is a bit off topic but since it is for Squeak to be able to easily control PWM devices it shouldn???t upset anyone too much???
>
> I???ve written a daemon to run on a Pi that provides /dev/pca9685servo so you can write commands to move a servo using a HAT that has a PCA9685 pwm chip. It in turn uses the pigpiod daemon that handles the i2c communications for me. It all works quite nicely *except*???.
>
> So, if I build the daemon and install it by doing the usual sort of terminal dance
> sudo make install
> then the code builds and gets copied and the init-script copied and all appears to be well. I can then do
> echo 0=50% > /dev/pca9685servo
> and have the servo connected to port 0 move to the centre of its range.
> echo o=+10% > /dev/pca9685servo
> will move it by 10% - you get the picture I???m sure. There a bucket load of options with some explanation in the help message.
>
> Sounds great! Except if I reboot the Pi things go weird. Part of the problem is likely that the init-script is an old-style inti.d file and not a systemd unit file. Part is that it doesn???t automatically start pigpiod, so I have to manually do that and restart the pca9685servo daemon. If I do that, the status claism all is well. I can send commands. But nothing happens to the servos. Sigh.
>
> If I kill the daemon with
> sudo systemctl stop pca9685servo
> and then manually start it with
> sudo /usr/local/sbin/pca9685servod
> well then my servos move around like the willing servants they are meant to be.
>
> I???ve been around and around on this far too many times for my sanity and I could do with some advice/assistance from someone that actually has a grip on this level of stuff. Since the source tgz is a whole 8Kb I???ll just attach it here -


From looking at the Makefile, I would say that the init script is being
installed but it has not been wired into the system boot processing.
Possibly the person who wrote the makefile left that part as an "exercise
for the reader".

Give this a try and see if it works: Reboot the Pi, at which point the servo
will not be working. Then run this command (possibly with sudo in front if
it if you are not root):

# /etc/init.d/pca9685servo start

At this point, the servo will probably be working.

If the above works out, then you will just need to set up a symlink to
one of the /etc/rc?.d/ directories. That will cause the init script to be
run when the system boots up.

Let me know if this works, and if so we'll figure out the symlink to add.

Dave

Reply | Threaded
Open this post in threaded view
|

Re: linux systems startup stuff for a servo controller daemon

timrowledge
 

> On 10-01-2018, at 7:53 PM, David T. Lewis <[hidden email]> wrote:
>
> From looking at the Makefile, I would say that the init script is being
> installed but it has not been wired into the system boot processing.
> Possibly the person who wrote the makefile left that part as an "exercise
> for the reader”.

The odd thing is that it does appear to try to start on boot (but inevitably fails because pigpiod is not autostarted) and I see

systemctl status pca9685servo
● pca9685servo.service - LSB: Start/stop pca9685servod.
   Loaded: loaded (/etc/init.d/pca9685servo; generated; vendor preset: enabled)
   Active: inactive (dead)


>
> Give this a try and see if it works: Reboot the Pi, at which point the servo
> will not be working. Then run this command (possibly with sudo in front if
> it if you are not root):
>
> # /etc/init.d/pca9685servo start

This gets a bit odder seeming to me -

pi@PiCamera-1:~ $ sudo /etc/init.d/pca9685servo start
Device address = 0x40
Requested servo cycle time:          20000.000us
Pulse increment step size:    5.000us
Setting prescale value to: 121
Actual frequency:   50.029
Actual cycle time: 19988.480us
Minimum width value:        500.000us (100)
Maximum width value:       2500.000us (500)

Setting prescale value to: 121
pi@PiCamera-1:~ $ echo  0=70% > /dev/pca9685servo
Raw width input = 70.000000
% specified -> 0.700000
set servo[0]=70.000000 %
servo on: 0 off: 389

… but the servo doesn’t move.
Another status check -
pi@PiCamera-1:~ $ systemctl status pca9685servo
● pca9685servo.service - LSB: Start/stop pca9685servod.
   Loaded: loaded (/etc/init.d/pca9685servo; generated; vendor preset: enabled)
   Active: inactive (dead)

ps aux says there is only one pca daemon running.
So let’s try stopping it … ok, no pca running anymore. Run it completely manually -
pi@PiCamera-1:~ $ sudo /usr/local/sbin/pca9685servod Device address = 0x40
Requested servo cycle time:          20000.000us
Pulse increment step size:    5.000us
Setting prescale value to: 121
Actual frequency:   50.029
Actual cycle time: 19988.480us
Minimum width value:        500.000us (100)
Maximum width value:       2500.000us (500)

Setting prescale value to: 121
pi@PiCamera-1:~ $ echo  0=70% > /dev/pca9685servo
Raw width input = 70.000000
% specified -> 0.700000
set servo[0]=70.000000 %
servo on: 0 off: 389

.. servo moves as expected. Gronk?

If i completely remove the /etc/init.d/pca9685servo script to make sure it can’t autostart and reboot then I do actually get to restart from clean.
pi@PiCamera-1:~ $ ps aux | grep pca
pi        1195  0.0  0.0   4380   576 pts/0    S+   12:21   0:00 grep --color=auto pca

And to make life still more annoying manually starting the daemon results in no servo motion.

Reboot once more; no pigpiod nor pca runnig.
start pigpiod
start pca
ps says both running
try to move servo - nope.

pi@PiCamera-1:~ $ systemctl status pca9685servo
● pca9685servo.service - LSB: Start/stop pca9685servod.
   Loaded: loaded (/etc/init.d/pca9685servo; generated; vendor preset: enabled)
   Active: active (running) since Thu 2018-01-11 12:30:16 PST; 3min 21s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1231 ExecStart=/etc/init.d/pca9685servo start (code=exited, status=0/
   CGroup: /system.slice/pca9685servo.service
           └─1238 /usr/local/sbin/pca9685servod

Jan 11 12:30:16 PiCamera-1 systemd[1]: Started LSB: Start/stop pca9685servod..
Jan 11 12:30:34 PiCamera-1 pca9685servo[1231]: Raw width input = 70.000000
Jan 11 12:30:34 PiCamera-1 pca9685servo[1231]: % specified -> 0.700000
Jan 11 12:30:34 PiCamera-1 pca9685servo[1231]: set servo[0]=70.000000 %
Jan 11 12:30:34 PiCamera-1 pca9685servo[1231]: servo on: 0 off: 389
Jan 11 12:30:40 PiCamera-1 pca9685servo[1231]: Raw width input = 10.000000
Jan 11 12:30:40 PiCamera-1 pca9685servo[1231]: Add 0.100000 to 0.700000 = 0.8000
Jan 11 12:30:40 PiCamera-1 pca9685servo[1231]: % specified -> 0.800000
Jan 11 12:30:40 PiCamera-1 pca9685servo[1231]: set servo[0]=80.000000 %
Jan 11 12:30:40 PiCamera-1 pca9685servo[1231]: servo on: 0 off: 430

So clearly it is running and receiving commands but failing at something. If I kill that incarnation and manually start with
pi@PiCamera-1:~ $ sudo /usr/local/sbin/pca9685servod
then my servo moves.

Is everyone else as baffled as me?

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange OpCodes: D: Detonate


Reply | Threaded
Open this post in threaded view
|

Re: linux systems startup stuff for a servo controller daemon

David T. Lewis
 
On Thu, Jan 11, 2018 at 12:44:35PM -0800, tim Rowledge wrote:

>  
>
> > On 10-01-2018, at 7:53 PM, David T. Lewis <[hidden email]> wrote:
> >
> > From looking at the Makefile, I would say that the init script is being
> > installed but it has not been wired into the system boot processing.
> > Possibly the person who wrote the makefile left that part as an "exercise
> > for the reader???.
>
> The odd thing is that it does appear to try to start on boot (but inevitably fails because pigpiod is not autostarted) and I see
>
> systemctl status pca9685servo
> ??? pca9685servo.service - LSB: Start/stop pca9685servod.
>    Loaded: loaded (/etc/init.d/pca9685servo; generated; vendor preset: enabled)
>    Active: inactive (dead)
>

I'm pretty much shooting in the dark here, but it sounds like your pca9685servod
daemon depends on the pigpiod daemon, and maybe the former fails to start cleanly
if the latter has not previously been started.

Maybe you just need to make sure that pigpiod is autostarted at boot time. Here
is a link that might help:

  https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=103752

Dave


>
> >
> > Give this a try and see if it works: Reboot the Pi, at which point the servo
> > will not be working. Then run this command (possibly with sudo in front if
> > it if you are not root):
> >
> > # /etc/init.d/pca9685servo start
>
> This gets a bit odder seeming to me -
>
> pi@PiCamera-1:~ $ sudo /etc/init.d/pca9685servo start
> Device address = 0x40
> Requested servo cycle time:          20000.000us
> Pulse increment step size:    5.000us
> Setting prescale value to: 121
> Actual frequency:   50.029
> Actual cycle time: 19988.480us
> Minimum width value:        500.000us (100)
> Maximum width value:       2500.000us (500)
>
> Setting prescale value to: 121
> pi@PiCamera-1:~ $ echo  0=70% > /dev/pca9685servo
> Raw width input = 70.000000
> % specified -> 0.700000
> set servo[0]=70.000000 %
> servo on: 0 off: 389
>
> ??? but the servo doesn???t move.
> Another status check -
> pi@PiCamera-1:~ $ systemctl status pca9685servo
> ??? pca9685servo.service - LSB: Start/stop pca9685servod.
>    Loaded: loaded (/etc/init.d/pca9685servo; generated; vendor preset: enabled)
>    Active: inactive (dead)
>
> ps aux says there is only one pca daemon running.
> So let???s try stopping it ??? ok, no pca running anymore. Run it completely manually -
> pi@PiCamera-1:~ $ sudo /usr/local/sbin/pca9685servod Device address = 0x40
> Requested servo cycle time:          20000.000us
> Pulse increment step size:    5.000us
> Setting prescale value to: 121
> Actual frequency:   50.029
> Actual cycle time: 19988.480us
> Minimum width value:        500.000us (100)
> Maximum width value:       2500.000us (500)
>
> Setting prescale value to: 121
> pi@PiCamera-1:~ $ echo  0=70% > /dev/pca9685servo
> Raw width input = 70.000000
> % specified -> 0.700000
> set servo[0]=70.000000 %
> servo on: 0 off: 389
>
> .. servo moves as expected. Gronk?
>
> If i completely remove the /etc/init.d/pca9685servo script to make sure it can???t autostart and reboot then I do actually get to restart from clean.
> pi@PiCamera-1:~ $ ps aux | grep pca
> pi        1195  0.0  0.0   4380   576 pts/0    S+   12:21   0:00 grep --color=auto pca
>
> And to make life still more annoying manually starting the daemon results in no servo motion.
>
> Reboot once more; no pigpiod nor pca runnig.
> start pigpiod
> start pca
> ps says both running
> try to move servo - nope.
>
> pi@PiCamera-1:~ $ systemctl status pca9685servo
> ??? pca9685servo.service - LSB: Start/stop pca9685servod.
>    Loaded: loaded (/etc/init.d/pca9685servo; generated; vendor preset: enabled)
>    Active: active (running) since Thu 2018-01-11 12:30:16 PST; 3min 21s ago
>      Docs: man:systemd-sysv-generator(8)
>   Process: 1231 ExecStart=/etc/init.d/pca9685servo start (code=exited, status=0/
>    CGroup: /system.slice/pca9685servo.service
>            ??????1238 /usr/local/sbin/pca9685servod
>
> Jan 11 12:30:16 PiCamera-1 systemd[1]: Started LSB: Start/stop pca9685servod..
> Jan 11 12:30:34 PiCamera-1 pca9685servo[1231]: Raw width input = 70.000000
> Jan 11 12:30:34 PiCamera-1 pca9685servo[1231]: % specified -> 0.700000
> Jan 11 12:30:34 PiCamera-1 pca9685servo[1231]: set servo[0]=70.000000 %
> Jan 11 12:30:34 PiCamera-1 pca9685servo[1231]: servo on: 0 off: 389
> Jan 11 12:30:40 PiCamera-1 pca9685servo[1231]: Raw width input = 10.000000
> Jan 11 12:30:40 PiCamera-1 pca9685servo[1231]: Add 0.100000 to 0.700000 = 0.8000
> Jan 11 12:30:40 PiCamera-1 pca9685servo[1231]: % specified -> 0.800000
> Jan 11 12:30:40 PiCamera-1 pca9685servo[1231]: set servo[0]=80.000000 %
> Jan 11 12:30:40 PiCamera-1 pca9685servo[1231]: servo on: 0 off: 430
>
> So clearly it is running and receiving commands but failing at something. If I kill that incarnation and manually start with
> pi@PiCamera-1:~ $ sudo /usr/local/sbin/pca9685servod
> then my servo moves.
>
> Is everyone else as baffled as me?
>
> tim
> --
> tim Rowledge; [hidden email]; http://www.rowledge.org/tim
> Strange OpCodes: D: Detonate
>
>
Reply | Threaded
Open this post in threaded view
|

Re: linux systems startup stuff for a servo controller daemon

timrowledge
 

> On 11-01-2018, at 4:15 PM, David T. Lewis <[hidden email]> wrote:
>
> I'm pretty much shooting in the dark here,

Me too - with a blindfold!

> but it sounds like your pca9685servod
> daemon depends on the pigpiod daemon, and maybe the former fails to start cleanly
> if the latter has not previously been started.
>
> Maybe you just need to make sure that pigpiod is autostarted at boot time. Here
> is a link that might help:

Happily there is a systemd service for pigpiod so that was easy to set up. Makes no difference at all though, apart from saving me from remembering to manually start it!

I’ve rebooted and powered off so many times I’ve lost count. I’ve added a load of debug output that shows that at least on some occasions the commands to move the servo are not being accepted. Still, if I `sudo make install` it works and if I do almost anything else it doesn’t. If it was completely consistent I might have a chance of working it out I guess.

Anyway I have to leave it alone for a while now in order to finish writing The Complete Beginners Guide to Starting with a Pi ready for Weds.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange OpCodes: RJT: Read and Jam Tape