send_control



In [1]:
import rospy
from std_msgs.msg import Float32, Float64, String, Header
from sensor_msgs.msg import JointState


from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

Main control


In [2]:
rospy.init_node("Control")

In [3]:
pub1_control=rospy.Publisher("/rail1_control", JointState, queue_size=10)
pub2_control=rospy.Publisher("/rail2_control", JointState, queue_size=10)

sub1_state = rospy.Subscriber("rail1_state", JointState)
sub2_state = rospy.Subscriber("rail2_state", JointState)

In [4]:
@interact_manual(position=widgets.FloatSlider(description="Tor 1 position",
                                min=100,
                                max=1900,
                                step=1,
                                value=1000,
                                continuous_update=False),
         velocity=widgets.FloatSlider(description="Velocity",
                                min=1,
                                max=300,
                                step=1,
                                value=100,
                                continuous_update=False),
         acceleration=widgets.FloatSlider(description="Acceleration",
                                min=1,
                                max=300,
                                step=1,
                                value=100,
                                continuous_update=False), 
         ) #you could also go 0-2000

def send_position_1(position,velocity,acceleration):
    control1 = JointState()
    control1.header = Header()
    control1.header.stamp = rospy.Time.now()
    control1.name = ["c_1"]
    control1.position = [position]
    control1.velocity = [velocity]
    control1.effort = [acceleration]

    pub1_control.publish(control1)
    
@interact_manual(position=widgets.FloatSlider(description="Tor 2 position",
                                min=100,
                                max=1900,
                                step=1,
                                value=1000,
                                continuous_update=False),
         velocity=widgets.FloatSlider(description="Velocity",
                                min=1,
                                max=300,
                                step=1,
                                value=100,
                                continuous_update=False), 
         acceleration=widgets.FloatSlider(description="Acceleration",
                                min=1,
                                max=300,
                                step=1,
                                value=100,
                                continuous_update=False), 
         ) #you could also go 0-2000

def send_position_2(position,velocity,acceleration):
    control2 = JointState()
    control2.header = Header()
    control2.header.stamp = rospy.Time.now()
    control2.name = ["c_2"]
    control2.position = [position]
    control2.velocity = [velocity]
    control2.effort = [acceleration]

    pub2_control.publish(control2)



In [ ]:


In [ ]:
from ipywidgets import Button
from IPython.display import display

stop_button=Button(description='Stop', button_style='danger')

def please_stop(what):
    print("no")
    
stop_button.on_click(please_stop)

display(stop_button)

In [ ]:
stop_button=Button(description='Stop', button_style='danger')

In [ ]:
send_position(1500)

In [ ]:
pos_2 = 1200
vel_2 = 100
accel_2 = 100

control2 = JointState()
control2.header = Header()
control2.header.stamp = rospy.Time.now()
control2.name = ["c_2"]
control2.position = [pos_2]
control2.velocity = [vel_2]
control2.effort = [accel_2]

pub2_control.publish(control2)

In [ ]:
pos_1 = 1000
vel_1 = 100
accel_1 = 75

pos_2 = 1000
vel_2 = 150
accel_2 = 50

control1 = JointState()
control1.header = Header()
control1.header.stamp = rospy.Time.now()
control1.name = ["c_1"]
control1.position = [pos_1]
control1.velocity = [vel_1]
control1.effort = [accel_1]

control2 = JointState()
control2.header = Header()
control2.header.stamp = rospy.Time.now()
control2.name = ["c_2"]
control2.position = [pos_2]
control2.velocity = [vel_2]
control2.effort = [accel_2]

pub1_control.publish(control1)
pub2_control.publish(control2)

In [ ]:
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

In [ ]:
@interact(x=True, y=1.0)
def g(x, y):
    return (x, y)

In [ ]: