Skip to content

Commit

Permalink
Fix I2C device numbers (#31)
Browse files Browse the repository at this point in the history
* Fix I2C device numbers

* ci fix

* clean

* fix
  • Loading branch information
lukicdarkoo authored Nov 23, 2023
1 parent 93b4651 commit 91ff8a1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions epuck_ros2_camera/src/pipuck_ov7670.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <sys/types.h>
#include <unistd.h>

#define I2C_CHANNEL 4
#define I2C_CHANNEL 12
#define OV7670_ADDR 0x21

/*######################
Expand Down Expand Up @@ -96,7 +96,7 @@ int read_i2c(uint8_t reg, uint8_t *val) {
}

int pipuck_ov7670_init(void) {
sprintf(filename, "/dev/i2c-%d", 4);
sprintf(filename, "/dev/i2c-%d", I2C_CHANNEL);
if ((file = open(filename, O_RDWR)) < 0) {
/* ERROR HANDLING: you can check errno to see what went wrong */
perror("Failed to open the i2c bus");
Expand Down
2 changes: 1 addition & 1 deletion epuck_ros2_driver/scripts/read_i2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _get_params(buffer):

while True:
data = []
with open('/tmp/dev/i2c-4_write', 'rb') as f:
with open('/tmp/dev/i2c-12_write', 'rb') as f:
data = list(f.read())

if len(data) > 0 and prev_data != data:
Expand Down
6 changes: 3 additions & 3 deletions epuck_ros2_driver/src/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ class EPuckDriver : public rclcpp::Node {

// Create I2C object
if (type == "test")
mI2cMain = std::make_shared<I2CWrapperTest>("/dev/i2c-4");
mI2cMain = std::make_shared<I2CWrapperTest>("/dev/i2c-12");
else
mI2cMain = std::make_shared<I2CWrapperHW>("/dev/i2c-4");
mI2cMain = std::make_shared<I2CWrapperHW>("/dev/i2c-12");
mImu = std::make_shared<MPU9250>(mI2cMain);
mImu->calibrate();
mTofInitStatus = tofInit(4, 0x29, 1);
mTofInitStatus = tofInit(12, 0x29, 1);
if (!mTofInitStatus)
RCLCPP_WARN(get_logger(), "ToF device is not accessible!");

Expand Down
10 changes: 5 additions & 5 deletions epuck_ros2_driver/test/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def int162arr(val):
return arr


def read_params_from_i2c(idx=4, address=0x1F):
def read_params_from_i2c(idx=12, address=0x1F):
params = {}
for _ in range(READ_WRITE_RETRY_COUNT):
with open(f'/tmp/dev/i2c-{idx}_write_' + str(address), 'r+b') as f:
Expand All @@ -74,7 +74,7 @@ def read_params_from_i2c(idx=4, address=0x1F):
return params, []


def write_params_to_i2c(params, idx=4, address=0x1F):
def write_params_to_i2c(params, idx=12, address=0x1F):
buffer = [0] * SENSORS_SIZE

# Fill the buffer
Expand Down Expand Up @@ -170,7 +170,7 @@ def generate_test_description():
# Inital IMU data
if not os.path.exists('/tmp/dev'):
os.makedirs('/tmp/dev')
with open(f'/tmp/dev/i2c-4_read_' + str(0x68), 'w+b') as f:
with open(f'/tmp/dev/i2c-12_read_' + str(0x68), 'w+b') as f:
f.write(bytearray([0] * 6))

controller = launch_ros.actions.Node(
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_odometry_backward(self, launch_service, proc_output):
self.assertTrue(condition, 'Should move backward')

def test_imu(self, launch_service, proc_output):
with open(f'/tmp/dev/i2c-4_read_' + str(0x68), 'w+b') as f:
with open(f'/tmp/dev/i2c-12_read_' + str(0x68), 'w+b') as f:
f.write(bytearray([0]*6))
time.sleep(MESSAGE_SEND_DELAY)
condition = check_topic_condition(
Expand All @@ -353,7 +353,7 @@ def test_imu(self, launch_service, proc_output):
)
self.assertTrue(condition, 'IMU should publish zeros')

with open(f'/tmp/dev/i2c-4_read_' + str(0x68), 'w+b') as f:
with open(f'/tmp/dev/i2c-12_read_' + str(0x68), 'w+b') as f:
f.write(bytearray([127, 0] * 3))
time.sleep(MESSAGE_SEND_DELAY)
condition = check_topic_condition(
Expand Down

0 comments on commit 91ff8a1

Please sign in to comment.