action gobeur

Dependencies:   ros_messages mbed Servo Manche_a_air Gobeur ros_lib_melodic

Committer:
kyxstark
Date:
Thu Jul 08 14:11:48 2021 +0000
Revision:
6:4af07c2de6ba
Parent:
5:c38735ab64dc
Child:
9:59a9831f067d
implementation de deux gobeurs et trois servomoteurs avec imterpretation des messages ROS(non teste);

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mondiaye 1:d6bbefff36fa 1 /*
mondiaye 1:d6bbefff36fa 2 * rosserial Publisher Example
mondiaye 1:d6bbefff36fa 3 * Prints "hello world!"
mondiaye 1:d6bbefff36fa 4 */
mondiaye 1:d6bbefff36fa 5
mondiaye 1:d6bbefff36fa 6 #include"mbed.h"
mondiaye 1:d6bbefff36fa 7 #include <ros.h>
mondiaye 1:d6bbefff36fa 8 #include <std_msgs/String.h>
mondiaye 1:d6bbefff36fa 9 #include <Gobeur.h>
kyxstark 6:4af07c2de6ba 10 #include <Manche_a_air.h>
mondiaye 1:d6bbefff36fa 11 #include <Servo.h>
kyxstark 6:4af07c2de6ba 12 #include "actuators.h"
kyxstark 6:4af07c2de6ba 13
kyxstark 6:4af07c2de6ba 14 Gobeur* gobeurs[2];
kyxstark 6:4af07c2de6ba 15 Manche_a_air* maas[3];
kyxstark 6:4af07c2de6ba 16
mondiaye 1:d6bbefff36fa 17
mondiaye 3:a284535865b7 18 ros::NodeHandle nh;
mondiaye 3:a284535865b7 19
mondiaye 3:a284535865b7 20 std_msgs::String str_msg;
mondiaye 3:a284535865b7 21 ros::Publisher chatter("chatter", &str_msg);
mondiaye 3:a284535865b7 22
kyxstark 6:4af07c2de6ba 23 ros::Subscriber<gobeur_node::Gobeur_msg> sub_gobeur("gobeur", &gobeur_trait_msg);
kyxstark 6:4af07c2de6ba 24 ros::Subscriber<manche_a_air_node::Manche_a_air_msg> sub_maa("manche_a_air", &maa_trait_msg);
mondiaye 3:a284535865b7 25
mondiaye 3:a284535865b7 26 char hello[13] = "hello!";
mondiaye 1:d6bbefff36fa 27
mondiaye 3:a284535865b7 28
kyxstark 6:4af07c2de6ba 29 float clock_s() { return us_ticker_read() / 1000000.0f; }
kyxstark 6:4af07c2de6ba 30 uint64_t clock_ms() { return us_ticker_read() / 1000; }
kyxstark 6:4af07c2de6ba 31 uint64_t clock_us() { return us_ticker_read(); }
mondiaye 3:a284535865b7 32
kyxstark 6:4af07c2de6ba 33 void gobeur_trait_msg(const gobeur_node::Gobeur_msg& gobeur_msg)
mondiaye 1:d6bbefff36fa 34 {
kyxstark 6:4af07c2de6ba 35 gobeurs[gobeur_msg.index_gobeur]->update_order(gobeur_msg.gobeur_order) ;
mondiaye 1:d6bbefff36fa 36 }
kyxstark 6:4af07c2de6ba 37 void maa_trait_msg(const manche_a_air_node::Manche_a_air_msg& maa_msg)
kyxstark 6:4af07c2de6ba 38 {
kyxstark 6:4af07c2de6ba 39 maas[maa_msg.index_manche_a_air]->update_order(maa_msg.manche_a_air_order) ;
mondiaye 1:d6bbefff36fa 40 }
mondiaye 1:d6bbefff36fa 41
mondiaye 1:d6bbefff36fa 42 int main() {
kyxstark 6:4af07c2de6ba 43 gobeurs[0] = new Gobeur(GOBEUR_TURBINE_LEFT_PIN, GOBEUR_SERVO_LEFT_PIN, GOBEUR_TURBINE_TH_ON, GOBEUR_TURBINE_TH_OFF, GOBEUR_SERVO_POS_OPEN, GOBEUR_SERVO_POS_CLOSE );
kyxstark 6:4af07c2de6ba 44 gobeurs[1] = new Gobeur(GOBEUR_TURBINE_RIGHT_PIN, GOBEUR_SERVO_RIGHT_PIN, GOBEUR_TURBINE_TH_ON, GOBEUR_TURBINE_TH_OFF, GOBEUR_SERVO_POS_OPEN, GOBEUR_SERVO_POS_CLOSE );
kyxstark 6:4af07c2de6ba 45 maas[0] = new Manche_a_air(MAA_SERVO_LEFT_PIN, MAA_SERVO_POS_OPEN, MAA_SERVO_POS_CLOSE);
kyxstark 6:4af07c2de6ba 46 maas[1] = new Manche_a_air(MAA_SERVO_RIGHT_PIN, MAA_SERVO_POS_OPEN, MAA_SERVO_POS_CLOSE);
kyxstark 6:4af07c2de6ba 47 maas[2] = new Manche_a_air(FLAG_SERVO_PIN, FLAG_SERVO_POS_OPEN, FLAG_SERVO_POS_CLOSE);
kyxstark 6:4af07c2de6ba 48
kyxstark 6:4af07c2de6ba 49 //maas[2] = new Manche_a_air(FLAG_SERVO_PIN, FLAG_SERVO_POS_OPEN, FLAG_SERVO_POS_CLOSE);
kyxstark 6:4af07c2de6ba 50 maas[2]->set_auto_open(1, 1);
kyxstark 6:4af07c2de6ba 51 maas[2]->set_auto_close(1, 5);
kyxstark 6:4af07c2de6ba 52 maas[0]->set_auto_open(1, 2);
kyxstark 6:4af07c2de6ba 53 maas[0]->set_auto_close(1, 4);
kyxstark 6:4af07c2de6ba 54 maas[1]->set_auto_open(1, 3);
kyxstark 6:4af07c2de6ba 55 maas[1]->set_auto_close(1, 3);
kyxstark 6:4af07c2de6ba 56
mondiaye 1:d6bbefff36fa 57 nh.initNode();
mondiaye 1:d6bbefff36fa 58 nh.advertise(chatter);
kyxstark 6:4af07c2de6ba 59 nh.subscribe(sub_gobeur);
kyxstark 6:4af07c2de6ba 60 nh.subscribe(sub_maa);
mondiaye 3:a284535865b7 61
kyxstark 6:4af07c2de6ba 62 str_msg.data = hello;
kyxstark 6:4af07c2de6ba 63 chatter.publish( &str_msg );
mondiaye 3:a284535865b7 64
mondiaye 1:d6bbefff36fa 65 while (1) {
kyxstark 6:4af07c2de6ba 66 gobeurs[0]->automate();
kyxstark 6:4af07c2de6ba 67 gobeurs[1]->automate();
kyxstark 6:4af07c2de6ba 68 maas[0]->automate();
kyxstark 6:4af07c2de6ba 69 maas[1]->automate();
kyxstark 6:4af07c2de6ba 70 maas[2]->automate();
kyxstark 6:4af07c2de6ba 71 nh.spinOnce();
mondiaye 1:d6bbefff36fa 72
mondiaye 1:d6bbefff36fa 73 }
kyxstark 6:4af07c2de6ba 74 }
kyxstark 6:4af07c2de6ba 75