Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
blimp
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mehtank
blimp
Commits
a600908c
Commit
a600908c
authored
4 years ago
by
mehtank
Browse files
Options
Downloads
Patches
Plain Diff
A to swap vertical axes
parent
60aadeb0
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
joystick.py
+36
-36
36 additions, 36 deletions
joystick.py
with
36 additions
and
36 deletions
joystick.py
+
36
−
36
View file @
a600908c
#!/usr/bin/env python3
import
pygame
import
math
from
websocket
import
create_connection
#helper function to change joystick range of [0,1] to [0,255]
def
convertServo
(
OldValue
):
OldMax
=
1
OldMin
=
-
1
NewMax
=
255
NewMin
=
0
OldRange
=
(
OldMax
-
OldMin
)
NewRange
=
(
NewMax
-
NewMin
)
NewValue
=
(((
OldValue
-
OldMin
)
*
NewRange
)
/
OldRange
)
+
NewMin
return
int
(
NewValue
)
def
convertThrust
(
OldValue
):
def
rescale
(
oldValue
,
newMin
=
0
,
newMax
=
255
):
oldMax
=
1
oldMin
=
-
1
OldMax
=
1
OldMin
=
-
1
N
ew
Max
=
255
NewMin
=
-
255
oldRange
=
(
oldMax
-
oldMin
)
newRange
=
(
newMax
-
newMin
)
n
ew
Value
=
(((
oldValue
-
oldMin
)
*
newRange
)
/
oldRange
)
+
newMin
return
int
(
newValue
)
OldRange
=
(
OldMax
-
OldMin
)
NewRange
=
(
NewMax
-
NewMin
)
NewValue
=
(((
OldValue
-
OldMin
)
*
NewRange
)
/
OldRange
)
+
NewMin
return
int
(
math
.
fabs
(
NewValue
))
#helper function to change joystick range of [0,1] to [0,255]
def
convertServo
(
axis
):
return
rescale
(
joystick
.
get_axis
(
axis
),
0
,
180
)
def
convertThrust
(
data
):
return
abs
(
rescale
(
data
,
-
255
,
255
))
#helper function to assign the proper hbridge values
def
convertHBridge
(
data
):
if
data
>
0
:
return
[
1
,
0
]
else
:
return
[
0
,
1
]
return
[
0
,
1
]
def
convertAxis
(
axis
):
value
=
joystick
.
get_axis
(
axis
)
*-
1
return
convertHBridge
(
value
)
+
[
convertThrust
(
value
)
]
data
=
joystick
.
get_axis
(
axis
)
*-
1
return
convertHBridge
(
data
)
+
[
convertThrust
(
data
)
]
if
__name__
==
"
__main__
"
:
target
=
"
ws://192.168.4.1:81
"
#Set up connection to Blimp Board over websocket
#ws = create_connection(target)
...
...
@@ -57,6 +42,16 @@ if __name__ == "__main__":
pygame
.
joystick
.
init
()
done
=
False
# Joystick axes
turn
=
0
forward
=
1
vertical
=
3
vertical_alt
=
4
camera_l
=
2
camera_r
=
5
debounce
=
0
while
not
done
:
try
:
for
event
in
pygame
.
event
.
get
():
...
...
@@ -67,14 +62,19 @@ if __name__ == "__main__":
joystick
.
init
()
axes
=
joystick
.
get_numaxes
()
forward
=
1
vertical
=
3
turn
=
joystick
.
get_axis
(
0
)
# Swap axes 3 and 4 on 'A' button push [ windowns vs linux ]
if
joystick
.
get_button
(
0
)
and
not
debounce
:
v
=
vertical_alt
vertical_alt
=
vertical
vertical
=
v
debounce
=
20
if
debounce
:
debounce
-=
1
#Create a new binary code to send to blimp
cmd
=
[
126
]
+
convertAxis
(
forward
)
+
[
convertServo
(
turn
)
]
+
convertAxis
(
vertical
)
+
[
127
]
cmd
=
[
126
]
+
convertAxis
(
forward
)
+
\
[
convertServo
(
turn
)
]
+
\
convertAxis
(
vertical
)
+
\
[
(
180
-
convertServo
(
camera_l
)
+
convertServo
(
camera_r
))
//
2
]
print
(
cmd
)
#ws.send_binary(cmd)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment