ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS - Linear Actuators

asked 2015-09-29 14:10:06 -0500

s1 gravatar image

updated 2015-09-29 14:14:49 -0500

ROS seems to have a library for servos but how would I control a Linear Actuator?

From this tutorial
http://learn.robotgeek.com/demo-code/...

It looks like an arduino can control an actuator with the use of push buttons, but how would i get feedback and signals to and from ROS, replacing push buttons with commands?

/* Linear Actuator Control using preset position

This demo shows how to do basic control of a large linear
actuator using an Arduino and two buttons. Each button is hard
coded with a preset position. Pressing a button will move
the actuator to that position.

 The circuit:
 * RobotGeek Pushbutton - Digital Pin 1
 * RobotGeek Pushbutton - Digital Pin 2
 * RobotGeek Relay - Digital Pin 4 
 * RobotGeek Relay - Digital Pin 7 

Products Used in this demo:
 - http://www.robotgeek.com/linear-actuators
 - http://www.robotgeek.com/robotgeek-geekduino-sensor-kit
 - http://www.robotgeek.com/robotGeek-pushbutton
 - http://www.robotgeek.com/robotgeek-relay

 */

// constants won't change. They're used here to set pin numbers:
const int button1Pin = 2;     // the number of the pushbutton1 pin
const int button2Pin = 4;     // the number of the pushbutton2 pin
const int relay1Pin =  7;      // the number of the Realy1 pin
const int relay2Pin =  8;      // the number of the Relay2 pin
const int sensorPin = 0;    // select the input pin for the potentiometer

// variables will change:
int button1State = 0;         // variable for reading the pushbutton status
int button2State = 0;         // variable for reading the pushbutton status
int sensorValue = 0;  // variable to store the value coming from the sensor

int goalPosition = 350; 
int CurrentPosition = 0; 
boolean Extending = false;
boolean Retracting = false;

void setup() {


        //start serial connection
        Serial.begin(9600);

        // initialize the pushbutton pin as an input:
        pinMode(button1Pin, INPUT);     
        pinMode(button2Pin, INPUT);    
        // initialize the relay pin as an output:
        pinMode(relay1Pin, OUTPUT);    
        pinMode(relay2Pin, OUTPUT);    

        //preset the relays to LOW
        digitalWrite(relay1Pin, LOW); 
        digitalWrite(relay2Pin, LOW); 


}

void loop(){

        // read the value from the sensor:
        CurrentPosition = analogRead(sensorPin); 


        // print the results to the serial monitor:
        Serial.print("Current = " );                       
        Serial.print(CurrentPosition);      
        Serial.print("\t Goal = ");      
        Serial.println(goalPosition);  

        // read the state of the pushbutton values:
        button1State = digitalRead(button1Pin);
        button2State = digitalRead(button2Pin);

        if (button1State == HIGH) {     
                // set new goal position
                goalPosition = 300; 

                if (goalPosition > CurrentPosition) {
                                Retracting = false;
                                Extending = true;
                                digitalWrite(relay1Pin, HIGH);  
                                digitalWrite(relay2Pin, LOW);  
                                Serial.println("Extending");     
                }      
                else if (goalPosition < CurrentPosition) {
                                Retracting = true;
                                Extending = false;
                                digitalWrite(relay1Pin, LOW);  
                                digitalWrite(relay2Pin, HIGH); 
                                Serial.println("Retracting");         
                }  
        }

        if (button2State == HIGH) {     
                // set new goal position
                goalPosition = 500; 

                if (goalPosition > CurrentPosition) {
                                Retracting = false;
                                Extending = true;
                                digitalWrite(relay1Pin, HIGH);  
                                digitalWrite(relay2Pin, LOW);  
                                Serial.println("Extending");   
                }        
                else if (goalPosition < CurrentPosition) {
                                Retracting = true;
                                Extending = false;
                                digitalWrite(relay1Pin, LOW);  
                                digitalWrite(relay2Pin, HIGH); 
                                Serial.println("Retracting");         
                }  
        }



        if (Extending = true && CurrentPosition > goalPosition) {
                //we have reached our goal, shut the relay off
                digitalWrite(relay1Pin, LOW); 
                boolean Extending = false; 
                Serial.println("IDLE");  
        }

        if (Retracting = true && CurrentPosition < goalPosition){
                //we have reached our goal, shut the relay off
                digitalWrite(relay2Pin, LOW); 
                boolean Retracting = false; 
                Serial.println("IDLE");  
        }




}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-09-29 14:27:54 -0500

Airuno2L gravatar image

Hello. Have you seen the rosserial_arduino package? It lets you talk to ROS from your arduino. There are a bunch of tutorials to get you started. You'll essentially want to take the code you have there and mix it with the blink tutorial which shows you how to subscribe to a message coming from ROS on your computer.

If you haven't done so already, you want to make sure you've done the beginner ROS tutorials to learn how things work with ROS in general before starting the arduino stuff.

edit flag offensive delete link more

Comments

Hi thanks for the response. I have gone thru the basic tutorials but I thought this was in the same section as "Servos". Will look into "Blink"

s1 gravatar image s1  ( 2015-09-29 14:33:26 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2015-09-29 14:10:06 -0500

Seen: 1,219 times

Last updated: Sep 29 '15