arduino代码

This commit is contained in:
astura
2026-07-18 18:22:58 +08:00
parent 2b7a320983
commit a2825ed71a
438 changed files with 36538 additions and 0 deletions
@@ -0,0 +1,38 @@
/*
* rosserial::std_msgs::Float64 Test
* Receives a Float64 input, subtracts 1.0, and publishes it
*/
#include <ros.h>
#include <std_msgs/Float64.h>
ros::NodeHandle nh;
float x;
void messageCb( const std_msgs::Float64& msg){
x = msg.data - 1.0;
digitalWrite(13, HIGH-digitalRead(13)); // blink the led
}
std_msgs::Float64 test;
ros::Subscriber<std_msgs::Float64> s("your_topic", &messageCb);
ros::Publisher p("my_topic", &test);
void setup()
{
pinMode(13, OUTPUT);
nh.initNode();
nh.advertise(p);
nh.subscribe(s);
}
void loop()
{
test.data = x;
p.publish( &test );
nh.spinOnce();
delay(10);
}