-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #1671: implement gyroscope rotation measurement for CalliopeV3
- Loading branch information
Showing
8 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...ources/crossCompilerTests/_expected/robotSpecific/astGenerated/calliopev3/sensor_gyro.ast
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,16 @@ | ||
SerialWriteAction[value: StringConst[value: Gyro test. Press A to step through]] | ||
|
||
(repeat [FOREVER, BoolConst[value: true]] | ||
AktionStmt [SerialWriteAction[value: SensorExpr [GyroSensor [_G, ANGLE, X]]]]WaitTimeStmt[time: NumConst[value: 100]] | ||
if SensorExpr [KeysSensor [A, PRESSED, - EMPTY_SLOT -]] | ||
,thenStmtFlowCon[flow: BREAK] | ||
|
||
) | ||
|
||
(repeat [FOREVER, BoolConst[value: true]] | ||
AktionStmt [SerialWriteAction[value: SensorExpr [GyroSensor [_G, ANGLE, Y]]]]WaitTimeStmt[time: NumConst[value: 100]] | ||
if SensorExpr [KeysSensor [A, PRESSED, - EMPTY_SLOT -]] | ||
,thenStmtFlowCon[flow: BREAK] | ||
|
||
) | ||
SerialWriteAction[value: StringConst[value: DONE]] |
6 changes: 6 additions & 0 deletions
6
...es/crossCompilerTests/_expected/robotSpecific/collectorResults/calliopev3/sensor_gyro.txt
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,6 @@ | ||
Sensors: | ||
[] | ||
Actors: | ||
[UsedActor [, KEY]] | ||
Methods: | ||
[GET_ROTATION] |
45 changes: 45 additions & 0 deletions
45
...urces/crossCompilerTests/_expected/robotSpecific/targetLanguage/calliopev3/sensor_gyro.py
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,45 @@ | ||
import calliopemini | ||
import random | ||
import math | ||
|
||
class BreakOutOfALoop(Exception): pass | ||
class ContinueLoop(Exception): pass | ||
|
||
timer1 = calliopemini.running_time() | ||
|
||
|
||
def run(): | ||
global timer1 | ||
print("Gyro test. Press A to step through") | ||
while True: | ||
print(get_rotation("pitch")) | ||
calliopemini.sleep(100) | ||
if calliopemini.button_a.is_pressed(): | ||
break | ||
while True: | ||
print(get_rotation("roll")) | ||
calliopemini.sleep(100) | ||
if calliopemini.button_a.is_pressed(): | ||
break | ||
print("DONE") | ||
|
||
def main(): | ||
try: | ||
run() | ||
except Exception as e: | ||
raise | ||
|
||
def get_rotation(dim): | ||
x = -calliopemini.accelerometer.get_y() | ||
y = calliopemini.accelerometer.get_x() | ||
z = -calliopemini.accelerometer.get_z() | ||
roll = math.atan2(y, z) | ||
if (dim == "roll"): | ||
return math.floor((-360*roll)/(2*math.pi)) | ||
elif (dim == "pitch"): | ||
factor = y * math.sin(roll) + z * math.cos(roll) | ||
if factor != 0: | ||
pitch = math.atan(-x / (factor)) | ||
return math.floor((360*pitch)/(2*math.pi)) | ||
if __name__ == "__main__": | ||
main() |
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
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