|
RSeries astromech firmware
|
|
Go to the documentation of this file.
10 #ifdef USE_MOTOR_DEBUG
11 #define MOTOR_DEBUG_PRINT(s) DEBUG_PRINT(s)
12 #define MOTOR_DEBUG_PRINTLN(s) DEBUG_PRINTLN(s)
13 #define MOTOR_DEBUG_PRINT_HEX(s) DEBUG_PRINT_HEX(s)
14 #define MOTOR_DEBUG_PRINTLN_HEX(s) DEBUG_PRINTLN_HEX(s)
16 #define MOTOR_DEBUG_PRINT(s)
17 #define MOTOR_DEBUG_PRINTLN(s)
18 #define MOTOR_DEBUG_PRINT_HEX(s)
19 #define MOTOR_DEBUG_PRINTLN_HEX(s)
303 virtual void motor(
float left,
float right,
float throttle) = 0;
331 speedModifier +=
getThrottle() * ((1.0f-speedModifier));
333 return min(max(speedModifier,0.0f),1.0f) * -1.0f;
343 return speedModifier;
373 auto turning = (float)(stickx + 128) / 127.5f - 1.0f;
374 auto throttle = (float)(sticky + 128) / 127.5f - 1.0f;
376 throttle = -throttle;
380 if (abs(turning) < 0.2)
383 turning = pow(abs(turning)-0.2, 1.4) * ((turning < 0) ? -1 : 1);
384 if (abs(throttle) < 0.2)
391 throttle = (throttle != 0) ? throttle : targetThrottle;
392 turning = (turning != 0) ? turning : targetTurning;
410 if (turning != 0 || throttle != 0)
475 float val = max(abs(turning -
fDriveTurning) / scale, 0.01f);
518 auto target_left = x;
519 auto target_right = y;
522 auto r = hypot(x, y);
523 auto t = atan2(y, x);
527 target_left = r * cos(t);
528 target_right = r * sin(t);
531 target_left *= sqrt(2);
532 target_right *= sqrt(2);
535 target_left = max(-1.0f, min(target_left, 1.0f));
536 target_right = max(-1.0f, min(target_right, 1.0f));
538 motor(target_left, target_right, drive_mod);
bool useHardStop()
Definition: TankDrive.h:226
virtual void animate() override
Dispatch any received i2c event to CommandEvent.
Definition: TankDrive.h:284
float getMaxSpeed()
Definition: TankDrive.h:132
State state
Definition: JoystickController.h:136
bool getTurnInverted()
Definition: TankDrive.h:112
void setUseRightStick()
Definition: TankDrive.h:256
float fGuestSpeedModifier
Definition: TankDrive.h:560
float fDriveThrottle
Definition: TankDrive.h:567
float fDriveTurning
Definition: TankDrive.h:568
float fSpeedModifier
Definition: TankDrive.h:559
bool fEnabled
Definition: TankDrive.h:549
virtual bool hasThrottle()
Definition: TankDrive.h:317
void setGuestStick(JoystickController &guestStick)
Definition: TankDrive.h:201
int8_t lx
Definition: JoystickController.h:9
uint32_t getSerialLatency()
Definition: TankDrive.h:82
Base class for all animated devices. AnimatedEvent::animate() is called for each device once through ...
Definition: AnimatedEvent.h:18
bool fTurnInverted
Definition: TankDrive.h:558
JoystickController & fDriveStick
Definition: TankDrive.h:546
Base class for all devices that require setup that cannot happen in the constructor....
Definition: SetupEvent.h:15
unsigned fThrottleDecelerationScale
Definition: TankDrive.h:564
unsigned getThrottleAccelerationScale()
Definition: TankDrive.h:144
bool isConnected() const
Definition: JoystickController.h:146
void setEnable(bool enable)
Definition: TankDrive.h:77
bool getThrottleInverted()
Definition: TankDrive.h:102
bool useRightStick()
Definition: TankDrive.h:236
unsigned fThrottleAccelerationScale
Definition: TankDrive.h:563
void setThrottleInverted(bool invert)
Definition: TankDrive.h:107
bool fUseLeftStick
Definition: TankDrive.h:554
void setUseHardStop(bool use)
Definition: TankDrive.h:246
void setDriveStick(JoystickController &driveStick)
Definition: TankDrive.h:196
unsigned fTurnDecelerationScale
Definition: TankDrive.h:566
Analog analog
Definition: JoystickController.h:130
bool fChannelMixing
Definition: TankDrive.h:552
void setThrottleAccelerationScale(unsigned scale)
Definition: TankDrive.h:149
void setTurnDecelerationScale(unsigned scale)
Definition: TankDrive.h:179
uint32_t fSerialLatency
Definition: TankDrive.h:561
void setTurnInverted(bool invert)
Definition: TankDrive.h:117
void setUseLeftStick()
Definition: TankDrive.h:251
Definition: TargetSteering.h:6
bool fThrottleInverted
Definition: TankDrive.h:557
Button button
Definition: JoystickController.h:131
int8_t rx
Definition: JoystickController.h:11
void setChannelMixing(bool mixing)
Definition: TankDrive.h:97
bool fUseHardStop
Definition: TankDrive.h:556
uint32_t fLastCommand
Definition: TankDrive.h:562
void driveStick(JoystickController *stick, float speedModifier)
Definition: TankDrive.h:346
unsigned fTurnAccelerationScale
Definition: TankDrive.h:565
AnalogStick stick
Definition: JoystickController.h:35
void setMaxSpeed(float modifier)
Definition: TankDrive.h:137
int8_t ly
Definition: JoystickController.h:10
bool getEnable()
Definition: TankDrive.h:72
void setTurnAccelerationScale(unsigned scale)
Definition: TankDrive.h:169
virtual void setup() override
Subclasses must implement this function to perform any necessary setup that cannot happen in the cons...
Definition: TankDrive.h:68
void setTargetSteering(TargetSteering *target)
Definition: TankDrive.h:216
bool useThrottle()
Definition: TankDrive.h:221
bool fWasConnected
Definition: TankDrive.h:550
Base template of automatic forwarder from i2c to CommandEvent.
Definition: TankDrive.h:37
bool fScaling
Definition: TankDrive.h:553
float getGuestSpeedModifier()
Definition: TankDrive.h:206
bool fUseThrottle
Definition: TankDrive.h:555
void setAccelerationScale(unsigned scale)
Definition: TankDrive.h:184
void setSerialLatency(uint32_t ms)
Definition: TankDrive.h:87
void setThrottleDecelerationScale(unsigned scale)
Definition: TankDrive.h:159
virtual float getThrottle()
Definition: TankDrive.h:305
unsigned getTurnAccelerationScale()
Definition: TankDrive.h:164
#define MOTOR_DEBUG_PRINTLN(s)
Definition: TankDrive.h:17
unsigned getThrottleDecelerationScale()
Definition: TankDrive.h:154
bool fMotorsStopped
Definition: TankDrive.h:551
#define MOTOR_DEBUG_PRINT(s)
Definition: TankDrive.h:16
AnalogButton button
Definition: JoystickController.h:36
bool getScaling()
Definition: TankDrive.h:122
float getTurning()
Definition: TargetSteering.h:37
int8_t ry
Definition: JoystickController.h:12
void setDecelerationScale(unsigned scale)
Definition: TankDrive.h:190
JoystickController * fGuestStick
Definition: TankDrive.h:547
bool useLeftStick()
Definition: TankDrive.h:231
unsigned getTurnDecelerationScale()
Definition: TankDrive.h:174
virtual void motor(float left, float right, float throttle)=0
Definition: JoystickController.h:4
JoystickController * getActiveStick()
Definition: TankDrive.h:268
TargetSteering * fTargetSteering
Definition: TankDrive.h:548
void setGuestSpeedModifier(float maxGuestSpeed)
Definition: TankDrive.h:211
bool getChannelMixing()
Definition: TankDrive.h:92
float getThrottle()
Definition: TargetSteering.h:32
void setScaling(bool scaling)
Definition: TankDrive.h:127
virtual void stop()
Definition: TankDrive.h:261
virtual float throttleSpeed(float speedModifier)
Definition: TankDrive.h:322
void setUseThrottle(bool use)
Definition: TankDrive.h:241
TankDrive(JoystickController &driveStick)
Constructor.
Definition: TankDrive.h:46