Skip to content

Commit

Permalink
Add support for PWM servo mode and PWM capture mode.
Browse files Browse the repository at this point in the history
For ports S1, S2, S3, if they are in servo mode, it is necessary to write to captureFile 0.

For capture mode, you need to write to captureFile 1.

captureFile is not needed for ports S4, S5, S6.
  • Loading branch information
danielsheh02 committed Dec 9, 2024
1 parent 14a119d commit ab31dab
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 14 deletions.
20 changes: 13 additions & 7 deletions tests/kernel-3.6/test-system-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,21 @@ equal to its class name.
deviceFile="/sys/class/pwm/ecap.2/duty_ns"
periodFile="/sys/class/pwm/ecap.2/period_ns"
runFile="/sys/class/pwm/ecap.2/run"
captureFile="/sys/class/pwm/ecap.2/capture"
/>
<servoMotor
port="S2"
deviceFile="/sys/class/pwm/ecap.1/duty_ns"
periodFile="/sys/class/pwm/ecap.1/period_ns"
runFile="/sys/class/pwm/ecap.1/run"
captureFile="/sys/class/pwm/ecap.1/capture"
/>
<servoMotor
port="S3"
deviceFile="/sys/class/pwm/ecap.0/duty_ns"
periodFile="/sys/class/pwm/ecap.0/period_ns"
runFile="/sys/class/pwm/ecap.0/run"
captureFile="/sys/class/pwm/ecap.0/capture"
/>
<servoMotor
port="S4"
Expand All @@ -113,18 +116,21 @@ equal to its class name.
/>
<pwmCapture
port="S1"
frequencyFile="/sys/class/pwm/ecap_cap.2/freq"
dutyFile="/sys/class/pwm/ecap_cap.2/duty_percentage"
frequencyFile="/sys/class/pwm/ecap.2/period_freq"
dutyFile="/sys/class/pwm/ecap.2/duty_ns"
captureFile="/sys/class/pwm/ecap.2/capture"
/>
<pwmCapture
port="S2"
frequencyFile="/sys/class/pwm/ecap_cap.1/freq"
dutyFile="/sys/class/pwm/ecap_cap.1/duty_percentage"
frequencyFile="/sys/class/pwm/ecap.1/period_freq"
dutyFile="/sys/class/pwm/ecap.1/duty_ns"
captureFile="/sys/class/pwm/ecap.1/capture"
/>
<pwmCapture
port="S3"
frequencyFile="/sys/class/pwm/ecap_cap.0/freq"
dutyFile="/sys/class/pwm/ecap_cap.0/duty_percentage"
port="S3"
frequencyFile="/sys/class/pwm/ecap.0/period_freq"
dutyFile="/sys/class/pwm/ecap.0/duty_ns"
captureFile="/sys/class/pwm/ecap.0/capture"
/>
<powerMotor port="M1" i2cCommandNumber="0x14" invert="true" />
<powerMotor port="M2" i2cCommandNumber="0x15" />
Expand Down
6 changes: 6 additions & 0 deletions tests/kernel-4.14/test-system-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,21 @@ equal to its class name.
deviceFile="/sys/class/pwm/ecap.2/duty_ns"
periodFile="/sys/class/pwm/ecap.2/period_ns"
runFile="/sys/class/pwm/ecap.2/run"
captureFile="/sys/class/pwm/ecap.2/capture"
/>
<servoMotor
port="S2"
deviceFile="/sys/class/pwm/ecap.1/duty_ns"
periodFile="/sys/class/pwm/ecap.1/period_ns"
runFile="/sys/class/pwm/ecap.1/run"
captureFile="/sys/class/pwm/ecap.1/capture"
/>
<servoMotor
port="S3"
deviceFile="/sys/class/pwm/ecap.0/duty_ns"
periodFile="/sys/class/pwm/ecap.0/period_ns"
runFile="/sys/class/pwm/ecap.0/run"
captureFile="/sys/class/pwm/ecap.0/capture"
/>
<servoMotor
port="S4"
Expand All @@ -133,16 +136,19 @@ equal to its class name.
port="S1"
frequencyFile="/sys/class/pwm/ecap_cap.2/freq"
dutyFile="/sys/class/pwm/ecap_cap.2/duty_percentage"
captureFile="/sys/class/pwm/ecap.2/capture"
/>
<pwmCapture
port="S2"
frequencyFile="/sys/class/pwm/ecap_cap.1/freq"
dutyFile="/sys/class/pwm/ecap_cap.1/duty_percentage"
captureFile="/sys/class/pwm/ecap.1/capture"
/>
<pwmCapture
port="S3"
frequencyFile="/sys/class/pwm/ecap_cap.0/freq"
dutyFile="/sys/class/pwm/ecap_cap.0/duty_percentage"
captureFile="/sys/class/pwm/ecap.0/capture"
/>
<powerMotor port="M1" i2cCommandNumber="0x14" invert="true" />
<powerMotor port="M2" i2cCommandNumber="0x15" />
Expand Down
20 changes: 13 additions & 7 deletions trikControl/configs/kernel-3.6/system-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,21 @@ equal to its class name.
deviceFile="/sys/class/pwm/ecap.2/duty_ns"
periodFile="/sys/class/pwm/ecap.2/period_ns"
runFile="/sys/class/pwm/ecap.2/run"
captureFile="/sys/class/pwm/ecap.2/capture"
/>
<servoMotor
port="S2"
deviceFile="/sys/class/pwm/ecap.1/duty_ns"
periodFile="/sys/class/pwm/ecap.1/period_ns"
runFile="/sys/class/pwm/ecap.1/run"
captureFile="/sys/class/pwm/ecap.1/capture"
/>
<servoMotor
port="S3"
deviceFile="/sys/class/pwm/ecap.0/duty_ns"
periodFile="/sys/class/pwm/ecap.0/period_ns"
runFile="/sys/class/pwm/ecap.0/run"
captureFile="/sys/class/pwm/ecap.0/capture"
/>
<servoMotor
port="S4"
Expand All @@ -115,18 +118,21 @@ equal to its class name.
/>
<pwmCapture
port="S1"
frequencyFile="/sys/class/pwm/ecap_cap.2/period_freq"
dutyFile="/sys/class/pwm/ecap_cap.2/duty_ns"
frequencyFile="/sys/class/pwm/ecap.2/period_freq"
dutyFile="/sys/class/pwm/ecap.2/duty_ns"
captureFile="/sys/class/pwm/ecap.2/capture"
/>
<pwmCapture
port="S2"
frequencyFile="/sys/class/pwm/ecap_cap.1/period_freq"
dutyFile="/sys/class/pwm/ecap_cap.1/duty_ns"
frequencyFile="/sys/class/pwm/ecap.1/period_freq"
dutyFile="/sys/class/pwm/ecap.1/duty_ns"
captureFile="/sys/class/pwm/ecap.1/capture"
/>
<pwmCapture
port="S3"
frequencyFile="/sys/class/pwm/ecap_cap.0/period_freq"
dutyFile="/sys/class/pwm/ecap_cap.0/duty_ns"
port="S3"
frequencyFile="/sys/class/pwm/ecap.0/period_freq"
dutyFile="/sys/class/pwm/ecap.0/duty_ns"
captureFile="/sys/class/pwm/ecap.0/capture"
/>
<powerMotor port="M1" i2cCommandNumber="0x14" invert="true" />
<powerMotor port="M2" i2cCommandNumber="0x15" />
Expand Down
6 changes: 6 additions & 0 deletions trikControl/configs/kernel-4.14/system-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,21 @@ equal to its class name.
deviceFile="/sys/class/pwm/pwmchip2/pwm0/duty_cycle"
periodFile="/sys/class/pwm/pwmchip2/pwm0/period"
runFile="/sys/class/pwm/pwmchip2/pwm0/enable"
captureFile="/sys/class/pwm/pwmchip2/pwm0/capture"
/>
<servoMotor
port="S2"
deviceFile="/sys/class/pwm/pwmchip1/pwm0/duty_cycle"
periodFile="/sys/class/pwm/pwmchip1/pwm0/period"
runFile="/sys/class/pwm/pwmchip1/pwm0/enable"
captureFile="/sys/class/pwm/pwmchip1/pwm0/capture"
/>
<servoMotor
port="S3"
deviceFile="/sys/class/pwm/pwmchip0/pwm0/duty_cycle"
periodFile="/sys/class/pwm/pwmchip0/pwm0/period"
runFile="/sys/class/pwm/pwmchip0/pwm0/enable"
captureFile="/sys/class/pwm/pwmchip0/pwm0/capture"
/>
<servoMotor
port="S4"
Expand All @@ -132,16 +135,19 @@ equal to its class name.
port="S1"
frequencyFile="/sys/class/pwm/ecap_cap.2/freq"
dutyFile="/sys/class/pwm/ecap_cap.2/duty_percentage"
captureFile="/sys/class/pwm/ecap_cap.2/capture"
/>
<pwmCapture
port="S2"
frequencyFile="/sys/class/pwm/ecap_cap.1/freq"
dutyFile="/sys/class/pwm/ecap_cap.1/duty_percentage"
captureFile="/sys/class/pwm/ecap_cap.1/capture"
/>
<pwmCapture
port="S3"
frequencyFile="/sys/class/pwm/ecap_cap.0/freq"
dutyFile="/sys/class/pwm/ecap_cap.0/duty_percentage"
captureFile="/sys/class/pwm/ecap_cap.0/capture"
/>
<powerMotor port="M1" i2cCommandNumber="0x14" invert="true" />
<powerMotor port="M2" i2cCommandNumber="0x15" />
Expand Down
8 changes: 8 additions & 0 deletions trikControl/src/pwmCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ PwmCapture::PwmCapture(const QString &port, const trikKernel::Configurer &config
, mDutyFile(hardwareAbstraction.createInputDeviceFile(configurer.attributeByPort(port, "dutyFile")))
, mState("PWM Capture on " + port)
{
QScopedPointer<trikHal::OutputDeviceFileInterface> captureFile
(hardwareAbstraction.createOutputDeviceFile(configurer.attributeByPort(port, "captureFile")));
if (!captureFile->open()) {
mState.fail();
return;
}
captureFile->write(QString::number(1));

if (!mFrequencyFile->open()) {
mState.fail();
}
Expand Down
10 changes: 10 additions & 0 deletions trikControl/src/servoMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ ServoMotor::ServoMotor(const QString &port, const trikKernel::Configurer &config
, mRun(false)
, mState("Servomotor on " + port)
{
if (port == "S1" || port == "S2" || port == "S3") {
QScopedPointer<trikHal::OutputDeviceFileInterface> captureFile
(hardwareAbstraction.createOutputDeviceFile(configurer.attributeByPort(port, "captureFile")));
if (!captureFile->open()) {
mState.fail();
return;
}
captureFile->write(QString::number(0));
}

const auto configure = [this, &port, &configurer](const QString &parameterName) {
return ConfigurerHelper::configureInt(configurer, mState, port, parameterName);
};
Expand Down

0 comments on commit ab31dab

Please sign in to comment.