Queries about a real mobile robot

Good evening to all!

First of all, I would like to apologize if I am not in the right place.

I have some questions about implementing a mobile robot.

I have an old construction mobile robot, wherein this robot the main controller has been removed, and I put in its place a Raspberry pi 4. The robot does not have encoders to implement odometry. The robot has five infrared distance sensors, and I want to control them with raspberry, I found a guide on the internet where it has a python code.

The first question is, how will I be able to attach this code to ROS?

I also have an accelerometer, which I want the code to enter in ROS. But I have no idea how this will happen.

I have also managed to give commands to the wheels through motor drives.

At the moment, these are my questions.

Thanks in advance!

Hi, if you already have code to read from the distance sensors and accelerometer then you are a lot of the way forward, especially if you have motor control too.

There are courses such as ROS in 5 days which take you through how to create publishers, subscribers, services etc - I think that would be a place to go next.

1 Like

The first question is, how will I be able to attach this code to ROS?

Hello @vasileios.tzimas, as @brianlmerrittcons pointed out, if you have code (python or C++) that reads out the values of your infrared sensors, then you would need to create a ROS publisher that reads out those sensor values and publishes them over the ROS network. This setup could suffice to implement a robot which is able to take action to avoid obstacles. I you can control your robots motors then you could also teleoperate your robot over ROS.



1 Like

Hello @brianlmerrittcons, @rzegers again!!

Initially, I have seen many of the courses, such as the one for a mobile robot and the one for python.
From the course for mobile robots, I managed and made this code below:

#! /usr/bin/env python3

import rospy
from geometry_msgs.msg import Twist
from std_msgs.msg import Float64

pub = rospy.Publisher('/twist_vels', Twist, queue_size=1)
vels = Twist()
vels.linear.x = 0.1
vels.angular.z = 0.3

class ConvertVels():
    def __init__(self):
        self.sub = rospy.Subscriber('/twist_vels', Twist, self.callback)
        self.rwheel_pub = rospy.Publisher('/rwheel_controller/command', Float64, queue_size=1)
        self.lwheel_pub = rospy.Publisher('/lwheel_controller/command', Float64, queue_size=1)
        self.twist_vels = Twist()
        self.vr = Float64()
        self.vl = Float64()
        rate = rospy.Rate(1)

    def callback(self, msg):
        self.twist_vels = msg

    def pub_wheel_vels(self):
        while not rospy.is_shutdown():

    def convert_velocities(self):
        L = 0.3
        R = 0.1
        self.vr = ((2*self.twist_vels.linear.x) + (self.twist_vels.angular.z*L))/(2*R)
        self.vl = ((2*self.twist_vels.linear.x) - (self.twist_vels.angular.z*L))/(2*R)

if __name__ == '__main__':
    rospy.init_node('calculate_vels_node', anonymous=True)
    cv = ConvertVels()
    rate = rospy.Rate(1)

I found this file here from a site.

sudo pigpiod

pigs s x 1000

pigs s x 1500

pigs s x 2000

where x is the Broadcom number of the GPIO.

But I do not understand how to convert the values from 1000 to 2000 to pass them in ROS.
Typically 1000 µs is fast counterclockwise, 1500 µs is stop, and 2000 µs is fast clockwise.

Any idea about my querry?

Hello @vasileios.tzimas,

I seems to me that you are trying to translate one range values to another using Python.

If that is the case have a look at this function:

def translate(value, leftMin, leftMax, rightMin, rightMax):
    # Figure out how 'wide' each range is
    leftSpan = leftMax - leftMin
    rightSpan = rightMax - rightMin

    # Convert the left range into a 0-1 range (float)
    valueScaled = float(value - leftMin) / float(leftSpan)

    # Convert the 0-1 range into a value in the right range.
    return rightMin + (valueScaled * rightSpan)

Disclaimer: This is not my code, I was taken from here:
python - Mapping a range of values to another - Stack Overflow

I hope this is what you were looking for.




Please, it would be great if you could open a new thread for each new question you have. Please do no post new questions as a reply lo a different question. The reason is that other stundents won’t be able to find a solution to a similar question if a question is “hidden” as a reply to a different question. You will also increase your chances to get a reply to your question if you post each question as a separate new question instead of a reply to a previous question.