teleop twist keyboard

 


harisalip@harisalip-HP:~$ rosrun rosserial_python serial_node.py tcp --port=1234 --baud=57600 --tcp-nodelay 192.168.1.9

[INFO] [1681629940.485766]: ROS Serial Python Node

[INFO] [1681629940.493020]: Fork_server is: False

[INFO] [1681629940.494140]: Waiting for socket connections on port 11411

[INFO] [1681629940.495303]: Waiting for socket connection

[INFO] [1681629940.505387]: Established a socket connection from 192.168.1.9 on port 51840

[INFO] [1681629940.507389]: calling startSerialClient

[INFO] [1681629942.613256]: Requesting topics...

[INFO] [1681629942.712969]: Note: subscribe buffer size is 512 bytes

[INFO] [1681629942.714760]: Setup subscriber on /cmd_vel [geometry_msgs/Twist]





harisalip@harisalip-HP:~$ catkin_make --pkg turtlesim Base path: /home/harisalip The specified source space "/home/harisalip/src" does not exist harisalip@harisalip-HP:~$

It looks like you don't have a ROS workspace set up yet. Here are the basic steps to create a new ROS workspace:

  1. Create a new directory for your workspace:
bash
mkdir -p ~/catkin_ws/src
  1. Navigate to the src directory of your workspace:
bash
cd ~/catkin_ws/src
  1. Initialize the workspace:
catkin_init_workspace
  1. Navigate back to the root of your workspace:
bash
cd ~/catkin_ws
  1. Build the workspace:
catkin_make
  1. Source the workspace:
bash
source ~/catkin_ws/devel/setup.bash

Once you have completed these steps, you should be able to build and run ROS packages within your workspace. To build the turtlesim package within your workspace, you can run the command catkin_make --pkg turtlesim from the root of your workspace.

harisalip2016@gmail.com
harisalip@harisalip-HP:~$ mkdir -p ~/catkin_ws/src harisalip@harisalip-HP:~$ cd ~/catkin_ws/src harisalip@harisalip-HP:~/catkin_ws/src$ catkin_init_workspace File "/home/harisalip/catkin_ws/src/CMakeLists.txt" already existsharisalip@harisalip-HP:~/catkin_ws/src$

It looks like you already have a CMakeLists.txt file in your src directory. This is typically created when you initialize a new workspace. You can continue with the remaining steps to build the workspace:

  1. Navigate back to the root of your workspace:
bash
cd ~/catkin_ws
  1. Build the workspace:
catkin_make
  1. Source the workspace:
bash
source ~/catkin_ws/devel/setup.bash

Once you have sourced the workspace, you should be able to build and run ROS packages within it, including the turtlesim package. To build the turtlesim package within your workspace, you can run the command catkin_make --pkg turtlesim from the root of your workspace.

harisalip2016@gmail.com
harisalip@harisalip-HP:~/catkin_ws$ catkin_make Base path: /home/harisalip/catkin_ws Source space: /home/harisalip/catkin_ws/src Build space: /home/harisalip/catkin_ws/build Devel space: /home/harisalip/catkin_ws/devel Install space: /home/harisalip/catkin_ws/install #### #### Running command: "cmake /home/harisalip/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/harisalip/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/harisalip/catkin_ws/install -G Unix Makefiles" in "/home/harisalip/catkin_ws/build" #### -- Using CATKIN_DEVEL_PREFIX: /home/harisalip/catkin_ws/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/noetic -- This workspace overlays: /opt/ros/noetic -- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3") -- Using PYTHON_EXECUTABLE: /usr/bin/python3 -- Using Debian Python package layout -- Using empy: /usr/lib/python3/dist-packages/em.py -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/harisalip/catkin_ws/build/test_results -- Forcing gtest/gmock from source, though one was otherwise available. -- Found gtest sources under '/usr/src/googletest': gtests will be built -- Found gmock sources under '/usr/src/googletest': gmock will be built -- Found PythonInterp: /usr/bin/python3 (found version "3.8.10") -- Using Python nosetests: /usr/bin/nosetests3 -- catkin 0.8.10 -- BUILD_SHARED_LIBS is on -- BUILD_SHARED_LIBS is on -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ traversing 1 packages in topological order: -- ~~ - ros_esp_mr -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- +++ processing catkin package: 'ros_esp_mr' -- ==> add_subdirectory(ros_esp_mr) CMake Error at /opt/ros/noetic/share/catkin/cmake/catkin_workspace.cmake:121 (add_subdirectory): The source directory /home/harisalip/catkin_ws/src/ros_esp_mr does not contain a CMakeLists.txt file. Call Stack (most recent call first): CMakeLists.txt:69 (catkin_workspace) -- Configuring incomplete, errors occurred! See also "/home/harisalip/catkin_ws/build/CMakeFiles/CMakeOutput.log". See also "/home/harisalip/catkin_ws/build/CMakeFiles/CMakeError.log". Invoking "cmake" failed harisalip@harisalip-HP:~/catkin_ws$ source ~/catkin_ws/devel/setup.bash harisalip@harisalip-HP:~/catkin_ws$

It looks like there was an error when you tried to build your workspace using catkin_make. The error message indicates that there is no CMakeLists.txt file in the ros_esp_mr package directory, which is causing the configuration to be incomplete.

To fix this, you should make sure that the ros_esp_mr package directory contains a CMakeLists.txt file. If it does, try running catkin_make again. If it doesn't, you may need to create a CMakeLists.txt file and add it to the package directory.

After successfully building your workspace, you can then source the setup.bash file to add the workspace to your environment variables.

harisalip2016@gmail.com
/* */ 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; void setup(){ Serial.begin(115200); 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(){ move_forward(); delay(1000); move_backward(); delay(1000); move_left(); delay(1000); move_right(); delay(1000); } void move_forward(){ Serial.println("Moving Forward"); digitalWrite(L_FORW, 1); digitalWrite(R_FORW, 1); ledcWrite(channel_R, 200); ledcWrite(channel_L, 200); } void move_left(){ Serial.println("Moving left"); digitalWrite(L_FORW, 0); digitalWrite(R_FORW, 1); ledcWrite(channel_R, 200); ledcWrite(channel_L, 0); } void move_right(){ Serial.println("Moving Right"); digitalWrite(L_FORW, 1); digitalWrite(R_FORW, 0); ledcWrite(channel_R, 0); ledcWrite(channel_L, 200); } void move_backward(){ Serial.println("Moving Backwards"); digitalWrite(L_FORW, 0); digitalWrite(R_FORW, 0); ledcWrite(channel_R, 200); ledcWrite(channel_L, 200); } void stop() { ledcWrite(channel_R, 0); ledcWrite(channel_L, 0); }

This is a basic Arduino code that controls the movement of a robot with two DC motors. It defines the pin connections of the motors and the PWM signals, and then defines functions to move the robot in different directions by setting the appropriate pins and PWM signals. The loop() function repeatedly calls the movement functions with a delay of one second between each movement. The stop() function is used to stop the robot by setting the PWM signals to 0.

Some important points to note:

  • This code uses the ledc library to generate PWM signals with a frequency of 5 kHz and a resolution of 8 bits.
  • The motor speed is controlled by setting the duty cycle of the PWM signal using the ledcWrite() function.
  • The direction of each motor is controlled by setting the L_FORW, L_BACK, R_FORW, and R_BACK pins. A value of 1 for a pin corresponds to the motor moving in the forward direction, and a value of 0 corresponds to the motor moving in the backward direction.
  • The move_left() and move_right() functions control the turning of the robot by making one motor move forward and the other move backward. The speed of each motor can be adjusted independently by setting the duty cycle of the corresponding PWM signal.












Post a Comment

Previous Post Next Post