BLUESINK / Mbed 2 deprecated s-rov-firmware

Dependencies:   mbed pca9685 ros_lib_kinetic ads1015

Files at this revision

API Documentation at this revision

Comitter:
YJ_Kim
Date:
Mon Jan 16 13:01:15 2017 +0000
Parent:
1:2062e7a67afd
Child:
3:2c5258907150
Commit message:
Import rosserial

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
msg/s_rov_msgs/s_rov_control_esc.h Show annotated file Show diff for this revision Revisions of this file
msg/s_rov_msgs/s_rov_control_extra.h Show annotated file Show diff for this revision Revisions of this file
msg/s_rov_msgs/s_rov_control_led.h Show annotated file Show diff for this revision Revisions of this file
pca9685.lib Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Jan 16 05:24:30 2017 +0000
+++ b/main.cpp	Mon Jan 16 13:01:15 2017 +0000
@@ -1,26 +1,77 @@
 #include "mbed.h"
 #include <ros.h>
-#include <std_msgs/Float32.h>
+#include <s_rov_msgs/s_rov_control_extra.h>
+#include <s_rov_msgs/s_rov_control_esc.h>
+#include <s_rov_msgs/s_rov_control_led.h>
 #include <pca9685/pca9685.h>
 
+#define CH_LED1        2
+#define CH_LED2        3
+#define CH_ESC1        4
+#define CH_ESC2        5
+#define CH_ESC3        6
+#define CH_ESC4        7
+#define CH_1          11
+#define CH_2          10
+#define CH_3           9
+#define CH_4           8
+#define CH_5           0
+#define CH_6           1
+
+#define ESC_SWITCH  PB_1
+
+
+/**************************** System Configuration ***************************/
+
+I2C i2c(PB_11, PB_10);        // sda, scl
+PCA9685 pwm(0x40, i2c, 50);  // Address, i2c object, frequency
+DigitalOut ESC_switch(ESC_SWITCH);
+
+/**************************** System Configuration ***************************/
+
+/******************************ROS Configuration *****************************/
+
 class NewHardware : public MbedHardware{
     public:
     NewHardware():MbedHardware(PA_9, PA_10, 57600){};    
 };
 ros::NodeHandle_<NewHardware> nh;
 
-I2C i2c(PB_11, PB_10);        // sda, scl
-PCA9685 pwm(0x40, i2c, 50); 
-
-void messageCb(const std_msgs::Float32& angle){
-    pwm.set_servo_angle(CH_6, angle.data);
+void messageExtra(const s_rov_msgs::s_rov_control_extra& control_msg){
+    pwm.set_servo_angle(CH_1, control_msg.extraPWM[0]);
+    pwm.set_servo_angle(CH_2, control_msg.extraPWM[1]);
+    pwm.set_servo_angle(CH_3, control_msg.extraPWM[2]);
+    pwm.set_servo_angle(CH_4, control_msg.extraPWM[3]);
+    pwm.set_servo_angle(CH_5, control_msg.extraPWM[4]);
+    pwm.set_servo_angle(CH_6, control_msg.extraPWM[5]);
 }
 
-ros::Subscriber<std_msgs::Float32> sub("servo", &messageCb);
+void messageESC(const s_rov_msgs::s_rov_control_esc& control_msg){
+    pwm.set_servo_angle(CH_ESC1, control_msg.escPWM[0]);
+    pwm.set_servo_angle(CH_ESC2, control_msg.escPWM[1]);
+    pwm.set_servo_angle(CH_ESC3, control_msg.escPWM[2]);
+    pwm.set_servo_angle(CH_ESC4, control_msg.escPWM[3]);
+    ESC_switch = control_msg.escSwitch;
+}
+
+void messageLed(const s_rov_msgs::s_rov_control_led& control_msg){
+    pwm.set_pwm_duty(CH_LED1, control_msg.ledPWM[0]);
+    pwm.set_pwm_duty(CH_LED2, control_msg.ledPWM[1]);
+}
+
+ros::Subscriber<s_rov_msgs::s_rov_control_extra> sub_extra_control("/s_rov/control/extra", &messageExtra);
+ros::Subscriber<s_rov_msgs::s_rov_control_esc> sub_esc_control("/s_rov/control/esc", &messageESC);
+ros::Subscriber<s_rov_msgs::s_rov_control_led> sub_led_control("/s_rov/control/led", &messageLed);
+
+/******************************ROS Configuration *****************************/
 
 int main() {
     nh.initNode();
-    nh.subscribe(sub);
+    nh.subscribe(sub_extra_control);
+    nh.subscribe(sub_esc_control);
+    nh.subscribe(sub_led_control);
+    
+    ESC_switch = false;
     pwm.init();
     
     while (1) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/msg/s_rov_msgs/s_rov_control_esc.h	Mon Jan 16 13:01:15 2017 +0000
@@ -0,0 +1,82 @@
+#ifndef _ROS_s_rov_msgs_s_rov_control_esc_h
+#define _ROS_s_rov_msgs_s_rov_control_esc_h
+
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include "ros/msg.h"
+
+namespace s_rov_msgs
+{
+
+  class s_rov_control_esc : public ros::Msg
+  {
+    public:
+      float escPWM[4];
+      bool escSwitch;
+
+    s_rov_control_esc():
+      escPWM(),
+      escSwitch(0)
+    {
+    }
+
+    virtual int serialize(unsigned char *outbuffer) const
+    {
+      int offset = 0;
+      for( uint32_t i = 0; i < 4; i++){
+      union {
+        float real;
+        uint32_t base;
+      } u_escPWMi;
+      u_escPWMi.real = this->escPWM[i];
+      *(outbuffer + offset + 0) = (u_escPWMi.base >> (8 * 0)) & 0xFF;
+      *(outbuffer + offset + 1) = (u_escPWMi.base >> (8 * 1)) & 0xFF;
+      *(outbuffer + offset + 2) = (u_escPWMi.base >> (8 * 2)) & 0xFF;
+      *(outbuffer + offset + 3) = (u_escPWMi.base >> (8 * 3)) & 0xFF;
+      offset += sizeof(this->escPWM[i]);
+      }
+      union {
+        bool real;
+        uint8_t base;
+      } u_escSwitch;
+      u_escSwitch.real = this->escSwitch;
+      *(outbuffer + offset + 0) = (u_escSwitch.base >> (8 * 0)) & 0xFF;
+      offset += sizeof(this->escSwitch);
+      return offset;
+    }
+
+    virtual int deserialize(unsigned char *inbuffer)
+    {
+      int offset = 0;
+      for( uint32_t i = 0; i < 4; i++){
+      union {
+        float real;
+        uint32_t base;
+      } u_escPWMi;
+      u_escPWMi.base = 0;
+      u_escPWMi.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
+      u_escPWMi.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
+      u_escPWMi.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
+      u_escPWMi.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
+      this->escPWM[i] = u_escPWMi.real;
+      offset += sizeof(this->escPWM[i]);
+      }
+      union {
+        bool real;
+        uint8_t base;
+      } u_escSwitch;
+      u_escSwitch.base = 0;
+      u_escSwitch.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
+      this->escSwitch = u_escSwitch.real;
+      offset += sizeof(this->escSwitch);
+     return offset;
+    }
+
+    const char * getType(){ return "s_rov_msgs/s_rov_control_esc"; };
+    const char * getMD5(){ return "29b94efb4e96b7ab876134acfa0a6e69"; };
+
+  };
+
+}
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/msg/s_rov_msgs/s_rov_control_extra.h	Mon Jan 16 13:01:15 2017 +0000
@@ -0,0 +1,65 @@
+#ifndef _ROS_s_rov_msgs_s_rov_control_extra_h
+#define _ROS_s_rov_msgs_s_rov_control_extra_h
+
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include "ros/msg.h"
+
+namespace s_rov_msgs
+{
+
+  class s_rov_control_extra : public ros::Msg
+  {
+    public:
+      float extraPWM[6];
+
+    s_rov_control_extra():
+      extraPWM()
+    {
+    }
+
+    virtual int serialize(unsigned char *outbuffer) const
+    {
+      int offset = 0;
+      for( uint32_t i = 0; i < 6; i++){
+      union {
+        float real;
+        uint32_t base;
+      } u_extraPWMi;
+      u_extraPWMi.real = this->extraPWM[i];
+      *(outbuffer + offset + 0) = (u_extraPWMi.base >> (8 * 0)) & 0xFF;
+      *(outbuffer + offset + 1) = (u_extraPWMi.base >> (8 * 1)) & 0xFF;
+      *(outbuffer + offset + 2) = (u_extraPWMi.base >> (8 * 2)) & 0xFF;
+      *(outbuffer + offset + 3) = (u_extraPWMi.base >> (8 * 3)) & 0xFF;
+      offset += sizeof(this->extraPWM[i]);
+      }
+      return offset;
+    }
+
+    virtual int deserialize(unsigned char *inbuffer)
+    {
+      int offset = 0;
+      for( uint32_t i = 0; i < 6; i++){
+      union {
+        float real;
+        uint32_t base;
+      } u_extraPWMi;
+      u_extraPWMi.base = 0;
+      u_extraPWMi.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
+      u_extraPWMi.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
+      u_extraPWMi.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
+      u_extraPWMi.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
+      this->extraPWM[i] = u_extraPWMi.real;
+      offset += sizeof(this->extraPWM[i]);
+      }
+     return offset;
+    }
+
+    const char * getType(){ return "s_rov_msgs/s_rov_control_extra"; };
+    const char * getMD5(){ return "e0b1472b58d9c0d22a92595a37385578"; };
+
+  };
+
+}
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/msg/s_rov_msgs/s_rov_control_led.h	Mon Jan 16 13:01:15 2017 +0000
@@ -0,0 +1,65 @@
+#ifndef _ROS_s_rov_msgs_s_rov_control_led_h
+#define _ROS_s_rov_msgs_s_rov_control_led_h
+
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include "ros/msg.h"
+
+namespace s_rov_msgs
+{
+
+  class s_rov_control_led : public ros::Msg
+  {
+    public:
+      float ledPWM[2];
+
+    s_rov_control_led():
+      ledPWM()
+    {
+    }
+
+    virtual int serialize(unsigned char *outbuffer) const
+    {
+      int offset = 0;
+      for( uint32_t i = 0; i < 2; i++){
+      union {
+        float real;
+        uint32_t base;
+      } u_ledPWMi;
+      u_ledPWMi.real = this->ledPWM[i];
+      *(outbuffer + offset + 0) = (u_ledPWMi.base >> (8 * 0)) & 0xFF;
+      *(outbuffer + offset + 1) = (u_ledPWMi.base >> (8 * 1)) & 0xFF;
+      *(outbuffer + offset + 2) = (u_ledPWMi.base >> (8 * 2)) & 0xFF;
+      *(outbuffer + offset + 3) = (u_ledPWMi.base >> (8 * 3)) & 0xFF;
+      offset += sizeof(this->ledPWM[i]);
+      }
+      return offset;
+    }
+
+    virtual int deserialize(unsigned char *inbuffer)
+    {
+      int offset = 0;
+      for( uint32_t i = 0; i < 2; i++){
+      union {
+        float real;
+        uint32_t base;
+      } u_ledPWMi;
+      u_ledPWMi.base = 0;
+      u_ledPWMi.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
+      u_ledPWMi.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
+      u_ledPWMi.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
+      u_ledPWMi.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
+      this->ledPWM[i] = u_ledPWMi.real;
+      offset += sizeof(this->ledPWM[i]);
+      }
+     return offset;
+    }
+
+    const char * getType(){ return "s_rov_msgs/s_rov_control_led"; };
+    const char * getMD5(){ return "b1fb200946fca2f8d28e4b9bda55f10b"; };
+
+  };
+
+}
+#endif
\ No newline at end of file
--- a/pca9685.lib	Mon Jan 16 05:24:30 2017 +0000
+++ b/pca9685.lib	Mon Jan 16 13:01:15 2017 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/BLUESINK/code/pca9685/#c6fb5a9a8f91
+https://developer.mbed.org/teams/BLUESINK/code/pca9685/#7e071acc57b1