1

I am trying to control a servo motor from a web interface. I am using SpringBoot 2.0, ServoBlaster and pi4j.

In order to start the application I am running as root ./gradlew bootrun --no-daemon. It has to be root in order to handle the GPIOs and I don't have any security worries about the device.

In simplified (a class with just the main function) Java/Kotlin I achieved to control the servo by any of the following ways:

  1. RPIServoBlasterProvider

    val servoProvider = RPIServoBlasterProvider() val servo0 = servoProvider.getServoDriver(servoProvider.definedServoPins[5]) println("Go to 150") //middle servo0.servoPulseWidth = 150 println("Went to ${servo0.servoPulseWidth}") Thread.sleep(1550)

  2. Write to /dev/servoblaster

    val out = PrintWriter(FileOutputStream("/dev/servoblaster"), true) println("Go to 65 again") out.println("5=65") out.flush() out.close

  3. Call a secondary script which writes to /dev/servoblaster

    val servoId = 5 val script = "/home/pi/ServoHardwareSteering.sh" val cmdMinPosition = "$script $servoId 65" val cmdMidPosition = "$script $servoId 150" val cmdMaxPosition = "$script $servoId 235" val runtime = Runtime.getRuntime() println(cmdMidPosition) runtime.exec(cmdMidPosition)//.waitFor() Thread.sleep(1550)

  4. Write the value to a file and have a secondary execute reading this file and applying this value to the servo

I have tried all of the above in Springboot but without success.

So the question is, could somebody tell me how could I:

  1. use the RPIServoBlasterProvider class from Springboot? OR
  2. write to /dev/servoblaster? OR
  3. execute any terminal script? OR
  4. where to save the script in order to be able to call it OR
  5. write to a simple file (ex. afile.txt)? OR
  6. solve the issue in a better way that I did not think about already.

Solutions at any of the above questions could help me solve my problem.

PS: Is there anything wrong with the blockquote for the source code in stackoverflow? I could not format it as a block and I used the line code formatting!

LiTTle
  • 1,811
  • 1
  • 20
  • 37

2 Answers2

0
use the RPIServoBlasterProvider class from Springboot? OR

The same you did before - its Java (kotlin is based on) - or just use Kotlin with Spring https://spring.io/guides/tutorials/spring-boot-kotlin/

write to /dev/servoblaster? OR

The same like you did - everything is a file in linux, thus its writing to a ordinary file

execute any terminal script? OR

Runtime.getRuntime.exec - any variant or ProcessBuilder

where to save the script in order to be able to call it OR

Anywhere

write to a simple file (ex. afile.txt)? OR

point 2.

solve the issue in a better way that I did not think about already.

No experience with servo blaster.

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • I already have said that `I have tried all of the above in Springboot but without success.`. I would a prefer an answer containing source code or link to examples. – LiTTle Dec 16 '19 at 07:38
  • You obviously did it wrong and you haven't include any meaningfull code + nobody knows whats wrong with it. That's the best you can get now. – Antoniossss Dec 16 '19 at 08:46
  • I am going to try it once again and I will come back with more info. – LiTTle Dec 16 '19 at 08:57
0

The whole problem was with the servod of the ServoBlaster. It was accidentally killed and I had to run it once again! I followed the No 5 solution.

LiTTle
  • 1,811
  • 1
  • 20
  • 37