This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
No communication between RPi and Nano using pypilot service
#1
Hi everyone

I'm building a navigation system including pypilot, and I'm currently having som trouble getting pypilot to talk to the Arduino. Below is a list of my hardware and the software I've installed.

Hardware:
RPi4, 8 GB with 64 GB SD-card in HighPi Case with fan
IMU 9250 mounted on snappable protoboard as a HAT
Arduino Nano (original) connected to RPi via USB cable
GPS on a USB cable
Keyboard, mouse and 13.3" screen
Potmeter for rudder sense

Breadboard, various wires, cables, resistors, LEDs and whatnot
Two channel 5V relay for allowing 12V signal to rudder control. The boat has permanent hydraulic pressure available, and the rudder is controlled by opening one of two sets of solenoid valves - so no pwm is required, just 12V for either starboard or port. Trying to move the rudder past end of travel has no consquence, the rudder just stops.

Software:
Lysmarine BBN 2022-06-23 (OpenPlotter 2 won't boot on my RPi 4, unfortunately)
OpenCPN 5.6.2
Pypilot plugin 0.34.4.0
Pypilot 0.34

I've used Arduino IDE (preinstalled in BBN, version 1.8.16) to install motor.ino onto the Arduino after applying below changes:
Disabled temp-sense
Disabled voltage-sense
clutch_pwm = 255 (is this the correct way to apply full signal without pwm ramp-up?)


When I start the pypilot plugin in OpenCPN, it is disconnected from pypilot. After hitting config and OK it connects (127.0.0.1), but reports "No Motor Controller" (and Tx and Rx on Nano stay off). Using terminal to first stop pypilot service (sudo service pypilot@pypilot stop) and then run it (pypilot), the OpenCPN plugin changes state to idle, and Tx and Rx start flashing.

I've grounded all analog pins on the Nano (except A4) through 1kOhm each, and connected A4 to the center pin of the potmeter, with the two outer pins connected to 3.3V and GND, respectively. Measuring the voltage between A4 and either 3.3V or GND using a voltmeter gives the expected values (perfectly linear from 0 to 3.3V when turning the potmeter), but in pypilot calibration, the rudder mostly reports False with sometimes erratic values (both positive and negative, sometimes within +/- 10, sometimes above or below 1000 - potmeter position doesn't seem to influence this value).

Is there a difference between the services pypilot and pypilot@pypilot, and could this have anything to do with my troubles?


To sum up, I have the following questions:
1. Is "clutch_pwm = 255" in motor.ino the correct way to disable ramp-up for rudder control?
2. Why does pypilot service fail to communicate with the Nano when pypilot run in terminal does?
3. Why does pypilot not read A4 correctly for rudder sense?
4. Which pins on the Nano should I use for controlling the relay (one pin for starboard and one pin for port)?


Thank you in advance Smile

Best regards, Jonas.
Reply
#2
1) clutch pwm is normally set from pypilot so this setting you can change from web etc (unless old version and uses this default)
2) the service may run it as a user that has wrong permissions to access usb ?
3) the range in RC mode or hbridge mode is 0-1.1v not 0-3.3v for ratiometric mode 0-5

if you are really running the nano at 3v3 that would be very odd. It is running at 5 volts correct?


4 depending on mode (described in comment), for hbridge try d2 and d3
Reply
#3
(2022-07-21, 04:33 PM)seandepagnier Wrote: 1) clutch pwm is normally set from pypilot so this setting you can change from web etc (unless old version and uses this default)
2)  the service may run it as a user that has wrong permissions to access usb ?
3)  the range in RC mode or hbridge mode is 0-1.1v not 0-3.3v   for ratiometric mode 0-5

if you are really running the nano at 3v3 that would be very odd.   It is running at  5 volts correct?


4   depending on mode (described in comment), for hbridge try d2 and d3

Hi Sean

Thank you for your quick reply, both by e-mail and here Smile

1) Going into pypilot Calibration -> Settings, I see that both servo.speed.max and servo.speed.min are set to 100 %, so I guess this is based on clutch pwm in motor.ino and that everything is as I want it Smile

2) To check the user running pypilot service:
user@lysmarine:~ $ systemctl show -pUser,UID pypilot
UID=[not set]
User=pi

So it looks like the service is run by the user "pi", although the user I'm logged in as is named "user". Based on https://forum.arduino.cc/t/permission-de.../475568/11 I tried "sudo adduser pi dialout" and "sudo usermod -a -G dialout pi", but both reported that the user pi does not exist. Is there any way to change the service to be run by "user" instead of "pi"?

3) The Arduino Nano is connected via USB, so it is indeed running at 5V (there's only 4.5V on the 5V pin, though, but I guess that's ok). I am using the 3.3V pin from the Arduino to power the potmeter (48.8kOhm). I've just now inserted a 100kOhm resistor before the pot, which reduces the center pin to 0-1.1V, and pypilot registers rudder sense perfectly now (and can calibrate as intended), and OpenCPN dashboard updates as intended - I am very happy now Smile

I'm considering connecting the RPi and Nano via wires instead of USB, but that will be in the next iteration. USB is fine for now.

4) I've changed pwm_style to 0 (h-bridge) and uploaded motor.ino to the nano again. Then I tested the different D-pins using a 1kOhm resistor and a LED. I tested using the center rudder function to obtain either idle, forward or reverse. Below are the pins that made the LED light up:
Idle: D4, 5, 6, 7, 8, 12, 13 (flashing very bright)
Forward: D4, 5, 6, 7, 8, 9, 11 (very bright), 12, 13 (very bright)
Reverse: D4, 5, 6, 7, 8, 9, 11 (very bright), 12, 13 (very bright)

I then repeated the same test with pwm_style = 1 and 2, and got the same results. I don't see any activity on D2 or D3.

I will test more in the coming few days.
Reply
#4
(2022-07-22, 11:32 PM)Jonas.EH Wrote: 1) Going into pypilot Calibration -> Settings, I see that both servo.speed.max and servo.speed.min are set to 100 %, so I guess this is based on clutch pwm in motor.ino and that everything is as I want it Smile

No this is actual motor speed.  The clutch pwm is a different setting that reduces the duty cycle on the clutch output (often a solenoid) to save power since it doesn't need much to hold it on.   For example, without this there could be a 1-2 amp current through the clutch and this can reduce it to a few hundred milliamps.
Quote:2) To check the user running pypilot service:
user@lysmarine:~ $ systemctl show -pUser,UID pypilot
UID=[not set]
User=pi

So it looks like the service is run by the user "pi", although the user I'm logged in as is named "user". Based on https://forum.arduino.cc/t/permission-de.../475568/11 I tried "sudo adduser pi dialout" and "sudo usermod -a -G dialout pi", but both reported that the user pi does not exist. Is there any way to change the service to be run by "user" instead of "pi"? c
Generally you can edit the scripts in /etc/systemd   Try to find the pypilot one, eg: find /etc/systemd | grep pypilot and change the user in the script.
Quote:3) The Arduino Nano is connected via USB, so it is indeed running at 5V (there's only 4.5V on the 5V pin, though, but I guess that's ok).
Yes, 4.5v is quite normal but at the low end of acceptable.  
Quote:I am using the 3.3V pin from the Arduino to power the potmeter (48.8kOhm). I've just now inserted a 100kOhm resistor before the pot, which reduces the center pin to 0-1.1V, and pypilot registers rudder sense perfectly now (and can calibrate as intended), and OpenCPN dashboard updates as intended - I am very happy now Smile
Great!   If you used the 5v pin you would need a slightly higher resistor, that is all.
Quote:I'm considering connecting the RPi and Nano via wires instead of USB, but that will be in the next iteration. USB is fine for now.
My designs all use this for reliability reasons ( and to free up the usb port)
Quote:4) I've changed pwm_style to 0 (h-bridge) and uploaded motor.ino to the nano again. Then I tested the different D-pins using a 1kOhm resistor and a LED. I tested using the center rudder function to obtain either idle, forward or reverse. Below are the pins that made the LED light up:
Idle: D4, 5, 6, 7, 8, 12, 13 (flashing very bright)
Forward: D4, 5, 6, 7, 8, 9, 11 (very bright), 12, 13 (very bright)
Reverse: D4, 5, 6, 7, 8, 9, 11 (very bright), 12, 13 (very bright)

I then repeated the same test with pwm_style = 1 and 2, and got the same results. I don't see any activity on D2 or D3.

I will test more in the coming few days.
check the schematic:
https://pypilot.org/schematics/hbridge_controller.pdf

Generally, D4, D5, D6 are all inputs.  These have weak pullup so could make sense they always light up.   This is true of D7, D8, D12 too.

D11 and D13 are clutch and led outputs and so they are actively driven.   None of the others are since you are in rc pwm mode.

You should tide D6 to ground to get hbridge mode and probably D4 as well (check the comments in motor.ino), otherwise it will use rc pwm mode.   So it makes sense you got the same behavior since the pwm_style set in code is overridden by the pin setting.

It is D2, and D3 that should output steady signal for each direction once this is set and D9/D10 will output pwm.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)