Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Q
quadruped-reactive-walking
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gepetto
quadruped-reactive-walking
Commits
e2df2e15
Commit
e2df2e15
authored
3 years ago
by
odri
Browse files
Options
Downloads
Patches
Plain Diff
Implementation of gamepad client
parent
0db56812
No related branches found
No related tags found
No related merge requests found
Pipeline
#16533
failed
3 years ago
Stage: test
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/qrw/Joystick.hpp
+21
-1
21 additions, 1 deletion
include/qrw/Joystick.hpp
src/Controller.cpp
+9
-2
9 additions, 2 deletions
src/Controller.cpp
src/Joystick.cpp
+38
-7
38 additions, 7 deletions
src/Joystick.cpp
src/control_solo12.cpp
+17
-17
17 additions, 17 deletions
src/control_solo12.cpp
with
85 additions
and
27 deletions
include/qrw/Joystick.hpp
+
21
−
1
View file @
e2df2e15
...
...
@@ -9,6 +9,10 @@
#ifndef JOYSTICK_H_INCLUDED
#define JOYSTICK_H_INCLUDED
#include
<fcntl.h>
#include
<stdio.h>
#include
<unistd.h>
#include
<linux/joystick.h>
#include
<iostream>
#include
<fstream>
#include
<cmath>
...
...
@@ -17,6 +21,15 @@
#include
"qrw/Types.h"
#include
"qrw/Params.hpp"
struct
gamepad_struct
{
double
v_x
=
0.0
;
double
v_y
=
0.0
;
double
w_yaw
=
0.0
;
int
start
=
0
;
int
select
=
0
;
};
class
Joystick
{
public:
////////////////////////////////////////////////////////////////////////////////////////////////
...
...
@@ -40,7 +53,7 @@ class Joystick {
/// \brief Destructor.
///
////////////////////////////////////////////////////////////////////////////////////////////////
~
Joystick
()
{}
~
Joystick
()
{
if
(
js
!=
-
1
)
{
close
(
js
);}
}
////////////////////////////////////////////////////////////////////////////////////////////////
///
...
...
@@ -55,6 +68,7 @@ class Joystick {
VectorN
handle_v_switch
(
double
k
,
VectorN
const
&
k_switch
,
MatrixN
const
&
v_switch
);
void
update_v_ref
(
int
k
,
int
velID
);
int
read_event
(
int
fd
,
struct
js_event
*
event
);
void
update_v_ref_gamepad
();
Vector6
getVRef
()
{
return
v_ref_
;
}
...
...
@@ -78,6 +92,12 @@ class Joystick {
double
vYScale
=
1.0
;
// Forward
double
vYawScale
=
1.2
;
// Rotation
// Gamepad client variables
struct
gamepad_struct
gamepad
;
const
char
*
device
;
int
js
;
struct
js_event
event
;
};
#endif // JOYSTICK_H_INCLUDED
This diff is collapsed.
Click to expand it.
src/Controller.cpp
+
9
−
2
View file @
e2df2e15
...
...
@@ -39,6 +39,7 @@ void Controller::initialize(Params& params) {
init_robot
();
// Initialization of the control blocks
joystick
.
initialize
(
params
);
statePlanner
.
initialize
(
params
);
gait
.
initialize
(
params
);
footstepPlanner
.
initialize
(
params
,
gait
);
...
...
@@ -218,7 +219,7 @@ void Controller::init_robot()
void
Controller
::
security_check
()
{
if
(
error_flag
==
0
&&
!
error
&&
!
joystick
.
getStop
()
)
if
(
error_flag
==
0
&&
!
error
)
{
error_flag
=
estimator
.
security_check
(
tau_ff
);
if
(
error_flag
!=
0
)
...
...
@@ -238,8 +239,14 @@ void Controller::security_check()
}
}
if
(
joystick
.
getStop
())
{
error
=
true
;
error_flag
=
-
1
;
}
// If something wrong happened in the controller we stick to a security controller
if
(
error
||
joystick
.
getStop
()
)
if
(
error
)
{
// Quantities sent to the control board
P
=
Vector12
::
Zero
();
...
...
This diff is collapsed.
Click to expand it.
src/Joystick.cpp
+
38
−
7
View file @
e2df2e15
...
...
@@ -6,6 +6,13 @@ Joystick::Joystick() : A3_(Vector6::Zero()), A2_(Vector6::Zero()),
void
Joystick
::
initialize
(
Params
&
params
)
{
predefined
=
params
.
predefined_vel
;
// Gamepad initialisation
device
=
"/dev/input/js0"
;
js
=
open
(
device
,
O_RDONLY
|
O_NONBLOCK
);
if
(
js
==
-
1
)
{
perror
(
"Could not open joystick"
);
}
}
VectorN
Joystick
::
handle_v_switch
(
double
k
,
VectorN
const
&
k_switch
,
MatrixN
const
&
v_switch
)
{
...
...
@@ -34,15 +41,39 @@ void Joystick::update_v_ref(int k, int velID)
update_v_ref_gamepad
();
}
int
Joystick
::
read_event
(
int
fd
,
struct
js_event
*
event
)
{
ssize_t
bytes
;
bytes
=
read
(
fd
,
event
,
sizeof
(
*
event
));
if
(
bytes
==
sizeof
(
*
event
))
return
0
;
/* Error, could not read full event. */
return
-
1
;
}
void
Joystick
::
update_v_ref_gamepad
()
{
// Create the gamepad client
// TODO
// Read information from gamepad client
if
(
read_event
(
js
,
&
event
)
==
0
)
{
if
(
event
.
type
==
JS_EVENT_BUTTON
)
{
if
(
event
.
number
==
9
)
gamepad
.
start
=
event
.
value
;
else
if
(
event
.
number
==
8
)
gamepad
.
select
=
event
.
value
;
}
else
if
(
event
.
type
==
JS_EVENT_AXIS
)
{
if
(
event
.
number
==
0
)
gamepad
.
v_y
=
+
event
.
value
/
32767.0
;
else
if
(
event
.
number
==
1
)
gamepad
.
v_x
=
-
event
.
value
/
32767.0
;
else
if
(
event
.
number
==
3
)
gamepad
.
w_yaw
=
+
event
.
value
/
32767.0
;
}
}
// printf("Start:%d Stop:%d Vx:%f \tVy:%f \tWyaw:%f\n",gamepad.start,gamepad.select,gamepad.v_x,gamepad.v_y,gamepad.w_yaw);
// Retrieve data from gamepad
double
vX
=
0.0
*
vXScale
;
double
vY
=
0.0
*
vYScale
;
double
vYaw
=
0.0
*
vYawScale
;
double
vX
=
gamepad
.
v_x
*
vXScale
;
double
vY
=
gamepad
.
v_y
*
vYScale
;
double
vYaw
=
gamepad
.
w_yaw
*
vYawScale
;
v_gp_
<<
vY
,
vX
,
0.0
,
0.0
,
0.0
,
vYaw
;
// Low pass filter to slow down the changes of velocity when moving the joysticks
...
...
@@ -52,6 +83,6 @@ void Joystick::update_v_ref_gamepad()
}
v_ref_
=
alpha
*
v_gp_
+
(
1
-
alpha
)
*
v_ref_
;
// Switch to safety controller if the
Back
key is pressed
//
if (g
p.backButton.value
) { stop = true; }
// TODO
// Switch to safety controller if the
select
key is pressed
if
(
g
amepad
.
select
==
1
)
{
stop
_
=
true
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/control_solo12.cpp
+
17
−
17
View file @
e2df2e15
...
...
@@ -69,7 +69,7 @@ int main()
// Initialization of variables
Controller
controller
;
// Main controller
controller
.
initialize
(
params
);
// Update urdf dependent parameters (mass, inertia, ...)
std
::
thread
parallel_thread
(
parallel_loop
);
// spawn new thread that
calls check_memory()
std
::
thread
parallel_thread
(
parallel_loop
);
// spawn new thread that
runs MPC in parallel
int
k_loop
=
0
;
// Initialize the communication, session, joints, wait for motors to be ready
...
...
@@ -123,22 +123,6 @@ int main()
robot
->
joints
->
PrintVector
(
robot
->
joints
->
GetPositions
());
std
::
cout
<<
std
::
endl
;
}
}
// Close parallel thread
stop_thread
();
parallel_thread
.
join
();
std
::
cout
<<
"Parallel thread closed"
<<
std
::
endl
;
int
duration_log
[
params
.
N_SIMULATION
-
2
];
for
(
int
i
=
0
;
i
<
params
.
N_SIMULATION
-
3
;
i
++
)
{
duration_log
[
i
]
=
static_cast
<
int
>
(
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
t_log
[
i
+
1
]
-
t_log
[
i
]).
count
());
}
for
(
int
i
=
0
;
i
<
params
.
N_SIMULATION
-
3
;
i
++
)
{
std
::
cout
<<
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
t_log
[
i
+
1
]
-
t_log
[
i
]).
count
()
<<
", "
;
}
// DAMPING TO GET ON THE GROUND PROGRESSIVELY *********************
...
...
@@ -175,5 +159,21 @@ int main()
printf
(
"Either the masterboard has been shut down or there has been a connection issue with the cable/wifi."
);
}
// Close parallel thread
stop_thread
();
parallel_thread
.
join
();
std
::
cout
<<
"Parallel thread closed"
<<
std
::
endl
;
int
duration_log
[
params
.
N_SIMULATION
-
2
];
for
(
int
i
=
0
;
i
<
params
.
N_SIMULATION
-
3
;
i
++
)
{
duration_log
[
i
]
=
static_cast
<
int
>
(
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
t_log
[
i
+
1
]
-
t_log
[
i
]).
count
());
}
for
(
int
i
=
0
;
i
<
params
.
N_SIMULATION
-
3
;
i
++
)
{
std
::
cout
<<
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
t_log
[
i
+
1
]
-
t_log
[
i
]).
count
()
<<
", "
;
}
std
::
cout
<<
std
::
endl
;
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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