-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
120 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import threading | ||
import time | ||
import csv | ||
|
||
class DataRecorder: | ||
def __init__( | ||
self, | ||
freq, | ||
path, | ||
myobrick_flex, | ||
myobrick_extend, | ||
angle_sensor | ||
): | ||
self.freq = freq | ||
self.path = path | ||
self.myobrick_flex = myobrick_flex | ||
self.myobrick_extend = myobrick_extend | ||
self.angle_sensor = angle_sensor | ||
|
||
|
||
self.stop_event = threading.Event() | ||
|
||
def _run(self): | ||
with open(self.path, 'a') as csvfile: | ||
writer = csv.writer(csvfile) | ||
while not self.stop_event.is_set(): | ||
flex_state = self.myobrick_flex.get_state() | ||
extend_state = self.myobrick_extend.get_state() | ||
|
||
writer.writerow([ | ||
time.time(), | ||
self.angle_sensor.get_value(), | ||
flex_state['pv_pos_encoder'], | ||
flex_state['pv_torque_encoder'], | ||
flex_state['pv_current'], | ||
self.myobrick_flex.sp_pwm, | ||
extend_state['pv_pos_encoder'], | ||
extend_state['pv_torque_encoder'], | ||
extend_state['pv_current'], | ||
self.myobrick_extend.sp_pwm, | ||
|
||
]) | ||
|
||
time.sleep(1/self.freq) | ||
|
||
def start(self): | ||
self.stop_event.clear() | ||
self.thread = threading.Thread(target=self._run) | ||
self.thread.start() | ||
|
||
def stop(self): | ||
self.stop_event.set() | ||
self.thread.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
uint64 tick | ||
|
||
float32 flex_myobrick_pwm | ||
float32 extend_myobrick_pwm | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
uint64 tick | ||
|
||
float32 angle | ||
|
||
bool safety_switch_pressed | ||
|