ROS on Raspberry PI...
 
Notifications
Clear all

ROS on Raspberry PI 3B+ progress report.

97 Posts
10 Users
4 Likes
46.5 K Views
Spyder
(@spyder)
Member
Joined: 5 years ago
Posts: 846
 

This worked

sudo apt-get install ros-kinetic-rosserial

This, however...

sudo apt-get install ros-kinetic-rosserial-arduino

initially gave me a complaint about asking for an impossible situation (isn't that what computers are for ?)

So I did 'update', then 'update --fix-missing', then ran it again, and it installed... stuff

then I did...

git clone  https://github.com/ros-drivers/rosserial.git 

And it copied the rosserial folder into the "bot" (this is all very positive so far)

So I now have rosserial for arduino in the bot, and rosserial examples in the arduino IDE. One of the examples references pubsub (which I assume is publisher subscriber). There are publisher options with tcp/ip, but the subscriber option just says subscriber. So, how does the arduino recieve msgs that it has subscribed to ?

I thought what I wanted was for the Pi to be the subscriber, then tell the arduino what to do

I thought, for a moment there, that I was making headway

 


   
ReplyQuote
Spyder
(@spyder)
Member
Joined: 5 years ago
Posts: 846
 

http://wiki.ros.org/joy/Tutorials/WritingTeleopNode

I don't know that I'm interpreting this correctly, but, I think what's happening here is that the Pi is connected to the joystick, and is then translating the joystick commands, and then publishing them, at which point the arduino is subscribing, and "twist" is somehow translating what the arduino is receiving

http://wiki.ros.org/simple_drive

It's not clear to me, however, by what means the data from the Pi is getting to the arduino... I'm guessing USB, but, now we've got the Pi powering the arduino, and the arduino powering the motor controller and the camera

This would seem to be the point at which Bill was concerned about items being powered twice

Now, if you look here...

https://store.arduino.cc/usa/arduino-uno-rev3

under power, it says that the arduino will choose the higher of the voltage inputs, and 7 is the recommended minimum. This says to me that we can use the USB for data from the Pi to the arduino, and simultaneously use the barrel jack on the arduino for power to that. 

This still means that the bot-pi is still acting as a publisher, and we want it as a subscriber. Maybe it can do both... IE: Subscribe to a topic that the master-pi is publishing, then publish that topic to the arduino

More tomorrow...


   
ReplyQuote
Spyder
(@spyder)
Member
Joined: 5 years ago
Posts: 846
 

So, it looks like "twist" tells the bot to move, as explained in this extremely detailed web page...

http://docs.ros.org/melodic/api/geometry_msgs/html/msg/Twist.html

And "spin" means to start the "loop", and spinonce means to just start

https://www.quora.com/What-is-spinOnce-used-for-in-ROS

It doesn't make a whole lot of sense tho. "twist" is saying speed and direction, angular and linear velocity, but not which pin to spit out the motor information to. There's got to be some sort of translator someplace that I'm missing


   
ReplyQuote
Spyder
(@spyder)
Member
Joined: 5 years ago
Posts: 846
 

DOH !

This video answered a question I had, sorta, but, the repository (as always) is missing. I ALMOST had a working demo that I could look at

I didn't have the parts for the first demo, but, the parts in the second demo looked familiar, so I check my shelves, and sure enough, I had the exact parts I needed for the second demo, so I grabbed the parts, connected them,

foiledagainsml

and then when I went to download the files...

The whole github was completely blank

This just isn't fair

On the other hand. What I did learn from the video...

The publisher doesn't care what hardware you have. All the publisher does is tell the subscriber to "do"

The subscriber is where the translation to the hardware needs to happen. But, this is as I suspected. At least it verified it for me tho

Would've been nice to have a functional demo...

RATS


   
ReplyQuote
soumitra
(@soumitra)
Member
Joined: 5 years ago
Posts: 61
 

@spyder

Hi spyder

If you want to simply connect with and arduino and want to see how publusher subcruber works

You can sumply connect an arduino using rosserial and upload hello world example for arduino to publish

 

Now on your ROS System you do rostopic list

You will see the list of topuc that is available, in this case it will show msg topic

Then do the rostopic echo / topic name you see 

You will see the ropic echo ie " hellow world" publushed in your screen

 

This topic list is sent by serial communication from the arduino.

This is one example

 

Next if you want a hardware control  abd feel how the ros controls the node you see below example you can cobtrol motor from your laptop or rpi3 by ssh

See below example

https://github.com/mktk1117/six_wheel_robot/wiki/Make-a-ROS-package-to-communicate-with-Arduino-to-control-motors


   
ReplyQuote
Spyder
(@spyder)
Member
Joined: 5 years ago
Posts: 846
 

@sdey76

Thank you !

I will... try that, or, at least some version of that


   
ReplyQuote
Spyder
(@spyder)
Member
Joined: 5 years ago
Posts: 846
 

Okay, so, the ino looks like this...

 

#include <string.h>

// pin settings
int pwmPin0 = 3;
int pwmPin1 = 5;
int pwmPin2 = 6; <---
int pwmPin3 = 9; <---
int pwmPin4 = 10; <---
int pwmPin5 = 11; <---
int INaPin0 = 2;
int INbPin0 = 4;
int INaPin1 = 7; <---
int INbPin1 = 8; <---
int INaPin2 = 12; <---
int INbPin2 = 13; <---
int INaPin3 = A5; <---
int INbPin3 = A4; <---
int INaPin4 = A3; <---
int INbPin4 = A2; <---
int INaPin5 = A1; <---
int INbPin5 = A0; <---

void setup() {
    Serial.begin(115200);

    // set pins to output
    pinMode(pwmPin0, OUTPUT);
    pinMode(pwmPin1, OUTPUT);
    pinMode(pwmPin2, OUTPUT); <---
    pinMode(pwmPin3, OUTPUT); <---
    pinMode(pwmPin4, OUTPUT); <---
    pinMode(pwmPin5, OUTPUT); <---
    pinMode(INaPin0, OUTPUT); 
    pinMode(INbPin0, OUTPUT); 
    pinMode(INaPin1, OUTPUT); <---
    pinMode(INbPin1, OUTPUT); <---
    pinMode(INaPin2, OUTPUT); <---
    pinMode(INbPin2, OUTPUT); <---
    pinMode(INaPin3, OUTPUT); <---
    pinMode(INbPin3, OUTPUT); <---
    pinMode(INaPin4, OUTPUT); <---
    pinMode(INbPin4, OUTPUT); <---
    pinMode(INaPin5, OUTPUT); <---
    pinMode(INbPin5, OUTPUT); <---
}


// function to control motor
// speed is how fast the motor rotates
// Please set pwmPin, InaPin and INbPin for the motor you want to drive
void control_motor(int speed, int pwmPin, int INaPin, int INbPin){
    if(speed > 0){
        analogWrite(pwmPin, speed);
        digitalWrite(INaPin, HIGH);
        digitalWrite(INbPin, LOW);
    }
    else if(speed < 0){
        analogWrite(pwmPin, -speed);
        digitalWrite(INaPin, LOW);
        digitalWrite(INbPin, HIGH);
    }
    else{
        digitalWrite(INaPin, LOW);
        digitalWrite(INbPin, LOW);
    }
}

// In time loop, receive from serial and control 6 motors
void loop() {
    static int speed[6];
    static char buff[30];
    int counter = 0;

    // read command from raspberry pi
    while(Serial.available()){
        buff[counter] = Serial.read();
        if (counter > 30 || buff[counter] == '*') {
            buff[counter] = '\0';
            speed[0]=atoi(strtok(buff,","));
            speed[1]=atoi(strtok(NULL,","));
            speed[2]=atoi(strtok(NULL,",")); <---
            speed[3]=atoi(strtok(NULL,",")); <---
            speed[4]=atoi(strtok(NULL,",")); <---
            speed[5]=atoi(strtok(NULL,",")); <---
        }
        else{
            counter++;
        }
    }

    // control motors
    control_motor(speed[0], pwmPin0, INaPin0, INbPin0);
    control_motor(speed[1], pwmPin1, INaPin1, INbPin1);
    control_motor(speed[2], pwmPin2, INaPin2, INbPin2); <---
    control_motor(speed[3], pwmPin3, INaPin3, INbPin3); <---
    control_motor(speed[4], pwmPin4, INaPin4, INbPin4); <---
    control_motor(speed[5], pwmPin5, INaPin5, INbPin5); <---

    // send messages to raspberry pi
    Serial.print(speed[0]); Serial.print(",");
    Serial.print(speed[1]); Serial.print(",");
    Serial.print(speed[2]); Serial.print(","); <---
    Serial.print(speed[3]); Serial.print(","); <---
    Serial.print(speed[4]); Serial.print(","); <---
    Serial.println(speed[5]);                  <---

    delay(100);
}

 

Since mine has only 2 motors, do you think I could delete the lines that I marked ?


   
ReplyQuote
soumitra
(@soumitra)
Member
Joined: 5 years ago
Posts: 61
 

@spyder

Pwmpin0

Inapin0

Inbpin0

Pwmpin1

Inapin1

Inbpin1

Omly required if u are using L298 n type control where you have one pwm and 2 dir

 

Rest you dont use

Name the same in the function to control motor

Rest you undefine only 

 

 


   
ReplyQuote
soumitra
(@soumitra)
Member
Joined: 5 years ago
Posts: 61
 

For two motors only.

You can add on motor till 6 numbers in this program 


   
ReplyQuote
Spyder
(@spyder)
Member
Joined: 5 years ago
Posts: 846
 
Posted by: @sdey76

For two motors only.

You can add on motor till 6 numbers in this program 

I'm going to try to adapt it for the L298N if I can find a wiring diagram for it. I mean, I found one, but, it uses different pins than the ones in the sketch

Or, I've got an Adafruit Featherwing, a couple of a4988's, some uln2003agp's, ORRR, I could use the MD10C's I've been saving for the big robot. Seems like that would be overkill, but, at least they'd be ready when it comes time to install them

Those actually look easier since there's only 3 inputs, which means that I can only screw it up 5 times before I get it right

Thoughts ?


   
ReplyQuote
triform
(@triform)
Member
Joined: 5 years ago
Posts: 324
 

@spyder

What are the specs on the motors you plan to drive?


   
ReplyQuote
Spyder
(@spyder)
Member
Joined: 5 years ago
Posts: 846
 

@triform

That depends. For testing I was using a couple of small 6v motors that came with a toy sumobot that I picked up 20 years ago. They were already mounted in a frame with wheels, so I figured why not. I could power those from a cell phone battery. And they work, when I just use the Pi and the L298N. I never tried connecting the Pi to the arduino  then to the L298N.

The big ones I plan to put into the big robot are the same 12V gobilda motors that Bill is using

https://www.servocity.com/5201-series-53-1-ratio-105-rpm-spur-gear-motor-w-encoder

 


   
ReplyQuote
soumitra
(@soumitra)
Member
Joined: 5 years ago
Posts: 61
 

@spyder

Hii

You can chk this out

https://howtomechatronics.com/tutorials/arduino/arduino-dc-motor-control-tutorial-l298n-pwm-h-bridge/

MD10 Cytron will not work as it has pwm and dir only

This will work in those motor controller that have pwm plus two dir pins for high and low status to control motor direction.

That is the limitation of this code.

Thanks


   
ReplyQuote
Spyder
(@spyder)
Member
Joined: 5 years ago
Posts: 846
 

@sdey76

I've got a couple of projects that need to come together for this to work, and so far, I'm trying to be happy with one thing at a time. For some reason I'm not having luck with getting the arduino code to compile without errors, so I can't even tell if it's connected correctly, even tho I think it is, unless it compiles, I can't actually test it

The nice thing about the ubiquity is that it's got a nice interface for my cell phone, which I have turned off because I don't have the hardware that it requires in order to get the software to interface with it. So I'm still at having the pi running the motors with keyboard control, which is nice, but, I need that arduino to be in the loop

Next see the jetbot post...


   
ReplyQuote
soumitra
(@soumitra)
Member
Joined: 5 years ago
Posts: 61
 

@spyder

I will get back with the code by thursday

Am now at rio de janerio... ? vacation


   
ReplyQuote
Page 3 / 7