Step -1
harisalip@harisalip-HP:~$ roscore
... logging to /home/harisalip/.ros/log/be00d204-dc44-11ed-a874-99f9ddbc8ec3/roslaunch-harisalip-HP-5448.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://harisalip-HP:33177/
ros_comm version 1.16.0
SUMMARY
========
PARAMETERS
* /rosdistro: noetic
* /rosversion: 1.16.0
NODES
auto-starting new master
process[master]: started with pid [5456]
ROS_MASTER_URI=http://harisalip-HP:11311/
setting /run_id to be00d204-dc44-11ed-a874-99f9ddbc8ec3
process[rosout-1]: started with pid [5466]
started core service [/rosout]
Step -2
harisalip@harisalip-HP:~$ rosrun rosserial_python serial_node.py tcp
[INFO] [1681642348.674940]: ROS Serial Python Node
[INFO] [1681642348.680783]: Fork_server is: False
[INFO] [1681642348.681962]: Waiting for socket connections on port 11411
[INFO] [1681642348.683115]: Waiting for socket connection
[INFO] [1681642348.686834]: Established a socket connection from 192.168.1.9 on port 57987
[INFO] [1681642348.688209]: calling startSerialClient
[INFO] [1681642350.791911]: Requesting topics...
[INFO] [1681642350.844518]: Note: subscribe buffer size is 512 bytes
[INFO] [1681642350.845852]: Setup subscriber on /cmd_vel [geometry_msgs/Twist]
Step -3
harisalip@harisalip-HP:~$ rostopic list
/cmd_vel
/diagnostics
/rosout
/rosout_agg
harisalip@harisalip-HP:~$ rosrun teleop_twist_keyboard teleop_twist_keyboard.py
Reading from the keyboard and Publishing to Twist!
---------------------------
Moving around:
u i o
j k l
m , .
For Holonomic mode (strafing), hold down the shift key:
---------------------------
U I O
J K L
M < >
t : up (+z)
b : down (-z)
anything else : stop
q/z : increase/decrease max speeds by 10%
w/x : increase/decrease only linear speed by 10%
e/c : increase/decrease only angular speed by 10%
CTRL-C to quit
currently: speed 0.5 turn 1.0
Step -4
OPEN SERIAL MONITOR ARDUINO IDE
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5856
entry 0x400806a8
.....SSID: Official Net
IP: 192.168.1.9
Get Ready
0.00 / 0.00
-0.25 / 0.75
0.25 / 0.25
0.75 / -0.25
-0.50 / 0.50
0.00 / 0.00
0.50 / -0.50
0.25 / -0.75
-0.25 / -0.25
-0.75 / 0.25
-0.25 / -0.25
-0.25 / -0.25
ARDUINO IDE CODE - SAMPLES
/*
*/
#define ROSSERIAL_ARDUINO_TCP
#include "WiFi.h"
#include <ros.h>
#include <geometry_msgs/Twist.h>
const uint8_t R_PWM = 12;
const uint8_t R_BACK = 14;
const uint8_t R_FORW = 27;
const uint8_t L_PWM = 33;
const uint8_t L_BACK = 25;
const uint8_t L_FORW = 26;
const uint8_t channel_L =0;
const uint8_t channel_R= 1;
float left_wheel;
float right_wheel;
// IPAddress server(192, 168, 100, 7);
IPAddress server(192, 169, 100, 4);
uint16_t serverPort = 11411;
const char* ssid = "Official Net";
const char* password = "12334462945";
void cmdVel_to_pwm_cb( const geometry_msgs::Twist& velocity_msg);
ros::NodeHandle nh;
ros::Subscriber<geometry_msgs::Twist> sub("/cmd_vel", &cmdVel_to_pwm_cb );
void setup(){
Serial.begin(115200);
setupWiFi();
nh.getHardware()->setConnection(server, serverPort);
nh.initNode();
nh.subscribe(sub);
pin_def();
stop();
Serial.println("Get Ready");
delay(2000);
}
void pin_def(){
const int freq = 5000;
const int res = 8;
pinMode(L_PWM, OUTPUT);
pinMode(L_FORW, OUTPUT);
pinMode(L_BACK, OUTPUT);
pinMode(R_PWM, OUTPUT);
pinMode(R_FORW, OUTPUT);
pinMode(R_BACK, OUTPUT);
ledcSetup(channel_R ,freq , res);
ledcSetup(channel_L ,freq , res);
ledcAttachPin(R_PWM,channel_R);
ledcAttachPin(L_PWM,channel_L);
}
void loop(){
nh.spinOnce();
}
void setupWiFi()
{
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { delay(500);Serial.print("."); }
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
Serial.print("IP: ");
Serial.println(WiFi.localIP());
}
void cmdVel_to_pwm_cb( const geometry_msgs::Twist& velocity_msg){
right_wheel = (velocity_msg.linear.x + velocity_msg.angular.z ) / 2 ;
left_wheel = (velocity_msg.linear.x - velocity_msg.angular.z ) /2 ;
direction();
speed();
if ( velocity_msg.linear.x ==0.0 & velocity_msg.angular.z ==0.0){
stop();
}
Serial.print(left_wheel);Serial.print(" / ");Serial.println(right_wheel);
}
void direction(){
digitalWrite(L_FORW, left_wheel >0 );
digitalWrite(L_BACK,left_wheel < 0);
digitalWrite(R_FORW,right_wheel > 0 );
digitalWrite(R_BACK,right_wheel < 0);
}
void speed (){
ledcWrite(channel_R, 200);
ledcWrite(channel_L, 200);
}
void stop()
{
ledcWrite(channel_R, 0);
ledcWrite(channel_L, 0);
}
