Browse Source

Add battery functionality

Touchais Julien 3 years ago
parent
commit
17f4df45d2

+ 1
- 1
software/raspberry/superviseur-robot/nbproject/private/configurations.xml View File

@@ -41,7 +41,7 @@
41 41
     </conf>
42 42
     <conf name="Debug__RPI_" type="1">
43 43
       <toolsSet>
44
-        <developmentServer>pi@10.105.1.08:22</developmentServer>
44
+        <developmentServer>pi@10.105.1.5:22</developmentServer>
45 45
         <platform>2</platform>
46 46
       </toolsSet>
47 47
       <dbx_gdbdebugger version="1">

+ 9
- 6
software/raspberry/superviseur-robot/nbproject/private/private.xml View File

@@ -7,12 +7,15 @@
7 7
     <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
8 8
     <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
9 9
         <group>
10
-            <file>file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/lib/camera.h</file>
11
-            <file>file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/lib/messages.cpp</file>
12
-            <file>file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/tasks.h</file>
13
-            <file>file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/lib/camera.cpp</file>
14
-            <file>file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/tasks.cpp</file>
15
-            <file>file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/lib/messages.h</file>
10
+            <file>file:/home/touchais/Documents/4A/RT/dumber/software/raspberry/superviseur-robot/main.cpp</file>
11
+            <file>file:/home/touchais/Documents/4A/RT/dumber/software/raspberry/superviseur-robot/tasks.cpp</file>
12
+            <file>file:/home/touchais/Documents/4A/RT/dumber/software/raspberry/superviseur-robot/lib/comrobot.h</file>
13
+            <file>file:/home/touchais/Documents/4A/RT/dumber/software/raspberry/superviseur-robot/lib/messages.h</file>
14
+            <file>file:/home/touchais/Documents/4A/RT/dumber/software/raspberry/superviseur-robot/lib/comrobot.cpp</file>
15
+            <file>file:/home/touchais/Documents/4A/RT/dumber/software/raspberry/superviseur-robot/lib/commonitor.h</file>
16
+            <file>file:/home/touchais/Documents/4A/RT/dumber/software/raspberry/superviseur-robot/tasks.h</file>
17
+            <file>file:/home/touchais/Documents/4A/RT/dumber/software/raspberry/superviseur-robot/lib/messages.cpp</file>
18
+            <file>file:/home/touchais/Documents/4A/RT/dumber/software/raspberry/superviseur-robot/lib/commonitor.cpp</file>
16 19
         </group>
17 20
     </open-files>
18 21
 </project-private>

+ 44
- 0
software/raspberry/superviseur-robot/tasks.cpp View File

@@ -26,6 +26,7 @@
26 26
 #define PRIORITY_TRECEIVEFROMMON 25
27 27
 #define PRIORITY_TSTARTROBOT 20
28 28
 #define PRIORITY_TCAMERA 21
29
+#define PRIORITY_TBATTERY 31
29 30
 
30 31
 /*
31 32
  * Some remarks:
@@ -123,6 +124,10 @@ void Tasks::Init() {
123 124
         cerr << "Error task create: " << strerror(-err) << endl << flush;
124 125
         exit(EXIT_FAILURE);
125 126
     }
127
+    if (err = rt_task_create(&th_checkBattery, "th_checkBattery", 0, PRIORITY_TBATTERY, 0)) {
128
+        cerr << "Error task create: " << strerror(-err) << endl << flush;
129
+        exit(EXIT_FAILURE);
130
+    }
126 131
     cout << "Tasks created successfully" << endl << flush;
127 132
 
128 133
     /**************************************************************************************/
@@ -167,6 +172,10 @@ void Tasks::Run() {
167 172
         cerr << "Error task start: " << strerror(-err) << endl << flush;
168 173
         exit(EXIT_FAILURE);
169 174
     }
175
+    if (err = rt_task_start(&th_checkBattery, (void(*)(void*)) & Tasks::CheckBatteryTask, this)) {
176
+        cerr << "Error task start: " << strerror(-err) << endl << flush;
177
+        exit(EXIT_FAILURE);
178
+    }
170 179
 
171 180
     cout << "Tasks launched" << endl << flush;
172 181
 }
@@ -384,6 +393,41 @@ void Tasks::MoveTask(void *arg) {
384 393
 }
385 394
 
386 395
 /**
396
+ * @brief Thread printing the robot battery
397
+ */
398
+void Tasks::CheckBatteryTask(void *arg) {
399
+    cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
400
+    // Synchronization barrier (waiting that all tasks are starting)
401
+    rt_sem_p(&sem_barrier, TM_INFINITE);
402
+    
403
+    /**************************************************************************************/
404
+    /* The task starts here                                                               */
405
+    /**************************************************************************************/
406
+    
407
+    MessageBattery * batLevel;
408
+    int rs;
409
+    
410
+    rt_task_set_periodic(NULL, TM_NOW, 500000000);
411
+    
412
+    while(1) {
413
+        rt_task_wait_period(NULL);
414
+        
415
+        rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE);
416
+        rs = robotStarted;
417
+        rt_mutex_release(&mutex_robotStarted);
418
+        if (rs == 1) {
419
+            rt_mutex_acquire(&mutex_robot, TM_INFINITE);
420
+            batLevel = (MessageBattery*)robot.Write(new Message(MESSAGE_ROBOT_BATTERY_GET));
421
+            rt_mutex_release(&mutex_robot);
422
+
423
+            rt_mutex_acquire(&mutex_monitor, TM_INFINITE);
424
+            monitor.Write(batLevel);
425
+            rt_mutex_release(&mutex_monitor);
426
+        }
427
+    }
428
+}
429
+
430
+/**
387 431
  * Write a message in a given queue
388 432
  * @param queue Queue identifier
389 433
  * @param msg Message to be stored

+ 6
- 1
software/raspberry/superviseur-robot/tasks.h View File

@@ -14,7 +14,6 @@
14 14
  * You should have received a copy of the GNU General Public License
15 15
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16
  */
17
-
18 17
 #ifndef __TASKS_H__
19 18
 #define __TASKS_H__
20 19
 
@@ -76,6 +75,7 @@ private:
76 75
     RT_TASK th_openComRobot;
77 76
     RT_TASK th_startRobot;
78 77
     RT_TASK th_move;
78
+    RT_TASK th_checkBattery;
79 79
     
80 80
     /**********************************************************************/
81 81
     /* Mutex                                                              */
@@ -132,6 +132,11 @@ private:
132 132
      */
133 133
     void MoveTask(void *arg);
134 134
     
135
+    /**
136
+     * @brief Thread handling control of the robot.
137
+     */
138
+    void CheckBatteryTask(void *arg);
139
+    
135 140
     /**********************************************************************/
136 141
     /* Queue services                                                     */
137 142
     /**********************************************************************/

Loading…
Cancel
Save