Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you want to interact with Arduino from ROS you have to do it by serial communication. I think the simplest way is python scripting. I did it a few years ago. I had implement a protocol with SYNC, OP_ID, PARAMETERS and CHECKSUM between the PC (ROS) and Arduino

This was my Python script import: ... import rospy import os import comm from datetime import datetime ....

where comm is the python file wich manages communication with arduino board

Here I am reading a message from arduino in my ros node file (this is the arduino objetc: ArdIfc)

...
  newMsg = ArdIfc.recv()
            if newMsg != None:
                if newMsg.mod == comm.MOD_SENSORS: 
                    if newMsg.op == comm.OP_GETCURRENTDIST:
                        torsoPos = newMsg.param[0]
...

Here I am sending a message to the Arduino from my ros node file

...
 rospy.loginfo("Torso-> Stop message.")
                msgMotor = comm.Msg(comm.ARDUINO_ID, comm.MOD_MOTORS, comm.OP_STOP_MOTOR, [], 0)
                ArdIfc.send(msgMotor)
                msgMotor_ack_received = False 
...

If you want the code I can send it to you.

best, Fedeico

If you want to interact with Arduino from ROS you have to do it by serial communication. I think the simplest way is python scripting. I did it a few years ago. I had implement a protocol with SYNC, OP_ID, PARAMETERS and CHECKSUM between the PC (ROS) and Arduino

This was my Python script import: import:

  ...
    import rospy
    import os
    import comm
    from datetime import datetime
    ....

....

where comm is the python file wich manages communication with arduino board

Here I am reading a message from arduino in my ros node file (this is the arduino objetc: ArdIfc)

...
  newMsg = ArdIfc.recv()
            if newMsg != None:
                if newMsg.mod == comm.MOD_SENSORS: 
                    if newMsg.op == comm.OP_GETCURRENTDIST:
                        torsoPos = newMsg.param[0]
...

Here I am sending a message to the Arduino from my ros node file

...
 rospy.loginfo("Torso-> Stop message.")
                msgMotor = comm.Msg(comm.ARDUINO_ID, comm.MOD_MOTORS, comm.OP_STOP_MOTOR, [], 0)
                ArdIfc.send(msgMotor)
                msgMotor_ack_received = False 
...

If you want the code I can send it to you.

best, Fedeico

If you want to interact with Arduino from ROS you have to do it by serial communication. I think the simplest way is python scripting. I did it a few years ago. I had implement a protocol with SYNC, OP_ID, PARAMETERS and CHECKSUM between the PC (ROS) and Arduino

This was my Python script import:imports:

  ...
    import rospy
    import os
    import comm
    from datetime import datetime
    ....

where comm is the python file wich manages communication with arduino board

Here I am reading a message from arduino in my ros node file (this is the arduino objetc: ArdIfc)

...
  newMsg = ArdIfc.recv()
            if newMsg != None:
                if newMsg.mod == comm.MOD_SENSORS: 
                    if newMsg.op == comm.OP_GETCURRENTDIST:
                        torsoPos = newMsg.param[0]
...

Here I am sending a message to the Arduino from my ros node file

...
 rospy.loginfo("Torso-> Stop message.")
                msgMotor = comm.Msg(comm.ARDUINO_ID, comm.MOD_MOTORS, comm.OP_STOP_MOTOR, [], 0)
                ArdIfc.send(msgMotor)
                msgMotor_ack_received = False 
...

If you want the code I can send it to you.

best, Fedeico