Skip to content

Commit

Permalink
Merge pull request #84 from hippo5329/pr-esp32-fix-up
Browse files Browse the repository at this point in the history
Pr esp32 fix up
  • Loading branch information
grassjelly committed Apr 20, 2024
2 parents 8a95745 + b4b73d3 commit d663bb0
Show file tree
Hide file tree
Showing 12 changed files with 929 additions and 32 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,27 @@ Constants' Meaning:

- **MOTORX_PWM** - Microcontroller pin that is connected to the PWM pin of the motor driver. This pin is usually labelled as EN or ENABLE pin on the motor driver board.


- **MOTORX_IN_A** - Microcontroller pin that is connected to one of the motor driver's direction pins. This pin is usually labelled as DIRA or DIR1 pin on the motor driver board. On BTS7960 driver, this is one of the two PWM pins connected to the driver (RPWM/LPWM).

- **MOTORX_IN_B** - Microcontroller pin that is connected to one of the motor driver's direction pins. This pin is usually labelled as DIRB or DIR2 pin on the motor driver board. On BTS7960 driver, this is one of the two PWM pins connected to the driver (RPWM/LPWM).

- **MOTORX_INV** - Flag used to invert the direction of the motor. More on that later.

*WIFI related settings*

- **AGENT_IP** - micro-ROS agent IP. eg. host IP, { 192, 168, 1, 100 }

- **AGENT_PORT** - micro-ROS agent port. default 8888

- **WIFI_SSID**

- **WIFI_PASSWORD**

The mirco-ROS wifi transport is selected with a setting in firmare/platformio.ini.

board_microros_transport = wifi

## Calibration
Before proceeding, **ensure that your robot is elevated and the wheels aren't touching the ground**.
5.1
Expand Down Expand Up @@ -356,10 +371,14 @@ Run:

This will allow the robot to receive Twist messages to control the robot, and publish odometry and IMU data straight from the microcontroller. Compared to Linorobot's ROS1 version, the odometry and IMU data published from the microcontroller use standard ROS2 messages and do not require any relay nodes to reconstruct the data to complete [sensor_msgs/Imu](http://docs.ros.org/en/noetic/api/sensor_msgs/html/msg/Imu.html) and [nav_msgs/Odometry](http://docs.ros.org/en/noetic/api/nav_msgs/html/msg/Odometry.html) messages.

Run the agent:
Run the serial transprot agent: (the serial device used for esp32 is /dev/ttyUSB0)

ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyACM0

Or run the wifi transport agent:

ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888

### 2. Drive around

Run teleop_twist_keyboard package and follow the instructions on the terminal on how to drive the robot:
Expand Down
12 changes: 12 additions & 0 deletions config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
#include "custom/esp32_config.h"
#endif

#ifdef USE_ESP32S2_CONFIG
#include "custom/esp32s2_config.h"
#endif

#ifdef USE_ESP32S3_CONFIG
#include "custom/esp32s3_config.h"
#endif

#ifdef USE_PICO_CONFIG
#include "custom/pico_config.h"
#endif

// this should be the last one
#ifndef LINO_BASE
#include "lino_base_config.h"
Expand Down
42 changes: 24 additions & 18 deletions config/custom/esp32_config.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2021 Juan Miguel Jimeno
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.esp32
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
Expand All @@ -15,7 +15,7 @@
#ifndef ESP32_CONFIG_H
#define ESP32_CONFIG_H

#define LED_PIN 2 //used for debugging status
#define LED_PIN LED_BUILTIN //used for debugging status

//uncomment the base you're building
#define LINO_BASE DIFFERENTIAL_DRIVE // 2WD and Tracked robot w/ 2 motors
Expand Down Expand Up @@ -59,10 +59,10 @@ ROBOT ORIENTATION
#define MOTOR_OPERATING_VOLTAGE 12 // motor's operating voltage (used to calculate max RPM)
#define MOTOR_POWER_MAX_VOLTAGE 12 // max voltage of the motor's power source (used to calculate max RPM)
#define MOTOR_POWER_MEASURED_VOLTAGE 12 // current voltage reading of the power connected to the motor (used for calibration)
#define COUNTS_PER_REV1 550 // wheel1 encoder's no of ticks per rev
#define COUNTS_PER_REV2 550 // wheel2 encoder's no of ticks per rev
#define COUNTS_PER_REV3 550 // wheel3 encoder's no of ticks per rev
#define COUNTS_PER_REV4 550 // wheel4 encoder's no of ticks per rev
#define COUNTS_PER_REV1 450 // wheel1 encoder's no of ticks per rev
#define COUNTS_PER_REV2 450 // wheel2 encoder's no of ticks per rev
#define COUNTS_PER_REV3 450 // wheel3 encoder's no of ticks per rev
#define COUNTS_PER_REV4 450 // wheel4 encoder's no of ticks per rev
#define WHEEL_DIAMETER 0.0560 // wheel's diameter in meters
#define LR_WHEELS_DISTANCE 0.224 // distance between left and right wheels
#define PWM_BITS 10 // PWM Resolution of the microcontroller
Expand Down Expand Up @@ -95,7 +95,7 @@ ROBOT ORIENTATION

// MOTOR PINS
#ifdef USE_GENERIC_2_IN_MOTOR_DRIVER
#define MOTOR1_PWM 21 //Pin no 21 is not a PWM pin on Teensy 4.x, you can swap it with pin no 1 instead.
#define MOTOR1_PWM 21
#define MOTOR1_IN_A 20
#define MOTOR1_IN_B 1

Expand All @@ -116,7 +116,7 @@ ROBOT ORIENTATION
#endif

#ifdef USE_GENERIC_1_IN_MOTOR_DRIVER
#define MOTOR1_PWM 21 //Pin no 21 is not a PWM pin on Teensy 4.x, you can use pin no 1 instead.
#define MOTOR1_PWM 21
#define MOTOR1_IN_A 20
#define MOTOR1_IN_B -1 //DON'T TOUCH THIS! This is just a placeholder

Expand All @@ -138,8 +138,8 @@ ROBOT ORIENTATION

#ifdef USE_BTS7960_MOTOR_DRIVER
#define MOTOR1_PWM -1 //DON'T TOUCH THIS! This is just a placeholder
#define MOTOR1_IN_A 19 // Pin no 21 is not a PWM pin on Teensy 4.x, you can use pin no 1 instead.
#define MOTOR1_IN_B 18 // Pin no 20 is not a PWM pin on Teensy 4.x, you can use pin no 0 instead.
#define MOTOR1_IN_A 19
#define MOTOR1_IN_B 18

#define MOTOR2_PWM -1 //DON'T TOUCH THIS! This is just a placeholder
#define MOTOR2_IN_A 16
Expand All @@ -158,7 +158,7 @@ ROBOT ORIENTATION
#endif

#ifdef USE_ESC_MOTOR_DRIVER
#define MOTOR1_PWM 21 //Pin no 21 is not a PWM pin on Teensy 4.x. You can use pin no 1 instead.
#define MOTOR1_PWM 21
#define MOTOR1_IN_A -1 //DON'T TOUCH THIS! This is just a placeholder
#define MOTOR1_IN_B -1 //DON'T TOUCH THIS! This is just a placeholder

Expand All @@ -178,9 +178,10 @@ ROBOT ORIENTATION
#define PWM_MIN -PWM_MAX
#endif

// #define USE_WIFI_TRANSPORT // use micro ros wifi transport
#define AGENT_IP { 192, 168, 1, 100 } // eg IP of the desktop computer
#define AGENT_PORT 8888
#define WIFI_SSID "WIFI_SSID"
#define WIFI_PASSWORD "WIFI_PASSWORD"
// Enable WiFi with null terminated list of multiple APs SSID and password
// #define WIFI_AP_LIST {{"WIFI_SSID", "WIFI_PASSWORD"}, {NULL}}
#define WIFI_MONITOR 2 // min. period to send wifi signal strength to syslog
Expand All @@ -197,9 +198,9 @@ ROBOT ORIENTATION
#define LIDAR_BAUDRATE 230400
#define LIDAR_SERVER { 192, 168, 1, 100 } // eg IP of the desktop computer
#define LIDAR_PORT 8889
#define BAUDRATE 115200
// #define SDA_PIN 21 // specify I2C pins
// #define SCL_PIN 22
#define BAUDRATE 921600
#define SDA_PIN 21 // specify I2C pins
#define SCL_PIN 22
#define NODE_NAME "esp32"
// #define TOPIC_PREFIX "esp32/"

Expand All @@ -218,16 +219,21 @@ const int16_t ADC_LUT[4096] = { /* insert adc_calibrate data here */ };
// #define ECHO_PIN 32
#define USE_SHORT_BRAKE // for shorter stopping distance
// #define WDT_TIMEOUT 60 // Sec
// #define BOARD_INIT sleep(5) // wait to begin IMU calibration
#define BOARD_INIT { \
Wire.begin(SDA_PIN, SCL_PIN); \
Wire.setClock(400000); \
}
// #define BOARD_INIT_LATE {}
// #define BOARD_LOOP {}

#ifdef USE_SYSLOG
#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){ \
syslog(LOG_ERR, "%s RCCHECK failed %d", __FUNCTION__, temp_rc); \
return false; }}
}}
#else
#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){ \
flashLED(3); \
return false; }} // do not block
}} // do not block
#endif

#endif
Loading

0 comments on commit d663bb0

Please sign in to comment.