Hi thanks for the fast reply
I’m using:
apt-cache show nvidia-jetpack
Package: nvidia-jetpack
Version: 4.6-b199
Description: Ubuntu 20.04.6 LTS
uname -a
Linux nano 4.9.253-tegra #1 SMP PREEMPT Mon Jul 26 12:13:06 PDT 2021 aarch64 aarch64 aarch64 GNU/Linux
I tried to compile the code with:
PCA9685
add_library(libpca9685 STATIC ${LIBRARY_DIRS}/pca9685.cpp )
target_link_libraries(libpca9685 ${WIRINGJET_LIBRARIES} -lpthread -lwiringjet)
as recommended on github, but this shows:
/usr/bin/ld: -lwiringjet kann nicht gefunden werden
collect2: error: ld returned 1 exit status
/usr/bin/ld: -lwiringjet kann nicht gefunden werden
collect2: error: ld returned 1 exit status
make[2]: *** [hexapod_controller/CMakeFiles/test_joint_controller.dir/build.make:135: /home/jetson/hexapod_ros_ang/devel/lib/libtest_joint_controller.so] Fehler 1
make[1]: *** [CMakeFiles/Makefile2:4776: hexapod_controller/CMakeFiles/test_joint_controller.dir/all] Fehler 2
make[1]: *** Auf noch nicht beendete Prozesse wird gewartet …
make[2]: *** [hexapod_controller/CMakeFiles/joint_controller.dir/build.make:135: /home/jetson/hexapod_ros_ang/devel/lib/libjoint_controller.so] Fehler 1
make[1]: *** [CMakeFiles/Makefile2:4839: hexapod_controller/CMakeFiles/joint_controller.dir/all] Fehler 2
make: *** [Makefile:141: all] Fehler 2
without -lwiringjet the code compiles without errors but when I launch the the controller it dies with:
process[joint_controller-7]: started with pid [36968]
Oops: Unable to determine board revision from /proc/cpuinfo
→ No “Hardware” line
→ You’d best google the error to find out why.
[joint_controller-7] process has died [pid 36968, exit code 1, cmd /home/jetson/hexapod_ros_alt/devel/lib/hexapod_driver/joint_controller /joint_controller/joints_command:=/joints_command __name:=joint_controller __log:=/home/jetson/.ros/log/ed97aa48-2d79-11ee-84f7-17f602ff5f49/joint_controller-7.log].
log file: /home/jetson/.ros/log/ed97aa48-2d79-11ee-84f7-17f602ff5f49/joint_controller-7*.log
cat /proc/cpuinfo
processor : 0
model name : ARMv8 Processor rev 1 (v8l)
BogoMIPS : 38.40
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x1
CPU part : 0xd07
CPU revision : 1
…
Hope this helps, thx.
ps.: I saw this error when compiling wiringpi on the wrong platform, but I changed the pca9685.cpp to wiringjet…
include <unistd.h>
include
include <wiringJetI2C.h>
include <wiringJet.h>
include “pca9685.h”
include “pca9685_constants.h”
PCA9685::PCA9685(int i2c_bus, int device_address) :
i2c_bus_(i2c_bus), device_address_(device_address) {}
PCA9685::PCA9685(int device_address): PCA9685(1, device_address) {}
PCA9685::~PCA9685() {
device_sleep();
}
int PCA9685::connect() {
file_descriptor_ = wiringJetI2CSetup(i2c_bus_,device_address_);
// file_descriptor_ = wiringJetI2CSetup(device_address_);
// TODO: Can still return a positive fd if device is not connected
if (file_descriptor_ < 0) {
return -1;
}
set_all_pwm(0, 0);
// Set mode2
wiringJetI2CWriteReg8(file_descriptor_, MODE2, OUTDRV);
// Set mode1
wiringJetI2CWriteReg8(file_descriptor_, MODE1, ALLCALL);
// Wait for oscillator. Takes 500 microseconds
usleep(500);
// Wake the device
device_wake();
return 1;
}
void PCA9685::set_pwm_freq(float frequency_hz) {
frequency_hz_ = frequency_hz;
const float oscillator_clock_freq_hz = 25000000.0f;
// Refer to the PCA9685 documentation for details on the prescale value.
int prescale_val = static_cast<int>(std::round(oscillator_clock_freq_hz / (PWM_RESOLUTION * frequency_hz)) - 1.0f);
// Enter low power mode so we can set the prescale.
device_sleep();
wiringJetI2CWriteReg8(file_descriptor_, PRESCALE, prescale_val);
// Wake the device.
device_wake();
int current_mode = wiringJetI2CReadReg8(file_descriptor_, MODE1);
wiringJetI2CWriteReg8(file_descriptor_, MODE1, current_mode | RESTART);
}
void PCA9685::set_pwm(int channel, uint16_t on, uint16_t off) {
wiringJetI2CWriteReg8(file_descriptor_, LED0_ON_L + 4 * channel, on & 0xFF);
wiringJetI2CWriteReg8(file_descriptor_, LED0_ON_H + 4 * channel, on >> 8);
wiringJetI2CWriteReg8(file_descriptor_, LED0_OFF_L + 4 * channel, off & 0xFF);
wiringJetI2CWriteReg8(file_descriptor_, LED0_OFF_H + 4 * channel, off >> 8);
}
void PCA9685::set_pwm_ms(int channel, float ms) {
float period_ms = 1000.0f / frequency_hz_;
int bits_per_ms = static_cast(PWM_RESOLUTION / period_ms);
int bits = static_cast(ms * static_cast(bits_per_ms));
set_pwm(channel, 0, bits);
}
void PCA9685::set_all_pwm(uint16_t on, uint16_t off) {
wiringJetI2CWriteReg8(file_descriptor_, ALL_LED_ON_L, on & 0xFF);
wiringJetI2CWriteReg8(file_descriptor_, ALL_LED_ON_H, on >> 8);
wiringJetI2CWriteReg8(file_descriptor_, ALL_LED_OFF_L, off & 0xFF);
wiringJetI2CWriteReg8(file_descriptor_, ALL_LED_OFF_H, off >> 8);
}
void PCA9685::device_sleep() {
// Setting the bit at position 4 (SLEEP) to 1 will put it in lower power mode (sleep mode).
int current_mode = wiringJetI2CReadReg8(file_descriptor_, MODE1);
int new_mode = (current_mode & 0x7F) | SLEEP;
// Update mode
wiringJetI2CWriteReg8(file_descriptor_, MODE1, new_mode);
}
void PCA9685::device_wake() {
// Setting the bit at position 4 (SLEEP) to 0 will put it in normal mode (wake mode).
int current_mode = wiringJetI2CReadReg8(file_descriptor_, MODE1);
int new_mode = (current_mode & 0x7F) & ~SLEEP;
// Update mode
wiringJetI2CWriteReg8(file_descriptor_, MODE1, new_mode);
// Wait for oscillator.
usleep(500);
}